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, queues, and topics.

To send a JMS message, a number of steps must first be performed to obtain a connection factory, establish a session, and create a QueueSender object. Although the 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.

1.
Obtain the JNDI initial context.
Context context = new InitialContext();
2.
Contact the JMS provider, obtain a JMS connection from the appropriate ...

Get Sams Teach Yourself J2EE™ in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.