Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

EJB Messaging, Part II: Message-Driven Beans-2 : Page 2


advertisement

MDBs: EJB and JMS Interfaces in One
Message-Driven Beans do not follow the typical pattern for EJB interface implementation, because an MDB is a cross between a stateless session EJB and a JMS client. Rather than defining EJB component interfaces, MDBs implement two interfaces: one is an EJB interface and the other is a JMS interface. The following code is a sample of an MDB class signature:


public class MessageBean implements MessageDrivenBean, 
MessageListener

The first interface, javax.ejb.MessageDrivenBean, is the bean's interface to the container. It allows the EJB container to manage the MDB, just as the container manages session and entity beans. The second interface, javax.jms.MessageListener, allows the bean to register with a JMS-enabled MOM (messaging-oriented middleware) server as a JMS listener.



As full-fledged JMS clients, MDBs can both send and receive messages asynchronously via a MOM server. As enterprise beans, MDBs are managed by the container and declaratively configured by an EJB deployment descriptor:


<ejb-jar>
 <enterprise-beans>
  <message-driven>
   <ejb-name>MyMessageBean</ejb-name>
   <ejb-class>com.gabhart.ejb.messaging.MessageBean</ejb-class>
   <transaction-type>Container</transaction-type>
   <message-driven-destination>
    <destination-type>javax.jms.Queue</destination-type>
   </message-driven-destination>
   ...
  </message-driven>
  ....
 </enterprise-beans>
</ejb-jar>

All of these element names should look familiar except for two:

  • <message-driven> This element represents the bean type. It is a direct parallel for the elements <session> and <entity>.
  • <message-driven-destination> This element indicates the JMS destination type (topic or queue) to which the MDB will bind.


  • Comment and Contribute

     

     

     

     

     


    (Maximum characters: 1200). You have 1200 characters left.

     

     

    Sitemap
    Thanks for your registration, follow us on our social networks to keep up-to-date