This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Message Driven Beans

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source:8.2. Topic Message Driven Bean Example

OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan Version: April 8, 2012


On Running the example and issuing a request to the following URL thrice:

http://localhost:8080/TopicMessageDrivenExample/sendmsg.do

The following output was seen in the server.logs:



Question: Why is there no order of messages received by MDB,each request results in a different MDB to receive a message( not in order they were created) ?

Please advise.
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohit,
Messages may be delivered out of sequence , EJB specs does not gurantee message delivery order.

See Section 5.4.11 of ejb 3.1 spec.

A container allows many instances of a message-driven bean class to be executing concurrently, thus allowing for the concurrent processing of a stream of messages. No guarantees are made as to the exact order in which messages are delivered to the instances of the message-driven bean class, although the container should attempt to deliver messages in order when it does not impair the concurrency of message processing. Message-driven beans should therefore be prepared to handle messages that are out of sequence: for example, the message to cancel a reservation may be delivered before the message to make the reservation.


Hope this helps.
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ravi
However,The example above sends only one message when i issue a request using URL.

My Question is why the order in which beans were created ( i.e. 1,2,3) are not getting the message in the same order ?



The order of message receivable is opposite of Bean creation
Each of the three message driven beans receive a copy of the message sent to the topic
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohit,

Order of bean creation is not tied to order in which they recieve the messages
MDB very much works like stateless session beans , where in container creates pool of MDB instances once the bean is deployed.
once we have a pool , Container can pick any instance from the pool and delegate it to process the message. Order is not supposed to be preserved.

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ravi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic