How to send reply message to ClientRequestor using Core API
thomaslo Aug 13, 2012 7:57 AMI am quite new to HornetQ. I am currently prototyping using HornetQ to provide both PubSub and also Request/Reply. I am hitting a problem in using HornetQ for Request/Reply using ClientRequestor. On the client side I basically created a ClientRequestor which sends the request to an address that is dedicated for the Request/Reply:
TransportConfiguration server1 = new TransportConfiguration( NettyConnectorFactory.class.getName(), server1Config );
ServerLocator locator = null;
if ( hosts.length == 2 )
{
HashMap<String,Object> server2Config = new HashMap<String,Object>();
server2Config.put( "host", hosts[1] );
server2Config.put( "port", ports[1] );
TransportConfiguration server2 = new TransportConfiguration( NettyConnectorFactory.class.getName(), server2Config );
locator = HornetQClient.createServerLocatorWithHA( server1, server2 );
}
else
{
locator = HornetQClient.createServerLocatorWithoutHA( server1 );
}
ClientSessionFactory factory = locator.createSessionFactory();
clientSession = factory.createSession();
clientRequestor = new ClientRequestor( clientSession, HornetQConstants.REQUEST_TOPIC );
ClientMessage requestMessage = clientSession.createMessage( false );
requestMessage.putBytesProperty( HornetQConstants.DATA, aData );
ClientMessage responseMessage = clientRequestor.request( requestMessage, 10000 );
if ( responseMessage == null )
{
throw new SystemException( "Timed out waiting for response" );
}
return responseMessage.getBytesProperty( HornetQConstants.DATA );
On the server side, I created a ClientConsumer to receive the request message from the client side and a ClientProducer to send the reply back to the client requestor. I am able to receive the request from the client through ClientConsumer. However, I am not able to send the reply back to the client through ClientProducer to the
REPLYTO_HEADER_NAME address:
hornetQ = new EmbeddedHornetQ();
hornetQ.setConfiguration( configuration );
ClientSessionFactory clientSessionFactory = serverLocator.createSessionFactory();
ClientSession responseClientSession = clientSessionFactory.createSession();
ClientProducer producer = responseClientSession.createProducer();
SimpleString responseQueue = message.getSimpleStringProperty( ClientMessageImpl.REPLYTO_HEADER_NAME );
ClientMessage message = responseClientSession.createMessage( false );
message.putBytesProperty( HornetQConstants.DATA, response );
producer.send( responseQueue, message );
The ClientRequestor never receive any data back. And I have been trying to trace the code but got nowhere. Does anyone know what I have done wrong? Many thanks in advance.