简体   繁体   English

如何通过Stomp.js设置回复主题

[英]How to set reply-to topic through Stomp.js

In C# using NMS API we set Response topic for ActiveMQ in this way 在使用NMS API的C#中,我们以这种方式设置ActiveMQ的Response主题

IDestination temp = session.CreateTemporaryTopic();
ITopic consumer = session.CreateConsumer(temp);

And while sending message we set it like this ... 在发送消息时,我们将其设置如下:

TextMessage reqMessage = session.CreateTextMessage(message);
reqMessage.NMSReplyTo = temp;

How can we do the same thing using Stomp.js? 我们如何使用Stomp.js做同样的事情?

Most STOMP operations are done using specific headers that are placed in the Message that you send. 大多数STOMP操作都是使用您发送的消息中放置的特定标头完成的。 In this case the 'reply-to' header indicates the address where the receiving client should send its response. 在这种情况下,“ reply-to”标头指示接收客户端应将其响应发送到的地址。 So the pattern would be to send the message with the 'reply-to' header set, something like this depending on the library you are using: 因此,模式将是发送带有“ reply-to”标头集的消息,具体取决于您所使用的库:

stomp.subscribe("/temp-queue/response-queue")
stomp.publish("/queue/work-queue", "WORK", {"reply-to" => "/temp-queue/response-queue"})

Since you are using temp Topic you must ensure that there is subscriber prior to the response message being sent, otherwise it will not get all the replies. 由于您使用的是临时主题,因此必须在发送响应消息之前确保有订阅者,否则它将无法获得所有答复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM