Skip to content

Commit 9993273

Browse files
committed
Add constructor with RpcClientParams to JsonRpcClient
[#161476914] References #417
1 parent 2e02ffe commit 9993273

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 org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
@@ -66,6 +67,25 @@ public class JsonRpcClient extends RpcClient implements InvocationHandler {
6667
*/
6768
private ServiceDescription serviceDescription;
6869

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

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)