英文:
Listening to new ActiveMQ topic as they created in runtime
问题
我正在开发一个应用程序(Spring Boot 应用程序),该应用程序应该从在运行时从其他应用程序创建的主题中进行监听。
我该如何得知在运行时在 Active MQ Broker 上创建了一个新主题?
以及我如何开始监听在运行时新创建的主题?
请注意,我希望能够监听在运行时创建的主题,而不是在启动时(应用程序启动,构建 Spring 应用程序上下文)进行监听。
我不知道在应用程序启动时可能需要监听多少个主题。这些主题是在运行时创建的,没有特定的命名模式。
英文:
I am working on application (spring boot application)which is supposed to be listening from the topic created in runtime from some other application.
How can I know a new topic is created on the Active MQ Brocker in the runtime?
And how can I start to listening the newly created topic un the runtime?
Please note that I want to listen to topic created in runtime not at launch time (application startup, spring application context is built).
I don't know how many topic I may have to listen to when my application starts up. Topics are created in the runtime with no specific naming pattern.
答案1
得分: 1
没有设置'持久性',这会产生竞态条件。如果生产者在消费者上线之前发送消息,代理将不会为消费者保留消息。'持久性'是代理为消费者保留消息的能力,即使消费者未连接。
然而!ActiveMQ通过为消费者使用通配符名称来解决了这个问题。建议您至少同意一个前缀以提供第一级过滤。注意——如果您转向多代理架构,您也会需要这个。类似于topic://ORDER.ABCD,topic://ORDER.XYZ,其中所有主题都以相同的格式创建,即'ORDER.$randomStuff'。
选项1:
让消费者使用ActiveMQ的通配符字符“>”注册持久性订阅。例如:topic://ORDER.>
选项2:
您可以监听ActiveMQ.Advisory主题上的事件,以便在创建目标时注册消费者。然而,这会产生消息丢失的竞态条件。
选项1可能是您最好的选择,但是如果每天的消息量达到数百万条或主题总数达到数千条,可能会遇到扩展问题。
英文:
Without 'durability' in place, this presents a race condition. If the producer sends a message before the consumer is online, the broker will not hold on to the message for the consumer. 'durability' is the broker holding on to messages for a consumer, even when the consumer is not connected.
However! ActiveMQ has this solved by using wild card names for consumers. It is recommended that you at least agree on a prefix to provide first level filtering. Note-- you'll also want this if you go to multi-broker architecture. Something like topic://ORDER.ABCD, topic://ORDER.XYZ where all the topics are created with the same format ie 'ORDER.$randomStuff'.
Option 1:
Have the consumer register a durable subscription using ActiveMQ's wild card character ">". ie. topic://ORDER.>
Option 2:
You can listen for events on the ActiveMQ.Advisory topics for when the destination is created, and then register a consumer. However, this has the race condition where messages could be missed.
Option 1 is probably your best bet, but can run into scaling problems if you start getting up to the message load in the 100M's of messages per day or 1000's of total number of topics.
答案2
得分: 1
订阅advisory主题 ActiveMQ.Advisory.Topic
(需要启用advisory消息 -- 详见[1])。每当创建新主题时,都会向此主题发布一条消息。该消息的正文将是一个 org.apache.activemq.command.DestinationInfo
类的对象,可以从中提取出新主题的名称。
应用程序可以使用这个名称订阅,就像订阅任何其他主题一样。
[1] http://activemq.apache.org/advisory-message.html
英文:
Subscribe to the advisory topic ActiveMQ.Advisory.Topic
(advisories need to be enabled -- see [1]). A message will be published to this topic every time a topic is created. The message will have as its body an object of class org.apache.activemq.command.DestinationInfo
, from which the name of the new topic can be extracted.
The application can subscribe using this name, as it would to any other topic.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论