简体   繁体   English

JMS主题在队列侦听器中接收

[英]JMS topic receive in a Queue listener

I have a question regarding JMS. 我对JMS有疑问。 I´ve been checking some blogs, where show how a sending topic message can be receive by a queue listener. 我一直在检查一些博客,其中展示了队列侦听器如何接收正在发送的主题消息。 It is that even possible, as far as I know only a client subscribe to a particular topic can receive a message published. 据我所知,甚至只有可能,订阅特定主题的客户端才能收到发布的消息。

Regards. 问候。

So, given you publish to a topic, you want to consume the messages from a queue. 因此,给定发布主题,您想使用队列中的消息。 I assume you use ActiveMQ since you added that tag. 我假设您使用ActiveMQ,因为您添加了该标签。

The main reason for this setup is to be able to load balance multiple cluster nodes of the consumer. 进行此设置的主要原因是能够负载均衡使用者的多个群集节点。 Plain durable subscriptions won't allow that in JMS 1.x. 普通的持久订阅在JMS 1.x中不允许这样做。 I guess your case is similar. 我想你的案子也差不多。

  • In generic JMS, this is not possible. 在通用JMS中,这是不可能的。 However, in JMS 2.0 durable subscriptions can be load balanced and hence work a bit like queues. 但是,在JMS 2.0中,持久订阅可以实现负载均衡,因此工作有点像队列。 Not all JMS brokers implements JMS 2.0. 并非所有的JMS代理都实现JMS 2.0。 ActiveMQ does not implement JMS 2.0, but ActiveMQ Artemis do. ActiveMQ不实现JMS 2.0,但ActiveMQ Artemis实现。

  • ActiveMQ allows this by a concept called Virtual Topics. ActiveMQ通过称为虚拟主题的概念允许这样做。 Using Virtual Topics you can give the topic a certain name, say VirtualTopic.MyTopic would forward all published messages to any created queue that matches Consumer.MyConsumer.VirtualTopic.MyTopic. 使用虚拟主题,您可以给主题指定一个名称,例如VirtualTopic.MyTopic会将所有已发布的消息转发到与Consumer.MyConsumer.VirtualTopic.MyTopic匹配的任何已创建队列。

Example topic name: 示例主题名称:

  • VirtualTopic.GameScores VirtualTopic.GameScores

Example queue names: 队列名称示例:

  • Consumer.ScoreBoardService.VirtualTopic.GameScores Consumer.ScoreBoardService.VirtualTopic.GameScores
  • Consumer.BettingService.VirtualTopic.GameScores Consumer.BettingService.VirtualTopic.GameScores

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

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