Why message driven beans?


EJB design: Why message driven beans?

  1. Why message driven beans? (5 messages)

    Hi All,

    Probably this is old question but couldn’t find answer for this so, I’m posting this.

    I have read about Message driven beans but I'm trying to find answer "why message driven beans". Can’t I use Javamail for notifications? How best can I use them?

    If some of you can take time and explain with some scenarios that will great.

    Thank you for your time.

    Threaded Messages (5)

  2. Why message driven beans?[ Go to top ]

    Message Driven Beans (MDBs) are not for notifications and they are very different from JavaMail. MDBs is just a way to process messages using all services of EJB container: transactional support, datasources, JMS resources, etc. The producer(s) of the messages is not necessarily aware about MDBs processing its messages.
    I’ll give an example from an on-line shop application. As soon as the customer places a purchase order, (s)he sees the next page before the order is delivered. Processing of the order after its submission goes asynchronously. The web application put the order details into a message and sends it. MDB without any rush picks it up and process. The messaging system guaranties that the message is not lost. MDB either 1) successfully processes the order and submits all changes (database updates and/or new JMS messages) at once or 2) fails and uses a secondary scenario to inform the customer or 3) simply leaves the message on the queue to repeat the attempt to process it later. Whatever situation is the order is not lost, information in database(s) remains consistent and the customer does not receive, for example, the order successful delivery email while processing fails to update the database.
  3. Why message driven beans?[ Go to top ]


    so, if there is a usecase where you want to hold the transaction for a while then MDB could be good candidate. but why would you hold the transaction.May be becuase,
    1:lack of resources to complete the transaction
    2:transaction takes lot of time and don't want user to stay there and wait for the results.

    but above two can be addressed by upgrading hardware,clustering. I'm trying to learn more becuase I don't want to regret after starting using them half way.

    In reality all tutorials of technolgy sounds great and they work fine, but when a complex application is developed they become "white elephants" like CMP-Entity beans.

    Thanks for your time.
  4. Why message driven beans?[ Go to top ]


    I vaguely remember a shop where CICS is not 24x7, so for one hour each day it's not available. Not exactly for this reason MDB is used, but also for other reasons as well.
  5. Why message driven beans?[ Go to top ]

    CICS? not sure what it is. but I get your point.I hope to hear more about my question.

    Thank you all.
  6. Why message driven beans?[ Go to top ]

          The main reason for MDB is that they are asynchronous. That means you don't have to worry about when the message will be consumed. Suppose in your application you want to log the event that the user created. eg: Shopping cart filled,Cart saved,Order Confirmed etc etc. Now you can do all this without causing your program to wait for these inserts into the database rather at the end of each stage you can send a message to a queue like "Cart saved" and it will be inserted into the database later. This is just an example and practically you can have transaction that are long and consume a lot of resources.

    hope it helps.