简体   繁体   中英

Activemq Topic with multiple consumers

I'm working on this problem a lot of time now and can't seem to find any final solution to it. I have a message producer that should work as a broadcaster, posting messages on two different topics. The publisher's posting process follows the flow :

  • Creating connection to the factory and starting it.
  • Creating session
  • Creating Message Producer by using the session and a given topic Name
  • Sending n* of messages
  • Waiting n seconds
  • Closing producer,session,connection

Then i have 3 consumers subscribed to those topics by using the following configuration (each consumer has it's own clientId and durableSubscriptionName ):

<route id="consumerOneRoute">
    <from uri="activemq:topic:topicName?clientId=consumerOneId&durableSubscriptionName=ConsumerOneName" />
    <bean ref="consumerBean" method="processMessage" />
</route>

The fact is that my consumers don't always receive the messages, at least not all of them. Sometimes two of the consumers get all the messages and the 3rd one don't get any, sometimes random consumer receive random number of messages and so on... One more fact that i noticed is that if i stop the broker and start it again, the consumers will receive the missing messages, and i really can't understand why won't that happen during the 1st lifetime of the broker. Would anyone be so kind and try to aid me?

Thanks, George.

PS : I was thinking about using virtual topics though since my main purpose is to have a broadcasting producer that will allow other consumers to attach in the future i don't want to have the need of modifyin' the producer everytime by adding another virtual branch to the main topic.

I had similar issue, 1 producer sends messages via topic to many consumers, not all of them receives messages. Problem was in consumer's timeout, I manually created timeout and it was shorter then ActiveMQ could deliver last messages. Extending timeout - helped.

Take a look at Prefetch Policy . If you set it to 1 then it may fix this one for you.

...&consumer.prefetchSize=1

唯一有效的解决方案是从具有持久性使用者的主题切换到虚拟主题。

生产者发送消息时,您的消费者必须连接到代理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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