NonStop JMS C++ API Programmer's Guide
NSJMS C++ API Sample Client Applications
NonStop Server for Java Message Service C++ API Programmer’s Guide—526459-002
6-3
SimpleSender.cpp
// Creating the Producer.
pProducer = pSes->createProducer(destName);
for (unsigned long count = 0; count < msgCount; count++)
{
strstream msg;
// Setting Message
msg<<"Sending message "<<count<<ends;
cout << msg.str() << endl;
// Creating Test Message
pMsg = pSes->createTextMessage();
pMsg->setStringProperty("test","SimpleSender");
// Setting Text
pMsg->setText (msg.str());
// Starting Transaction Sending the Message
BEGINTRANSACTION();
pProducer->send(pMsg, deliveryMode,PRIORITY,DEFAULT_JMSEXPIRATION);
ENDTRANSACTION();
// Freeing Message
pSes->freeMessage(pMsg);
pMsg = NULL;
}
long long end = JULIANTIMESTAMP();
long long perf = (julianToMillis(end) - julianToMillis(start));
cout<<"Finished Sending "<<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-1. SimpleSender.cpp Sample Client Application (page 2 of 3)