Dreamer
Dreamer

Reputation: 7549

Can JMS to configure to allow one message to receive/process by only one receiver?

I am not sure if the issue is related to synchronization or more like transaction management, but my current goal is to implement a module by Spring like this:

  1. One sender to send messages to queue
  2. Multiple receivers to receive messages from queue.
  3. Each receiver extracts information from the message and put into data persistence(database)
  4. ***The most important requirement is ONLY ONE MESSAGE can be received by ONE receiver at a time so that it will not cause database transaction issue(like Optimistic Locking issue). If all receivers start to process the same message then it will cause trouble in the database transaction management.

The key is make sure to prevent a message to receive by more than one receiver, that's all.

I have finished 1,2,3 but confuse about 4, I find this thread helpful, but I am not sure it can resolve above situation, also at same time I wonder if without JTA transaction management from Spring, can standard JMS or JMS provider(ActiveMQ, Websphere MQ, JBoss HonetQ etc) provide any configuration so that can guarantee one message can only be received or process by only one receiver?

Upvotes: 2

Views: 984

Answers (2)

Rohit
Rohit

Reputation: 2152

Read this . As Gary already mentioned, the message on queue are always received by single consumer irrespective of number subscribers. This is true with/without transactions.

Upvotes: 1

Gary Russell
Gary Russell

Reputation: 174554

That's the way JMS works. Only one consumer will get each message as long as you use a queue and not a topic.

Upvotes: 1

Related Questions