synchronous messaging with STOMP over HornetQ
I am trying to figure out how to do syncronous messaging using stomp with hornetq, or if its even possible. I have an async stomp client working, but I can't see how I would implement a sync version.
On the server side, my acceptor looks like this:
<acceptor name="stomp-acceptor">
<factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
<param key="protocol" value="stomp" />
<param key="port" value="61613" />
</acceptor>
and my listener looks like this:
public class SimpleSyncListener extends BaseListener implements SessionAwareMessageListener<Message> {
@Override
public void onMessage(Message message, Session session) throws JMSException {
String lastMessage = "";
try {
lastMessage = ((TextMessage) message).getText();
//System.out.println("server recieved: " + lastMessage);
Destination replyDestination = message.getJMSReplyTo();
StringBuffer sb = new StringBuffer();
sb.append("reply ");
sb.append(Calendar.getInstance().getTimeInMillis());
sb.append(" ");
sb.append(lastMessage);
TextMessage replyMessage = session.cre开发者_JS百科ateTextMessage(sb.toString());
replyMessage.setJMSCorrelationID(message.getJMSMessageID());
MessageProducer replyProducer = session.createProducer(replyDestination);
replyProducer.send(replyMessage);
} catch (JMSException e) {
throw new RuntimeException(e);
}
incrementCount();
}
I assume I need to put something in the temp queue and send it back like you do with JMS. Its just not clear to me how that works with STOMP. Do i need to open another tcp connection back on the client side that correspond to the "temp queue" on the server side?
Stomp is a simple protocol, and on this case I don't think you can have a multiplexed channel. So you will probably need a Stream to send, and a Stream to receive.
The common strategy to implement synchronous (request / response) communication with JMS - using temporary destinations - is also available with the STOMP implementations of many message brokers (ActiveMQ, Apollo, OpenMQ and RabbitMQ are examples).
However, HornetQ does not support temporary destinations in the current 2.4.0.Final version.
精彩评论