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-12
SimpleConsumer.cpp
Example 6-4. SimpleConsumer.cpp Sample Client Application (page 1 of 3)
/**
*
* Copyright (c) Hewlett-Packard Company, 2002-2003
* Protected as an unpublished work.
* All rights reserved.
*
* The computer program listings, specifications, and documentation herein
* are the property of Hewlett-Packard Company or a third party supplier and
* shall not be reproduced, copied, disclosed, or used in whole or in part
* for any reason without the prior express written permission of
* Hewlett-Packard Company.
*/
#include <unistd.h>
#include <libgen.h>
#include <cextdecs.h(JULIANTIMESTAMP,BEGINTRANSACTION,ENDTRANSACTION)>
#include "nsjmsc.h"
bool tGiven = FALSE;
bool durable=FALSE;
int msgCount=10;
unsigned long msgSize = 128;
unsigned long messages_received = 0;
char *destName,*subName, *clientId;
Session* pSes;
Consumer* pConsumer;
Message* pMsg;
/**
* Print out information on running this sevice
*/
void usage(char * appName)
{
cerr<<" Usage: "<<basename(appName)<<" [options]"<<endl;
cerr<<" -topic <string> Topic destination name"<<endl;
cerr<<" -name <string> Durable Subscriber subscription name"<<endl;
cerr<<" -id <string> Durable Subscriber client id"<<endl;
cerr<<" -count <number> Number of messages to receive (10)"<<endl;
cerr<<" -help This Message"<<endl;
return;
}
/**
* Receives a message from the destination.
*/
int receive_message()
{
try {
pSes = NULL;
pConsumer = NULL;
pMsg = NULL;
// Use an environment variable to dynamically assign a directory
char *propFile = getenv(“NSJMS_HOME”);
strcat(propFile, “/nsjms.properties”);
pSes = new Session(propFile);