12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

JMS and Transactions<br />

and its accompanying <strong>Borland</strong> descriptor application-client-borland.xml:<br />

JMS and Transactions<br />

<br />

...<br />

<br />

jms/MyJMSTopicConnectionFactory<br />

resources/tcf<br />

<br />

<br />

jms/MyJMSTopic<br />

resources/t<br />

<br />

...<br />

<br />

Now let's see how we obtain object references to a JMS connection factory and a<br />

destination in the application logic. In retrieval of the connection factory, the application<br />

performs a JNDI lookup of the value from element in the<br />

J2EE deployment descriptor. To retrieve the destination object, a JNDI lookup is<br />

performed against the value of element in the<br />

J2EE deployment descriptor. The names specified for are identical to JNDI<br />

names in elements of the JMS resource definitions in a deployed DAR<br />

module. When a lookup succeeds a JMS resource object is obtained, that is, for JMS<br />

connection factory identified through logical name jms/MyJMSTopicConnectionFactory a<br />

deployed JMS definition object is retrieved from the Naming Service under resources/<br />

tcf and from it a connection factory object is created and returned to the application.<br />

For example, the application client code associated with client descriptors provided<br />

above resolves JMS resource objects as follows:<br />

javax.jms.TopicConnectionFactory myTCF;<br />

javax.jms.Topic myTopic;<br />

try {<br />

javax.naming.Context ctx = (javax.naming.Context) new<br />

javax.naming.InitialContext();<br />

myTCF = (TopicConnectionFactory) ctx.lookup("java:comp/env/jms/<br />

MyJMSTopicConnectionFactory");<br />

// Now ready to obtain a connection from myTCF<br />

myTopic = (Topic) ctx.lookup("java:comp/env/jms/MyJMSTopic");<br />

...<br />

}<br />

catch (javax.naming.NamingException exp) {<br />

exp.printStackTrace();<br />

}<br />

The rules for using JMS APIs in EJB bean code with transactions are discussed in the<br />

EJB 2.0 specification section 17.3.5.<br />

Following is an extract:<br />

17.3.5 Use of JMS APIs in transactions<br />

The Bean Provider must not make use of the JMS request/reply paradigm (sending of a<br />

JMS message, followed by the synchronous receipt of a reply to that message) within<br />

a single transaction.<br />

Because a JMS message is not delivered to its final destination until the<br />

transaction commits, the receipt of the reply within the same transaction will<br />

never take place. Because the container manages the transactional enlistment of JMS<br />

216 BES Developer’s Guide

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

Saved successfully!

Ooh no, something went wrong!