Interview Questions

Can an MDB be a message producer or both a producer and consumer?

BEA WebLogic Questions and Answers


(Continued from previous question...)

Can an MDB be a message producer or both a producer and consumer?

Yes. You have no JMS context inside the MDB so you will need to establish a connection, session and producer yourself. One option is to do this every time you come into the onMessage routine for the MDB. This is sufficient if the message rate is relatively low. The second option is to establish the necessary objects in ejbActivate(). Note that the objects are not serializable so they can't be passivated for a stateful session bean or an entity bean. When the EJB deactivates, you need to close the associated objects. The third option is that you could build up a JMS connection/sender session pool within a startup class complete with your own synchronization and blocking to get a connection. There is an example in the answer to the question "Is it possible to send or receive a message from within a message listener?"

(Continued on next question...)

Other Interview Questions