4.5. Writing Request/Response Applications in Python

This section describes two sample programs that implement a Request/Response application using a Direct exchange.
  • server.py receives messages, converts them to upper case, and sends them back to the original client.
  • client.py sends requests to the server as messages, receives responses and prints them to the screen.

4.5.1. Running the Request/Response Examples

The example programs discussed in this section are found in /usr/share/doc/rhm-0.2/python/request-response. 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. Run the server.
    $ python server.py
    You should see the following output:
    Request server running - run your client now.
    (Times out after 100 seconds ...)
  3. In a separate window, start a client:
    $ python client.py
    You should see the following output:
    Request: Twas brillig, and the slithy toves
    Request: Did gyre and gimble in the wabe.
    Request: All mimsy were the borogroves,
    Request: And the mome raths outgrabe.
    Messages on queue: reply_to:db0f862e-6b36-4e0f-a4b2-ad049eb435ce
    Response: TWAS BRILLIG, AND THE SLITHY TOVES
    Response: DID GYRE AND GIMBLE IN THE WABE.
    Response: ALL MIMSY WERE THE BOROGROVES,
    Response: AND THE MOME RATHS OUTGRABE.
    No more messages!
Now let's take a look at 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 4.1, “Creating and Closing Sessions”.