Getting Started with WebSphere Application Server
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
120 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> Community Edition<br />
Destination destination =<br />
(Queue)jndiContext.lookup("java:comp/env/jms/myQueue");<br />
The following code snippet shows how to access the queue <strong>with</strong> resource injection.<br />
@Resource(name = "myConnectionFactory")<br />
private ConnectionFactory connectionFactory;<br />
@Resource(name = "jms/myQueue")<br />
private Destination myQueue;<br />
6.4.2 Message-driven beans<br />
The onMessage() method of an MDB is triggered when a message comes to a specific<br />
queue or topic. For this to happen, the deployer has to perform the following:<br />
1. Define a dependency to the JMS resource group in openejb-jar.xml just like<br />
what you did in Listing 6.1<br />
2. Specify the JMS resource link in the openejb-jar.xml as shown in Listing 6.3.<br />
<br />
<br />
GreetingMDB<br />
<br />
myJmsResourceGroup<br />
<br />
<br />
<br />
Listing 6.3 – Define JMS resource link for MDB.<br />
3. Register myQueue as the destination which MDB is listening to as shown in Listing<br />
6.4.<br />
@MessageDriven(activationConfig = {<br />
@ActivationConfigProperty<br />
(propertyName = "destinationType", propertyValue =<br />
"javax.jms.Queue"),<br />
@ActivationConfigProperty<br />
(propertyName = "destination", propertyValue = "myQueue")<br />
})<br />
public class GreetingMDB implements MessageListener {<br />
public void onMessage(Message message) {<br />
TextMessage textMessage = (TextMessage) message;<br />
try {<br />
System.out.println("Recieved message:"+