Discussions

EJB programming & troubleshooting: MDB and Session Beans

  1. MDB and Session Beans (8 messages)

    Can anybody tell the best scenario of MDB(Message Driven bean) communicating with other beans like sessio beans.What is the best benifit we get if embed these two,
    Thanks
    -krish

    Threaded Messages (8)

  2. MDB and Session Beans[ Go to top ]

    You have raised a good point. Usually I back up my MDB by a session bean. I mean say, for example if the processing is asynchronous, then we need to use MDBs. But MDBs for most cases should call (delegate to) the session bean for business processing. In case we require synchronous calls (business user changes mind or business processing changes), then the same session bean can be used without any refactoring of code
    Mohit
  3. MDB and Session Beans[ Go to top ]

    Mohit, You mean to say, for asynchronous processing it is better mdb call session bean.so session bean is backed of session bean.If it is like this there is point that client can not call mdb directly.So how can this flow goes? I got cofused the flow of beans (which one call which one).can you please explain

    Regards, Harikrishna
  4. MDB and Session Beans[ Go to top ]

    Hari,
    Mohit meant that the same Session Bean can be used for processing of synchronous requests from the client (aka HTTP request from Web server) and from MDB. In case of MDB it is acting as a client to the same session bean. The only difference is that MDB is started by j2EE container based on incoming message and the session bean CANNOT return any result back to the original client unless it using messaging. You can keep the business logic in Session Bean and use it to serve client or MDB request.
       
    I think first of all you have to get clear picture what is MDB. Sorry it may not sound polite, but based on you question it looks like that you do not understand MDB.
    First of all client NEVER call MDB. It is up to the server (Container) to call MDB based on incoming message.
    MDB more or less the same as Stateless Session bean, but for asynchronous messages.
    MDB just allows J2EE container to listen outside messaging world (Topics or Queues).

    Glen
  5. MDB and Session Beans[ Go to top ]

    Thanks for the information.
    Can tell me a scenarion which have the communication between Session and mdb
    -hari
  6. MDB and Session Beans[ Go to top ]

    Thanks for the information.
    Can tell me a scenarion which have the communication between Session and mdb
    is mdb client and session bean client are different?
    -hari
  7. MDB and Session Beans[ Go to top ]

    For example if you want to deliver result or exception back to the caller from a Session Bean business method. With MDB Client you cannot do it directly.

    There are more or less the same, but with few exceptions:
    1. “Regular” Client can call Session Bean only synchronically and can get result or exception back from a Session Bean
    2. MDB Client "accepts" asynchronous request from “Regular” Client and delegates processing to a Session Bean and it cannot return directly result or exception back to the original requester from Session Bean's method.
  8. MDB and Session Beans[ Go to top ]

    Hi Glen

    You have written that with MDB we cannnot send result or exception back to client directly. I agree but could you please tell us a way in which it could be done INDIRECTLY.
    i.e is there any indirect way to send back results from MDB to the client(say servlet) , may be using another message queue or something. I do understand that this will also be asynchronous.

    Kindly tell that indirect way if you know of one.
  9. MDB and Session Beans[ Go to top ]

    It depends on context.
    If you start transaction for MDB(onMessage(...)) and you want to send something back, then you have to spawn new transaction and send reply to desired destination(Queue,Topic, TempQueue, TempTopic) from the context of new transaction.