8 Replies Latest reply: Aug 14, 2012 9:37 AM by Thomas Lo RSS

How to send reply message to ClientRequestor using Core API

Thomas Lo Newbie

I 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.

 


  • 1. Re: How to send reply message to ClientRequestor using Core API
    Jeff Mesnil Master

    Thomas Lo wrote:

     

                                  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();

    You must start the session in order to receive messages

  • 2. Re: How to send reply message to ClientRequestor using Core API
    Thomas Lo Newbie

    Ah, super thanks. I kept looking at the server side and I didn't even check the client side. I will try that. Many thanks!

  • 3. Re: How to send reply message to ClientRequestor using Core API
    Thomas Lo Newbie

    Jeff, super thanks for the solution. It works. But now I have a different problem. I have a client tester to perform performance testing on the HornetQ as request/reply transport. Client issues 100,000 requests to the server with embedded hornetq. After running half way through the server starts to have memory issue. After checking seems like the queue created on the server side is holding on the ServerMessageImpl. The queue is set up as non-temporary non-durable with persistence turned off. Do I need to explicitly remove the message from the queue? Ideally after the consumer on the server side receives the message I don't need the message on the queue anymore.

     

    Once again super thanks on the quick response and helpful suggestion.

  • 4. Re: How to send reply message to ClientRequestor using Core API
    Jeff Mesnil Master

    you did not acknowledge the message returned by the client requestor. The server still hold the message until you ack it.

  • 5. Re: How to send reply message to ClientRequestor using Core API
    Thomas Lo Newbie

    Super thanks again. Didn't realize I have to do that on the ClientRequestor side. Excellent help. Thanks very much

  • 6. Re: How to send reply message to ClientRequestor using Core API
    Thomas Lo Newbie

    Jeff, want to bother you once again. Currently I am benchmarking the performance with our new RPC framework using transport adaptor from zeromq, http, and hornetq. HornetQ performs on avg 124 micro second (we work in institutional financial trading system so our performance no is a bit nutty) on request time versus 228.33 on HTTP side which is good. But response time from HornetQ avg 165 micro versus 152 micro on HTTP. Assume the delay is from the ack. Is there a way to configure to eliminate the overhead on ack? Also, for performance tuning, other than no persistence (we are using just Core API), what else should we watch out for? Super thanks once again.

  • 8. Re: How to send reply message to ClientRequestor using Core API
    Thomas Lo Newbie

    Super thanks again!