I would like to know what happens if MessageListenerContainer, pointing to a topic, recieves 2 (or more) messages at the same time.

For example, 2 users of the app triggers a publish at the same time, hence 2 jmstemplate calls sending 2 different messages to the same topic.

How will the container handle this?

  1. Will the container create 2 threads calling the MessageListenerAdapter (which should implemented as thread-safe) at same time?
  2. Or will the container have just 1 thread calling the MessageListenerAdapter serially (sequentially)?
有帮助吗?

解决方案

The concurrency setting controls how many listeners consume messages concurrently. You should not use more than 1 consumer for topics, otherwise, the message may be consumed twice on the same node.

<jms:listener-container
  container-type="default"
  connection-factory="connectionFactory"
  acknowledge="auto"
  concurrency="1"     
  cache="consumer">
  <jms:listener destination="TEST.FOO" 
                ref="simpleMessageListener"
                method="onMessage" />
</jms:listener-container>

See this too... https://stackoverflow.com/a/5808803/791406

Spring Docs... http://static.springsource.org/spring/docs/3.0.5.RELEASE/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top