NonStop JMS C++ API Programmer's Guide

NSJMS C++ API Sample Client Applications
NonStop Server for Java Message Service C++ API Programmer’s Guide526459-002
6-10
SimplePublisher.cpp
// Creating the Producer.
pProducer = pSes->createProducer(destName);
long long start = JULIANTIMESTAMP();
for (unsigned long count = 0; count < msgCount; count++)
{
strstream msg;
// Setting Message
msg<<"Publishing this message " << count << ends;
cout << msg.str() << endl;
// Creating Test Message
pMsg = pSes->createTextMessage();
// Setting Text
pMsg->setText (msg.str());
// Starting Transaction Sending the Message
BEGINTRANSACTION();
pProducer->send(pMsg, deliveryMode, PRIORITY,
DEFAULT_JMSEXPIRATION);
ENDTRANSACTION();
pSes->freeMessage(pMsg);
pMsg = NULL;
}
long long end = JULIANTIMESTAMP();
long long perf = (julianToMillis(end) - julianToMillis(start));
cout<<"Finished Publishing "<<msgCount<<" messages, took "<< perf <<
" msecs"<<endl;
//Freeing the producer object.
pSes->freeProducer(pProducer);
delete pSes;
}
catch (NSJMS_Exception & excp)
{
cout << "NSJMS_Exception: " << excp.getClassName() << ", " <<
excp.getMessage() << endl;
pSes->freeMessage(pMsg);
pSes->freeProducer(pProducer);
return 1;
}
catch (exception & excp)
{
cout << excp.what() << endl;
return 1;
}
return 0;
}
int main(int argc, char* argv[])
{
int optind;
for (optind = 0; optind < argc; optind++)
{
Example 6-3. SimplePublisher.cpp Sample Client Application (page 2 of 3)