Point-to-Point Messaging Example

You are now in a position to start coding. For all the following code examples, you will need to import the javax.jms package. This contains all the classes for creating connections, sessions, and destinations.

Connecting to a Queue

To send a JMS message, a number of steps must first be performed. You must

Obtain a ConnectionFactory
Establish a Session
Create a MessageProducer object

Although this example is in the point-to-point message domain, the same steps are required for publish/subscribe topics.

The following steps show how to create a queue used later to send a simple text message.

Obtain the JNDI initial context.
Context context = new InitialContext();
Contact the JMS provider, obtain ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.