10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

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.

Coding the Message-Driven Bean: MessageBean.java<br />

<strong>The</strong> message-driven bean class, clientsessionmdb-ejb/src/java/mdb/MessageBean.java,is<br />

almost identical to the one in Chapter 23, “A Message-Driven Bean Example.” However, the<br />

@MessageDriven annotation is different, because instead of a queue the bean is using a topic<br />

with a durable subscription, and it is also using a message selector. <strong>The</strong>refore, the annotation<br />

sets the activation config properties messageSelector, subscriptionDurability, clientId,<br />

and subscriptionName, as follows:<br />

@MessageDriven(mappedName="jms/Topic",<br />

activationConfig=<br />

{ @ActivationConfigProperty(propertyName="messageSelector",<br />

propertyValue="NewsType = ’Sports’ OR NewsType = ’Opinion’"),<br />

@ActivationConfigProperty(<br />

propertyName="subscriptionDurability",<br />

propertyValue="Durable"),<br />

@ActivationConfigProperty(propertyName="clientId",<br />

propertyValue="MyID"),<br />

@ActivationConfigProperty(propertyName="subscriptionName",<br />

propertyValue="MySub")<br />

})<br />

<strong>The</strong> JMS resource adapter uses these properties to create a connection factory for the<br />

message-driven bean that allows the bean to use a durable subscriber.<br />

Creating Resources for the clientsessionmdb<br />

Example<br />

This example uses the topic named jms/Topic and the connection factory<br />

jms/ConnectionFactory, which you created in “Creating JMS Administered Objects for the<br />

Synchronous Receive Example” on page 910. If you deleted the connection factory or topic, you<br />

can create them again using targets in the build.xml file for this example. Use the following<br />

commands to create the resources:<br />

ant create-cf<br />

ant create-topic<br />

A <strong>Java</strong> <strong>EE</strong> ApplicationThat Uses the JMS API with a Session Bean<br />

Building, Deploying, and Running the<br />

clientsessionmdb Example Using NetBeans IDE<br />

To build, deploy, and run the application using NetBeans IDE, do the following:<br />

1. Start the Application Server, if it is not already running.<br />

2. In NetBeans IDE, choose Open Project from the File menu.<br />

Chapter 32 • <strong>Java</strong> <strong>EE</strong> Examples Using the JMS API 959

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

Saved successfully!

Ooh no, something went wrong!