RabittMQ RPC Request/Response example using hoplin.io library
Following example creates RPC client and then setups Async response handler, which follows by the request to get processed.
Hoplin client supports both Direct-Reply and Queue per Request/Response patterns.
RpcClient<LogDetailRequest, LogDetailResponse> client = DefaultRpcClient.create(options(), bind());
// rpc response
client.respondAsync((request)->
{
final LogDetailResponse response = new LogDetailResponse("Response message", "info");
return response;
});
// rpc request
final LogDetailResponse response = client.request(new LogDetailRequest("Request message", "info"));
log.info("RPC response : {} ", response);
This is the binding that is used to create our client.
private static Binding bind()
{
return BindingBuilder
.bind("rpc.request.log")
.to(new FanoutExchange("rpc.logs"));
}