简体   繁体   English

如何为我在activemq中拥有的每个消费者创建单独的队列?

[英]How to create separate queue for each consumer I have in activemq?

I'm using activemq (pretty new to me) and I have one producer and several consumers. 我正在使用activemq(对我来说还很新),我有一个生产者和几个消费者。

Thing is, I want to address messages for specific consumers. 问题是,我想针对特定消费者发送消息。 I read about selectors but also read that it is a bad practice to use and also read about some alternatives . 我阅读了有关选择器的文章,但同时也阅读到使用它是一种不好的做法 ,还阅读了一些替代方法

The alternative sounds good for me, but I'm not sure how I can create these queues for each and every one of my slaves. 替代方案对我来说听起来不错,但是我不确定如何为每个奴隶创建这些队列。 Each of my slaves has an ID (uuid) that I can use when I'm creating the listener - like this: 我的每个奴隶都有一个ID(uuid),我可以在创建侦听器时使用它-像这样:

<jms:listener-container
        container-type="default"
        connection-factory="jmsConnectionFactory"
        acknowledge="auto">
    <jms:listener destination="slave.tasks.${slave.id}" ref="jmsActivityListener" method="onMessage" />
</jms:listener-container>

This requires the slave.properties file to contain the following entry: 这需要slave.properties文件包含以下条目:

slave.id=XXXXXXX

My questions are: 我的问题是:

1) Is that the way to do it (defining a queue per consumer)? 1)是这样做的方法(为每个使用者定义一个队列)吗?

2) How can I generate this salve.id value (I don't want the user to fill it as it has to be unique)? 2)如何生成此salve.id值(我不希望用户填充它,因为它必须是唯一的)?

Thanks 谢谢

Virtual Topics to the rescue 拯救虚拟话题

The idea behind virtual topics is that producers send to a topic in the usual JMS way. 虚拟主题的思想是生产者以通常的JMS方式发送主题。 Consumers can continue to use the Topic semantics in the JMS specification. 消费者可以继续使用JMS规范中的Topic语义。 However if the topic is virtual, consumer can consume from a physical queue for a logical topic subscription, allowing many consumers to be running on many machines & threads to load balance the load. 但是,如果主题是虚拟的,则消费者可以从物理队列中消费逻辑主题订阅,从而允许许多消费者在许多计算机和线程上运行以平衡负载。 Eg, let's say we have a topic called VirtualTopic.Orders . 例如,假设我们有一个名为VirtualTopic.Orders的主题。 (Where the prefix VirtualTopic. indicates its a virtual topic). (其中前缀VirtualTopic。指示其为虚拟主题)。 And we logically want to send orders to systems A and B. Now with regular durable topics we'd create a JMS consumer for clientID_A and "A" along with clientID_B and "B". 我们逻辑上希望将订单发送到系统A和B。现在,使用常规的持久性主题,我们将为clientID_A和“ A”以及clientID_B和“ B”创建一个JMS使用者。 With virtual topics we can just go right ahead and consume to queue Consumer.A.VirtualTopic.Orders to be a consumer for system A or consume to Consumer.B.VirtualTopic.Orders to be a consumer for system B. We can now have a pool of consumers for each system which then compete for messages for systems A or B such that all the messages for system A are processed exactly once and similarly for system B. 有了虚拟主题,我们就可以继续消费,并把Consumer.A.VirtualTopic.Orders排队作为系统A的消费者,或者消费到Consumer.B.VirtualTopic.Orders成为系统B的消费者。我们现在可以拥有一个每个系统的使用者池,然后这些用户争用系统A或B的消息,以使系统A的所有消息都被精确地处理一次,并且类似地针对系统B。

http://activemq.apache.org/virtual-destinations.html http://activemq.apache.org/virtual-destinations.html

 <jms:listener-container container-type="default" connection-factory="jmsConnectionFactory" acknowledge="auto"> <jms:listener destination="Consumer.#{T(java.lang.System).currentTimeMillis()}.VirtualTopic.tasks" ref="jmsActivityListener" method="onMessage" /> </jms:listener-container> 

your producer can send messages to topic "VirtualTopic.tasks" and these messages will be sent to all Consumer.*.VirtualTopic.tasks queues 您的生产者可以将消息发送到主题"VirtualTopic.tasks"并且这些消息将发送到所有Consumer.*.VirtualTopic.tasks队列

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

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