Skip Navigation Links | |
Exit Print View | |
Oracle GlassFish Server Message Queue 4.5 Developer's Guide for C Clients |
Message Queue C Client Setup Operations
To Set Up a Message Queue C Client to Produce Messages
To Set Up a Message Queue C Client to Consume Messages Synchronously
To Set Up a Message Queue C Client to Consume Messages Asynchronously
Defining Connection Properties
Working With Secure Connections
Configuring the Client for Secure Communication
Verification Using Fingerprints
Coordinating NSS Initialization
Working With Sessions and Destinations
Getting Information About Destinations
Receiving a Message Synchronously
Receiving a Message Asynchronously
Working With Distributed Transactions
Message Queue Resource Manager Information
When you create a connection, set message header properties, or set user-defined message properties, you must pass a handle to a properties object. You use the MQCreateProperties function to create this object and to obtain a handle to it. When you receive a message, you can use specific MQGet...Property functions to obtain the type and value of each message property.
This section describes the functions you use to set and get properties. A property is defined as a key-value pair.
You use the functions listed in Table 2-1 to create a handle to a properties object, and to set properties. You can use these functions to create and define properties for connections or for individual messages.
Set message properties and message header properties using the same procedure you use to set connection properties. You can set the following message header properties for sending a message:
MQ_CORRELATION_ID_HEADER_PROPERTY
MQ_MESSAGE_TYPE_HEADER_PROPERTY
For more information, see the description of the MQSetMessageProperties() function.
Table 2-1 Functions Used to Set Properties
|
Which function you call depends on the type of the property you want to set; for example, to set an MQString property, you call the MQSetStringProperty function; to set an MQBool property, you call the MQSetBoolProperty function; and so on. Each function that sets a property requires that you pass a key name and value; these are listed and described in Table 4-2.
Once the connection is created with the properties you specify, you cannot change its properties. If you need to change connection properties after you have created a connection, you will need to destroy the old connection and its associated objects and create a new one with the desired properties. It is a good idea to think through the desired behavior before you create a connection.
The code sample below illustrates how you create a properties handle and how you use it for setting connection properties.
MQStatus status; MQPropertiesHandle propertiesHandle = MQ_INVALID_HANDLE; status = (MQCreateProperties(&propertiesHandle); status = (MQSetStringProperty(propertiesHandle, MQ_BROKER_HOST_PROPERTY, “localhost”)); status = (MQSetInt32Property(propertiesHandle, MQ_BROKER_PORT_PROPERTY, 7676)); status = MQSetStringProperty(propertiesHandle, MQ_CONNECTION_TYPE_PROPERTY, “TCP”));
The Message Queue C client runtime sets the connection properties that specify the name and version of the Message Queue product; you can retrieve these using the functionMQGetMetaData(). These properties are described at the end of Table 4-2, starting with MQ_NAME_PROPERTY.
When you receive a message, if you are interested in the message properties, you need to obtain a handle to the properties object associated with that message:
Use the MQGetMessageProperties function to obtain a handle to the properties object for user-defined properties.
If you are interested in any message header properties, use the MQGetMessageHeaderProperties function to obtain a handle to the header properties. See MQGetMessageHeaders.
Having obtained the handle, you can iterate through the properties and then use the appropriate MQGet...Property function to determine the type and value of each property.
Table 2-2 lists the functions you use to iterate through a properties handle and to obtain the type and value of each property.
Table 2-2 Functions Used to Get Message Properties
|
If you know the property key, you can just use the appropriate MQGet...Property function to get its value. The code sample below illustrates how you implement these steps.
MQStatus status; MQPropertiesHandle headersHandle = MQ_INVALID_HANDLE; MQBool redelivered; ConstMQString my_msgtype; status = (MQGetMessageHeaders(messageHandle, &headersHandle)); status = (MQGetBoolProperty(headersHandle, MQ_REDELIVERED_HEADER_PROPERTY, &redelivered)); status = MQGetStringProperty(headersHandle, MQ_MESSAGE_TYPE_HEADER_TYPE_PROPERTY, &my_msgtype);