gpt4 book ai didi

java - 通过 HornetQ 使用 STOMP 同步消息

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:15:25 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用 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 连接?

最佳答案

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

关于java - 通过 HornetQ 使用 STOMP 同步消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7536317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com