Chapter 2. Examples Overview

This tutorial consists of a series of examples in Python, C++, and Java JMS, using the three most commonly used exchange types in MRG Messaging - Direct, Fanout and Topic exchanges. These examples show how to write applications that use the most common messaging paradigms. This chapter contains descriptions of each of the paradigms used throughout the examples. After these examples, there are a few brief sections that show how to enable durable queues and messages, and how to use transactions.

Overview of the C++, Python, and Java JMS Examples

In the direct examples, a message producer writes to the direct exchange, specifying a routing key. A message consumer reads messages from a named queue. A separate configuration program binds the queues, determining which routing keys are associated with each queue. This illustrates clean separation of concerns - message producers need to know only the exchange and the routing key, message consumers need to know only which queue to use on the broker. By changing the bindings in the configuration program, messages can be routed in different ways without affecting message producers or message consumers.
The fanout examples use a fanout exchange and do not use routing keys. Each binding specifies that all messages for a given exchange should be delivered to a given queue.
In the publish/subscribe examples, a publisher application writes messages to an exchange, specifying a multi-part key. A subscriber application subscribes to messages that match the relevant parts of these keys, using a private queue for each subscription.
In the request/response examples, a simple service accepts requests from clients and sends responses back to them. Clients create their own private queues and corresponding routing keys. When a client sends a request to the server, it specifies its own routing key in the reply-to field of the request. The server uses the client's reply-to field as the routing key for the response.
MRG Messaging provides guaranteed delivery unless the server crashes. Durable queues and durable messages are stored using persistent storage on the server, and restored when the broker is restarted, providing guaranteed delivery even if there is a crash. This section shows how to make queues and messages durable.
This section shows how to use local server transactions, which buffer published messages and acknowledgements and process them upon commit, guaranteeing that they will all succeed or fail as a unit.
XML Exchange
This section shows how to declare an XML Exchange and use it to route XML messages based on their content, using XQuery. Because the XML Exchange can not currently be declared in a pure Java JMS program, this example is shown only for C++ and Python clients. (Java JMS programs can declare an exchange and an XQuery binding using Python or C++, then use the corresponding exchange and queues using Java JMS. There is also a low level Java API which supports custom exchanges, but this API is not yet documented.)