• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Running Message Driven Beans

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ravi
 
I am mighty! And this is a mighty small ad:
ScroogeXHTML - a fast and small RTF to HTML5 and XHTML converter library
https://coderanch.com/t/742149/ScroogeXHTML-RTF-HTML-XHTML-converter
reply
    Bookmark Topic Watch Topic
  • New Topic