5.6.1. Running the XML-based Routing Examples
The example programs discussed in this section are found in /usr/share/rhm-docs-0.2/python/xml-exchange. To run these programs, do the following:
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.
Declare an XML exchange and a message queue, then bind the queue to the 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 xml exchange using the routing key query_name are sent to the queue named message_queue if they satisfy the conditions specified in the following XQuery, which is used in the binding:
declare variable $control external; ./message/id mod 2 = 1 or $control = 'end'
This query is true if the message ID is an odd number or if the message has an application header of control='end'.
Publish a series of messages to the xml exchange by running xml_producer.py, as follows:
$ ./xml_producer
You will see the following output, which shows the messages that are produced:
Message data: <message><id>0</id></message> Message data: <message><id>1</id></message> Message data: <message><id>2</id></message> Message data: <message><id>3</id></message> Message data: <message><id>4</id></message> Message data: <message><id>5</id></message> Message data: <message><id>6</id></message> Message data: <message><id>7</id></message> Message data: <message><id>8</id></message> Message data: <message><id>9</id></message> >
Read the messages from the message queue using listener, as follows:
$ ./listener
You should see the following output:
Message: <message><id>1</id></message> Message: <message><id>3</id></message> Message: <message><id>5</id></message> Message: <message><id>7</id></message> Message: <message><id>9</id></message> Message: <end>That's all, folks!</end> 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”.