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-3
Creating a Session
Creating a Session
A Session is a context used to create and free all NSJMS C++ APIs objects. A Session
provides methods for creating Consumers (receivers and subscribers), Producers,
Durable Subscribers, BytesMessages, MapMessages, ObjectMessages,
StreamMessages, and TextMessages.
A Session object is created using a constructor which specifies a file name containing
the NSJMS properties file. These properties are used to configure NSJMS clients, as
well as NSJMS C++ API clients. If the name is unqualified, the current working
directory is assumed. This constructor is used by clients as the first call to initiate
NSJMS C++ APIs sessions.
Creating a Session object when using a properties file in the current working directory
is shown is this code fragment:
// Create a new session
Session *pSes = new Session("nsjms.properties");
Creating a Session object when using an environment variable to dynamically assign a
directory is shown in this code fragment:
char *propFile = getenv("NSJMS_HOME");
strcat(propFile, "/nsjms.properties");
pSes = new Session(propFile);
Populating a Message with Data
The NSJMS and NSJMS C++ APIs messaging products treat messages as entities
that consist of a header, a body, and, optionally, application-defined property values.
The header contains fields used for message routing and identification; the body
contains the application data being sent.
Prior to populating a message with data, the client must first create a message object
as shown in these code fragments:
// Creating a Text Message
TextMessage *pMsg = pSes->createTextMessage();
// Creating a Bytes Message
BytesMessage *pMsg = pSes->createBytesMessage();
// Creating a Map Message
MapMessage *pMsg = pSes->createMapMessage();
// Creating a Stream Message
StreamMessage *pMsg = pSes->createStreamMessage();
// Creating a Object Message
ObjectMessage *pMsg = pSes->createObjectMessage();
Note. Creating a Session object must be done prior to creating any other NSJMS C++ API
objects.