12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter<br />

20<br />

20Message-Driven Beans and JMS<br />

Chapter<br />

Important<br />

For documentation updates, go to www.borland.com/techpubs/bes.<br />

JMS and EJB<br />

According to the EJB 2.0 specification, there are no limitations on a bean acting as a<br />

JMS message producer or synchronous consumer. It can use the regular JMS APIs to<br />

send a message to a queue or publish to a topic. As long as you perform synchronous<br />

style consumption of messages (that is, not based on javax.jms.MessageListener), then<br />

there are no problems on the consumption side either. The complexity lies in wanting<br />

the sending/receiving of the message to share the transaction context of some other<br />

piece of work. We already know how to solve this problem using JMS and JTA in<br />

conjunction. The EJBs demand no special treatment.<br />

Since EJB method invocations are synchronous, some calls will have to wait until the<br />

bean has completed its processing. This may include calling other beans, databases,<br />

and so forth. This RMI behavior can be undesirable in many situations. For example,<br />

you may just want to call the method and have it return before doing any heavy<br />

processing, allowing the caller to proceed with other tasks in the meantime. Threading<br />

in the client is an obvious way to achieve this, but it suffers from two problems:<br />

■<br />

■<br />

the client's programming model is not a true asynchronous style<br />

if the client is an EJB, threading is prohibited in its method implementations<br />

Chapter 20: Message-Driven Beans and JMS 183

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!