NonStop JMS User's Manual (H06.03+, J06.03+, NonStop JMS 3.0+)

NSJMS and JMS Client Applications
NonStop Server for Java Message Service User’s Manual522356-006
4-7
Sending Messages
Sending Messages
A JMS client uses a MessageProducer to send messages to a specified destination. A
message producer is an object created by a session that is used by JMS clients to
send messages to queues or topics. The PTP messaging application uses the
QueueSender interface as its message producer, and the Pub/Sub messaging
application uses the TopicPublisher interface as its message producer.
Sending a message to a Queue
To send a message to a queue, you create a QueueSender using the
createSender() method. This code fragment sends a message to a queue:
QueueSender.send(aMessage);
Sending a message to a Topic
To send a message to a topic, you create a TopicPublisher using the
createPublisher() method. This code fragment publishes a message to a topic:
TopicPublisher.publish(aMessage);
Specifying a Destination
A QueueSender or TopicPublisher is typically created for a specific queue or topic. This
ensures that all messages sent using the QueueSender or TopicPublisher are sent to
the specific queue or topic. The destination of the queue or topic is specified using a
Queue or Topic object. Queue and Topic objects can be built and stored in a JNDI
namespace or created at runtime.
Retrieve Queue or Topic Objects from a JNDI Namespace
Retrieving a Queue object from a JNDI namespace is shown in this code fragment:
Queue queue = (Queue)jndiContext.lookup(queueName);
Retrieving a Topic object from a JNDI namespace is shown in this code fragment:
Topic topic = (Topic)jndiContext.lookup(topicName);
Create Queue or Topic Objects at Runtime
This code fragment creates a Queue object dynamically:
Queue queue = (Queue)session.createQueue(queueName);
This code fragment creates a Topic object dynamically:
Topic topic = (Topic)session.createTopic(topicName);