Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Writing Direct Applications

This section describes three two programs that implement direct messaging using a Direct
exchange:
• org.apache.qpid.example.direct.Producer (from example-direct-producer) publishes messages to the amq.direct exchange, using the routing key routing_key.
•org.apache.qpid.example.direct.Listener (from example-direct-Listener) uses a message listener to receive messages from the queue named message_queue.

Running the Direct Examples

1) Make sure your PATH contains the directory <home>/qpid/lib

2) Make sure that a qpid broker is running:

Code Block

$ ps -eaf | grep qpidd

If a broker is running, you should see the qpidd process in the output of the above
command.

3) Publish a series of messages to the amq.direct exchange by running direct producer, as follows:

Code Block

$ cd <home>/qpid/examples/direct

With cygwin:

Code Block

$ ./example-direct-Producer.exe  

or with mono:

Code Block

$ mono ./example-direct-Producer.exe

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

4) Read the messages from the message queue using direct consumer or listener, as follows:

Code Block

$ cd <home>/qpid/examples/direct

With cygwin:

Code Block

$ ./example-direct-Listener.exe  

or with mono:

Code Block

$ mono ./example-direct-Listener.exe

You should see the following output:

Code Block

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 "Creating and Closing Sessions".