5.2.1. Running the Direct Examples

5.2.1. Running the Direct Examples

The example programs discussed in this section are found in /usr/share/rhm-docs-0.2/cpp/direct. To run these programs, do the following:

  1. Make sure that a qpidd broker is running:

    $ ps -eaf | grep qpidd
    

    If a broker is running, you should see the qpidd process in the output of the above command. If no broker is running, see the instructions in Chapter 3, Installing MRG Messaging.

  2. In the direct directory, build the examples using make.

    $ make
    
  3. Declare a message queue and bind it to an exchange by running declare_queues, as follows:

    $ ./declare_queues
    

    This program has no output. After this program has been run, all messages sent to the amq.direct exchange using the routing key “routing_key” are sent to the queue named “message_queue”.

  4. Publish a series of messages to the amq.direct exchange by running direct_producer, as follows:

    $ ./direct_producer
    

    This program has no output; the messages are routed to the message queue, as instructed by the binding.

  5. Read the messages from the message queue using direct_consumer or listener, as follows:

    $ ./direct_consumer
    

    or

    $ ./listener
    

    You should see the following output:

    Message: Message 0
    Message: Message 1
    Message: Message 2
    Message: Message 3
    Message: Message 4
    Message: Message 5
    Message: Message 6
    Message: Message 7
    Message: Message 8
    Message: Message 9
    Message: That's all, folks!
    Shutting down listener for message_queue
    

Now we will examine the code for each of these programs. In each section, we will discuss only the code that must be added to the skeleton shown in Section 5.1, “Creating and Closing Sessions”.