Apache Qpid - 在消息级别设置路由密钥
是否有任何选项可以在 Apache Qpid 中的消息级别设置路由密钥。 我目前的做法是
在地址字符串中指定路由键。使用此目标地址创建生产者。
topic = (主题) context.lookup("目的地"); sender = session.createProducer(topic);
-
通过生产者发送消息。
这样所有的消息都具有相同的路由密钥。我想要实现的是为每条消息单独设置一个路由键。
让我知道这是否可以做到
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过指定每条消息的主题可以轻松完成此操作。
当使用 0-10 协议时,Qpid 地址方案定义的“主题”将映射到主题的路由键。
这允许您使用标准 JMS 接口,同时仍然使用 Qpid 附加组件。
This can be easily done by specifying a per message subject.
The "subject" as defined by the Qpid address scheme, would map to the routing key for Topics when using the 0-10 protocol.
This allows you to use standard JMS interfacing while still using the Qpid add-ons.
我首先尝试这样做:
但是在发送消息时,它仍然具有在我的目的地中设置的路由密钥。
查看 Qpid 的 Java 源代码,我不确定这目前是否可行。如果您查看 https://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java,您将看到如下代码:
不幸的是,这似乎意味着即使您在消息上设置了路由键,如果消息的路由键与目标的路由键不同,它也会被目标的路由键替换目的地的路由键。
也许有办法做到这一点,但不幸的是,我对 Qpid 的 Java 方面不太熟悉。您最好的选择可能是在 Qpid 用户邮件列表上询问(请参阅 http://qpid.apache.org/ mailing_lists.html 获取信息)。
I first tried doing this:
But upon sending the message, it still had the routing key that was set in my Destination.
Looking at Qpid's Java source code, I'm not sure this is currently possible. If you look at https://svn.apache.org/repos/asf/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java, you'll see code like this:
This unfortunately appears to mean that even if you set a routing key on your message, it will be replaced by the destination's routing key if the message's routing key differs from the destination's routing key.
There may be a way to do this, but I'm not super familiar with the Java side of Qpid, unfortunately. Your best bet is probably to ask on the Qpid User Mailing List (see http://qpid.apache.org/mailing_lists.html for info).
您可以将 setJMSReplyTo("address") 设置为路由键。
我已使用它来获取所需响应渠道的回复。
You can set the setJMSReplyTo("address") to the routing key.
I have used it to get replies on required response channel.
您应该能够通过使用 AMQP Topic 来实现您想要的目标。将routingKey 设置为“my-topic”之类的内容。根据设计将您的消费者设置为不同的主题,例如“subject-1”,“subject-2”,...
对于生产者,每个人都可以发送具有不同主题的消息,例如“my-topic.subject-1 ", "my-topic.subject-2", ...使用它们作为生产者的routingKey。
示例代码如下所示:
通过这种方式,您还可以设置消费者来接收发送到“my-topic”的所有消息,并使用“my-topic.*”作为其路由键。
请参阅 Qpid 文档“Programming-In-Apache-Qpid”中的更多详细信息
You should be able to achieve what you want by using AMQP Topic. Set the routingKey to something such as "my-topic". Set up your Consumers to different subjects as designed, such as "subject-1", "subject-2", ...
For the producers each of them can send messages with different subjects, such as "my-topic.subject-1", "my-topic.subject-2", ... use those as the routingKey for the producers.
Sample code look like this:
in this way you can also set up a consumer to receive all the message that are sent to "my-topic" as well using "my-topic.*" as its routing key.
See more details in Qpid documentation, "Programming-In-Apache-Qpid"