【问题标题】:synchronous messaging with STOMP over HornetQ通过 HornetQ 使用 STOMP 进行同步消息传递
【发布时间】:2014-10-19 00:14:44
【问题描述】:

我正在尝试弄清楚如何使用 stomp 和 hornetq 进行同步消息传递,或者是否可能。我有一个异步 stomp 客户端正在工作,但我看不到如何实现同步版本。

在服务器端,我的接受器如下所示:

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

我的听众看起来像这样:

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.createTextMessage(sb.toString());
        replyMessage.setJMSCorrelationID(message.getJMSMessageID());

        MessageProducer replyProducer = session.createProducer(replyDestination);

        replyProducer.send(replyMessage);

    } catch (JMSException e) {
        throw new RuntimeException(e);
    }
    incrementCount();

}

我假设我需要在临时队列中放入一些东西,然后像使用 JMS 一样将其发回。我只是不清楚它是如何与 STOMP 一起工作的。我是否需要在客户端打开另一个与服务器端的“临时队列”相对应的 tcp 连接?

【问题讨论】:

    标签: java jms synchronous hornetq stomp


    【解决方案1】:

    Stomp 是一个简单的协议,在这种情况下,我认为您不能拥有多路复用通道。所以你可能需要一个 Stream 来发送和一个 Stream 来接收。

    【讨论】:

      【解决方案2】:

      与 JMS 实现同步(请求/响应)通信的常用策略 - 使用临时目的地 - 也适用于许多消息代理的 STOMP 实现(例如 ActiveMQ、Apollo、OpenMQ 和 RabbitMQ)。

      但是,HornetQ 在当前 2.4.0.Final 版本中不支持临时目的地。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-03-20
        • 2011-06-29
        • 2011-03-22
        • 2014-12-12
        • 2014-02-02
        • 2012-05-08
        • 2011-04-05
        • 2011-09-12
        相关资源
        最近更新 更多