advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Message Driven Beans :

MDB Features

The Message driven bean provides all the features that EJB clients are good for. The EJB container takes the responsibility of concurrency, transactions, security and other services so that the client can focus solely on the business logic. A few of the features are discussed below.

  1. The EJB Advantage
  2. By implementing the MessageDrivenBean interface the MDB allows the container to take control over the bean and how it is handled. This results in more robust and reliable message consumers compared to traditional message clients.

  3. The flexibility of JMS
  4. The MDB implements the javax.jms.MessageListener interface to leverage on the advantages of JMS. By implementing JMS separately MDB's provide room for providing implementation of other types of messaging systems. Currently only JMS is supported. Support for other Message types like JAXM message-driven beans is also possible.      

  5. Timing out MDB's
  6. In addition to the above interfaces MDB's can implement the javax.ejb.TimedObject interface to add time based event notifications. This registers the MDB with the EJB Timer service. When the Timer expires the container calls the ejbTimeout method

  7. The MessageDrivenContext interface
  8. When the container calls the ejbCreate method of the MDB to create a bean and puts it into the container it also creates an instance of the MessageDrivenContext. The MessageDrivenContext provides methods for transaction management, Timer service, security services etc. In bean managed transaction based MDB the MessageDrivenContext can be used to set transaction demarcations. The getUserTransaction method returns a javax.transaction.UserTransaction object which can be used to find the status of a transaction or set rollback on a transaction.    

  9. Concurrency
  10. Typical Message consumers are single threaded unless they are specifically written to handle multiple requests. MDB's are by default multithreaded and can handle concurrent requests. The container creates multiple instances of message beans in the pool and allows MDB's to concurrently serve requests. However the container does not guarantee the order in which the request would be served since MDb's are asynchronous clients. It would be the responsibility of the calling program to handle the order.

  11. Transaction management
  12. Like Entity beans, Message driven beans allow either the bean to manage its own transaction or the container takes care of transactions. The type of transaction needs to be specified in the transaction-type attribute of the deployment descriptor. If a bean prefers to deal with transactions by itself then it implements the javax.transaction.UserTransaction interface to demarcate transactions.  

  13. Configuration properties
  14. MDB's provide the flexibility to describe the configuration of the Message driven bean in its deployment environment. This is helpful for deployers to deploy the bean. The information could be message acknowledgement modes, message selectors, destinations etc. 

  15. Message Acknowledgement
  16. Message acknowledgement is automatically handled by the container. If the Message driven bean uses container managed transaction demarcation then the message acknowledgement is done automatically as a part of the transaction commit. If bean managed transaction demarcation is used then the receipt is acknowledged by the container. However the Bean provider can specify the type of acknowledgement in the deployment descriptor. The activation-config-property-value  attribute is used to specify the acknowledge mode. The options are JMS AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE. The JMS AUTO_ACKNOWLEDGE is the default and is assumed if the entry is not specified.

  17. Message Selectors
  18. With Message driven beans the bean provider can restrict the types of messages received by the bean. The bean provider can specify the message selector to determine the messages that the MDB can receive. 

  19. Destinations
  20. A Message driven bean always has an associated destination and it is determined only at deployment time when the bean is being deployed. However the bean provider provides information on whether the message needs to be associated with a Queue or Topic in the deployment descriptor file. The deployer has to associate the actual bean with the destination.  

  21. Exceptions
  22. Message driven beans are not allowed to throw runtime exceptions. A RuntimeException thrown from any method of the message driven bean class results in the bean being thrown into the 'does not exist state'. But as far as the client is concerned it does not know the message consumer and hence does not stop sending messages even if a exception occurs. However the container takes care of it and redirects subsequent requests for the bean to a different instance. 

Deployment Descriptor

In line with the EJB specifications for enterprise beans, Message driven beans have to register themselves in the XML deployment descriptor. A typical descriptor is shown below.

<enterprise-beans>
	session beans or entity beans             ...
	..
	<message-driven>
	<ejb-name>message Bean Name</ejb-name>  
	<ejb-class>com.name.bean.SampleMessageBean</ejb-class>
	<transaction-type>Container</transaction-type>
	<message-driven-destination>
		<destination-type>javax.jms.Queue</destination-type>
		</message-driven-destination>
	<security-identity>
	<run-as><role-name>everyone</role-name></run-as> 
	</security-identity>
	</message-driven>
</enterprise-beans>  

The deployment descriptor defines all the enterprise beans that are defined in a specified ejb-jar file. Message driven beans are defined in the 'message-driven' tags. This includes the Message Driven bean name, class. The 'transaction-type' could be container or bean-managed. The 'message-driven-destination' is either a queue or a Topic, depending on what the bean is supposed to do. The 'security-identity' defines the security roles and permissions for the beans.

Conclusion

Sun has tried its best at standardizing the messaging API and also provide support for messaging in the EJB2.0 specification. However these are just specifications and are left to the vendors for implementation. Just as technologies, like JSP, servlets, and EJBs, Message driven beans will take some time to standardize themselves in the application server market.  

 

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs