Sun GlassFish Message Queue 4.4 Developer's Guide for C Clients

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.

ProcedureTo Set Up a Message Queue C Client to Produce Messages

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

  2. 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.

  3. Use the MQCreateConnection function to create a connection.

  4. 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.

  5. 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.

  6. 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.)

  7. Use the MQCreateBytesMessage function or the MQCreateTextMessage function to get a newly created message handle.

  8. 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.

  9. 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.

  10. Use the MQSetMessageHeaders function, passing a handle to the properties object you created in Step 8 and Step 9.

  11. Repeat Step 8 if you want to define custom message properties, and then use the MQSetMessageProperties function to set these properties for your message.

  12. Use the MQSetMessageReplyTo function if you want to specify a destination where replies to the message are to be sent.

  13. Use one of the MQSendMessage... functions to send the message.

ProcedureTo Set Up a Message Queue C Client to Consume Messages Synchronously

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

  2. 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.

  3. Use the MQCreateConnection function to create a connection.

  4. Use the MQCreateSession function to create a session and to specify its receive mode. Specify MQ_SESSION_SYNC_RECEIVE for a synchronous session.

  5. 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.

  6. Use the MQCreateMessageConsumer function or the MQCreateDurableMessageConsumer function to create a consumer.

  7. Use the MQStartConnection function to start the connection.

  8. Use one of the MQReceiveMessage... functions to start message delivery.

ProcedureTo Set Up a Message Queue C Client to Consume Messages Asynchronously

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

  2. 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.

  3. Use the MQCreateConnection function to create a connection.

  4. 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.

  5. 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.

  6. 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.

  7. Use the MQCreateAsyncMessageConsumer function or the MQCreateAsyncDurableMessageConsumer function to create a consumer.

  8. Use the MQStartConnection function to start the connection and message delivery.