Sun Java System Message Queue 4.3 Developer's Guide for C Clients

Setting Connection and Message Properties

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:

For more information, see the description of the MQSetMessageProperties() function.

Table 2–1 Functions Used to Set Properties

Function 

Description 

MQCreateProperties

Creates a properties object and passes back a handle to it. 

MQSetBoolProperty

Sets an MQBool property.

MQSetStringProperty

Sets an MQString property.

MQSetInt8Property

Sets an MQInt8 property.

MQSetInt16Property

Sets an MQInt16 property.

MQSetInt32Property

Sets an MQInt32 property.

MQSetInt64Property

Sets an MQInt64 property.

MQSetFloat32Property

Sets an MQFloat32 property.

MQSetFloat64Property

Sets an MQFloat64 property.

ProcedureTo Set Properties for a Connection

  1. Call the MQCreateProperties function to get a handle to a newly created properties object.

  2. Call one of the MQSet...Property functions to set one of the connection properties described in Table 4–2 . At a minimum, you must specify the name of the host of the broker to which you want to connect and its port number.

    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.

  3. When you have set all the properties you want to define for the connection, you can then create the connection, by calling the MQCreateConnection function.

    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.