16.10.2015 Views

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.

Chapter 6 – Messaging 119<br />

For example, to use the JMS resource group<br />

console.jms/myJmsResourceGroup/1.0/rar you just created in Community<br />

Edition, you could add the dependency in the application deployment plan as shown in<br />

Listing 6.1.<br />

<br />

<br />

console.jms<br />

myJmsResourceGroup<br />

1.0<br />

rar<br />

<br />

<br />

Listing 6.1 - Defining dependencies to the JMS resource group in geronimoweb.xml<br />

or openejb-jar.xml<br />

6.4.1 Accessing queues or topics from a Web application<br />

Developers specify resource references and resource environment references to the<br />

connection factories, queues, and topics used in their JSPs and Servlets.<br />

For a Web application that sends messages to myQueue, you still need to define the<br />

resource referenced in web.xml of the Web application. Listing 6.2 shows web.xml <strong>with</strong><br />

resource references.<br />

<br />

myConnectionFactory<br />

javax.jms.ConnectionFactory<br />

Container<br />

Shareable<br />

<br />

<br />

jms/myQueue<br />

javax.jms.Queue<br />

Produces<br />

myQueue<br />

<br />

Listing 6.2 - web.xml <strong>with</strong> resource references<br />

In the following code examples, myConnectionFactory and jms/myQueue are logical<br />

names used in the application. The following code snippet shows how to access the queue<br />

<strong>with</strong> JNDI look up.<br />

Context jndiContext = new InitialContext();<br />

ConnectionFactory connectionFactory = (ConnectionFactory)jndiContext<br />

.lookup("java:comp/env/myConnectionFactory");

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

Saved successfully!

Ooh no, something went wrong!