Message Queue C Client Setup Operations
The general procedures for producing and consuming messages are introduced below. The procedures
have a number of common steps which need not be duplicated if a
client is both producing and consuming messages.
To Set Up a Message Queue C Client to Produce Messages
- Call the MQCreateProperties function to get a handle to a properties object.
- Use one or more of the MQSet...Property functions to set connection properties that
specify the name of the broker, its port number, and its behavior.
- Use the MQCreateConnection function to create a connection.
- Use the MQCreateSession function to create a session and to specify its acknowledge
mode and its receive mode. If the session will be used only for
producing messages, use the receive mode MQ_SESSION_SYNC_RECEIVE to avoid creating a thread
for asynchronous message delivery.
- Use the MQCreateDestination function to specify a physical destination on the broker. The
destination name you specify must be the same as the name of the
physical destination.
- Use the MQCreateMessageProducer function or the MQCreateMessageProducerForDestination function to create a message producer. (If
you plan to send a lot of messages to the same destination, you
should use the MQCreateMessageProducerForDestination function.)
- Use the MQCreateBytesMessage function or the MQCreateTextMessage function to get a newly
created message handle.
- Call the MQCreateProperties function to get a handle to a properties object that
will describe the message header properties. This is only required if you want
to set a message header property.
- Use one or more of the MQSet...Property functions to set properties that specify
the value of the message header properties you want to set.
- Use the MQSetMessageHeaders function, passing a handle to the properties object you created
in Step 8 and Step 9.
- Repeat Step 8 if you want to define custom message properties, and then
use the MQSetMessageProperties function to set these properties for your message.
- Use the MQSetMessageReplyTo function if you want to specify a destination where replies
to the message are to be sent.
- Use one of the MQSendMessage... functions to send the message.
To Set Up a Message Queue C Client to Consume Messages Synchronously
- Call the MQCreateProperties function to get a handle to a properties object.
- Use one or more of the MQSet...Property functions to set connection properties that
specify the name of the broker, its port number, and its behavior.
- Use the MQCreateConnection function to create a connection.
- Use the MQCreateSession function to create a session and to specify its receive
mode. Specify MQ_SESSION_SYNC_RECEIVE for a synchronous session.
- Use the MQCreateDestination function to specify a destination on the broker from which
the consumer is to receive messages. The destination name you specify must be
the same as the name of the physical destination.
- Use the MQCreateMessageConsumer function or the MQCreateDurableMessageConsumer function to create a consumer.
- Use the MQStartConnection function to start the connection.
- Use one of the MQReceiveMessage... functions to start message delivery.
To Set Up a Message Queue C Client to Consume Messages Asynchronously
- Call the MQCreateProperties function to get a handle to a properties object.
- Use one or more of the MQSet...Property functions to set connection properties that
specify the name of the broker, its port number, and its behavior.
- Use the MQCreateConnection function to create a connection.
- Use the MQCreateSession function to create a session and to specify its acknowledge
mode and its receive mode. Specify MQ_SESSION_ASYNC_RECEIVE for asynchronous message delivery.
- Use the MQCreateDestination function to specify a destination on the broker from which
the consumer is to receive messages. The logical destination name you specify must
be the same as the name of the physical destination.
- Write a callback function of type MQMessageListenerFunc that will be called when the
broker starts message delivery. In the body of this callback function, use the
functions described in Processing a Message , to process the contents of the incoming
message.
- Use the MQCreateAsyncMessageConsumer function or the MQCreateAsyncDurableMessageConsumer function to create a consumer.
- Use the MQStartConnection function to start the connection and message delivery.