| Author |
Running Message Driven Beans
|
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
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.
|
OCPJP 6.0 93%
OCPJWCD 5.0 98%
|
 |
Ravi Bansal
Ranch Hand
Joined: Aug 18, 2008
Posts: 82
|
|
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.
|
SCJP 5.0 94%
OCE-EJBD 90%
|
 |
Mohit G Gupta
Ranch Hand
Joined: May 18, 2010
Posts: 634
|
|
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
Joined: Aug 18, 2008
Posts: 82
|
|
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
Joined: May 18, 2010
Posts: 634
|
|
|
Thanks Ravi
|
 |
 |
|
|
subject: Running Message Driven Beans
|
|
|