NonStop JMS C++ API Programmer's Guide
Using the NSJMS C++ APIs
NonStop Server for Java Message Service C++ API Programmer’s Guide—526459-002
5-12
Building NSJMS C++ APIs Client Applications
fragments. It is good practice to always test the message class before casting, so that
unexpected errors are handled gracefully.
// Confirm this is a TextMessage before calling getText()
if (strcmp(pMsg->getJMSType(),"TextMessage") == 0)
// Confirm this is a BytesMessage before calling readBytes()
if (strcmp(pMsg->getJMSType(),"BytesMessage") == 0)
// Confirm this is a MapMessage before calling getXXX()
if (strcmp(pMsg->getJMSType(),"MapMessage") == 0)
// Confirm this is a StreamMessage before calling readXXX()
if (strcmp(pMsg->getJMSType(),"StreamMessage") == 0)
/* Confirm this is an ObjectMessage before calling
readBytes()*/
if (strcmp(pMsg->getJMSType(),"ObjectMessage") == 0)
Using the getJMSType() when retrieving the contents from a TextMessage is shown
in this code fragment:
// Starting Transaction, Receiving the Message
BEGINTRANSACTION();
pMsg = pConsumer->receive(3000);
ENDTRANSACTION();
if (pMsg != NULL)
{
// Confirm this is a TextMessage before calling getText()
if (strcmp(pMsg->getJMSType(),"TextMessage") == 0)
{
char *pText = (( TextMessage* )pMsg)->getText();
cout << "Rcv Message: " << pText << endl;
}
else
{
cout << "Received message was not a TextMessage" <<
endl;
}
}
Building NSJMS C++ APIs Client Applications
This subsection describes how to compile and link user written C++ programs and run
NSJMS C++ API clients that use the NSJMS C++ API classes.
See the /usr/tandem/nsjms/T2811-version/examples/Makefile, for a
working example of compiling and linking NSJMS C++ APIs clients, as described in
these subsections.