Skip to content

Commit e3517ac

Browse files
committed
Add constructor with RpcClientParams to JsonRpcClient
[#161476914] References #417 (cherry picked from commit 9993273)
1 parent 55071c0 commit e3517ac

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/main/java/com/rabbitmq/tools/jsonrpc/JsonRpcClient.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.rabbitmq.client.Channel;
1919
import com.rabbitmq.client.RpcClient;
20+
import com.rabbitmq.client.RpcClientParams;
2021
import com.rabbitmq.client.ShutdownSignalException;
2122
import com.rabbitmq.tools.json.JSONReader;
2223
import org.slf4j.Logger;
@@ -67,6 +68,25 @@ public class JsonRpcClient extends RpcClient implements InvocationHandler {
6768
*/
6869
private ServiceDescription serviceDescription;
6970

71+
/**
72+
* Construct a new {@link JsonRpcClient}, passing the {@link RpcClientParams} through {@link RpcClient}'s constructor.
73+
* <p>
74+
* The service description record is
75+
* retrieved from the server during construction.
76+
*
77+
* @param rpcClientParams
78+
* @param mapper
79+
* @throws IOException
80+
* @throws JsonRpcException
81+
* @throws TimeoutException
82+
*/
83+
public JsonRpcClient(RpcClientParams rpcClientParams, JsonRpcMapper mapper)
84+
throws IOException, JsonRpcException, TimeoutException {
85+
super(rpcClientParams);
86+
this.mapper = mapper;
87+
retrieveServiceDescription();
88+
}
89+
7090
/**
7191
* Construct a new JsonRpcClient, passing the parameters through
7292
* to RpcClient's constructor. The service description record is
@@ -76,7 +96,12 @@ public class JsonRpcClient extends RpcClient implements InvocationHandler {
7696
*/
7797
public JsonRpcClient(Channel channel, String exchange, String routingKey, int timeout, JsonRpcMapper mapper)
7898
throws IOException, JsonRpcException, TimeoutException {
79-
super(channel, exchange, routingKey, timeout);
99+
super(new RpcClientParams()
100+
.channel(channel)
101+
.exchange(exchange)
102+
.routingKey(routingKey)
103+
.timeout(timeout)
104+
);
80105
this.mapper = mapper;
81106
retrieveServiceDescription();
82107
}

src/test/java/com/rabbitmq/client/AbstractJsonRpcTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public void init() throws Exception {
5050
// safe to ignore when loops ends/server is canceled
5151
}
5252
}).start();
53-
client = new JsonRpcClient(clientChannel, "", queue, 1000, createMapper());
53+
client = new JsonRpcClient(
54+
new RpcClientParams().channel(clientChannel).exchange("").routingKey(queue).timeout(1000),
55+
createMapper()
56+
);
5457
service = client.createProxy(RpcService.class);
5558
}
5659

0 commit comments

Comments
 (0)