NonStop JMS C++ API Programmer's Guide

Using the NSJMS C++ APIs
NonStop Server for Java Message Service C++ API Programmer’s Guide526459-002
5-6
Sending a Message
Sending a Message
NSJMS C++ APIs client uses a Producer to send messages to a specified destination.
A message producer is an object created by a session that is used by clients to send
messages to queues or topics. The PTP messaging application and the Pub/Sub
messaging application both use the Producer class as their message producer.
Sending a message to a Queue or Topic
To send a message to a queue or topic, clients create a Producer object using the
createProducer() method from the Session class.
Creating a queue producer is shown in this code fragment:
char *queueName = “MyQueue”;
// Create a Queue Producer
Producer *pProducer = pSes->createProducer(queueName);
Creating a topic producer is shown in this code fragment:
char *topicName = “MyTopic”;
// Create a Topic Producer
Producer *pProducer = pSes->createProducer(topicName);
Producer class
The Producer class supports three send() methods:
void send(Message *message);
and
void send(Message *message, int deliveryMode, int priority );
and
void send(Message *message, int deliveryMode, int priority,
int64 timeToLive );
Starting a transaction, sending a message using the default send options, and ending
the transaction is shown in this code fragment:
/* Starting Transaction, Sending the Message using the
default send options*/
BEGINTRANSACTION();
pProducer->send(pMsg);
ENDTRANSACTION();
Note. Destinations (queue and topic) must be created prior to use within the NSJMS C++ API.
Use the NSJMS administrative utility ADD Command (see the NonStop Server for Java
Message Service User’s Manual) to create queue and topic destinations.
Note. The Producer send operation must be wrapped within a transaction because the
MESSAGE table is audited.