5.3.1. Running the Fanout Examples

5.3.1. Running the Fanout Examples

The example programs discussed in this section are found in /usr/share/rhm-docs-0.2/cpp/fanout. 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 fanout directory, build the examples using make.

    $ make
    
  3. In separate windows, start two or more fanout listeners as follows:

    $ ./listener
    

    The listener creates a private queue, binds it to the amq.fanout exchange, and waits for messages to arrive on the queue. When the listener starts, you will see the following message:

    Listening
    
  4. In a separate window, publish a series of messages to the amq.fanout exchange by running fanout_producer, as follows:

    $ ./fanout_producer
    

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

  5. Go to the windows where you are running listeners. You should see the following output for each listener:

    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 5ce43b63-83be-4bd3-8545-c16f94d7febf
    

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