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.

textMessage.getText());<br />

} catch (JMSException e) {<br />

e.printStackTrace();<br />

}<br />

}<br />

}<br />

Listing 6.4 – Sample MDB that uses JMS Destination<br />

Chapter 6 – Messaging 121<br />

6.4.3 Stand-alone Java application<br />

With message provider specific APIs, you can access JMS resources in stand-alone Java<br />

applications. For example, you can use ActiveMQ API ActiveMQConnectionFactory<br />

to access JMS resources in Community Edition.<br />

To access JMS resources in Community Edition using ActiveMQConnectionFactory, you<br />

need to add following packages under /repository/ in the classpath:<br />

org/apache/activemq/activeio-core/3.0.1/activeio-core-3.0.1.jar<br />

org/apache/activemq/activemq-core/4.1.2/activemq-core-4.1.2.jar<br />

org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimojms_1.1_spec-1.1.1.jar<br />

backport-util-concurrent/backport-util-concurrent/2.2/backport-utilconcurrent-2.2.jar<br />

commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar<br />

org/apache/geronimo/specs/geronimo-j2eemanagement_1.1_spec/1.0.1/geronimo-j2ee-management_1.1_spec-1.0.1.jar<br />

After that, you can use ActiveMQConnectionFactory in your stand-alone Java application.<br />

The code snippet in Listing 6.5 shows how to use the JMS resources in a stand-alone Java<br />

application.<br />

ActiveMQConnectionFactory connectionFactory = new<br />

ActiveMQConnectionFactory("tcp://localhost:61616");<br />

Connection connection = connectionFactory.createConnection();<br />

Session session =<br />

connection.createSession(false,Session.AUTO_ACKNOWLEDGE);<br />

Destination topic = session.createQueue("myTopic");<br />

Listing 6.5 – Use JMS Resources in stand-alone Java application<br />

6.5 Summary<br />

In this chapter we discussed the typical steps to develop JMS applications. We also<br />

described how to configure a JMS resource group and how to develop JMS applications<br />

<strong>with</strong> the created JMS resource in Community Edition.

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

Saved successfully!

Ooh no, something went wrong!