Transient or durable subscriptions

Transient subscriptions

A transient subscription is one where messages are delivered to the message consuming application only when that application is running and connected to the broker. Messages that are produced while the consumer application is not running or is off-line are lost.

To implement transient subscriptions, use the auto-delete option of the queue when doing the Queue.Declare. If you set this option, the queue will be destroyed once the application disconnects from the broker and all messages in the queue will be dropped. When the application reconnects, it will create the queue anew and start receiving messages.

A simple instant messaging application demonstrates the concept of transient queues. Here are the source files:

To compile and link the files set your environment in the same way as you do to build OpenAMQ server and do the following:

$ c -l im_sender.c
Compiling im_sender...
Linking im_sender...
$ c -l im_receiver.c
Compiling im_receiver...
Linking im_receiver...

To run the whole thing, you have to start OpenAMQ server first:

$ amq_server

Once the server is running you can run chatroom window this way:

$ ./im_receiver <broker-address> <chatroom>

For example:

$ ./im_receiver localhost:5672 "OpenAMQ discussion"

To send messages to the chatroom, you have to run sender window this way:

$ ./im_sender <broker-address> <chatroom> <your-name>

For example:

$ ./im_sender "OpenAMQ discussion" "Baron Bartholomaeus von Saburg-Fridetzki"

There can be any number of clients connected to the same chat room. There's no need to create chat rooms explicitly. These are created on demand.

Durable subscriptions

A durable subscription means that messages you are subscribed to will be delivered to you even though your message consuming application is not running at the particular point of time. Once it reconnects to the broker, all the messages that were posted in the meantime will be delivered immediately.

The examples in the AMQ model tutorial show how to implement durable subscriptions.


Add a New Comment

Edit | Files | Tags | Source | Print

rating: +2+x


Martin Sustrik <moc.xitami|kirtsus#moc.xitami|kirtsus>

All tutorials

Performance Tests: This tutorial explains how to do OpenAMQ performance tests using 0MQ performance testing framework.

Broker federation: How to setup a geographically distributed federation of OpenAMQ brokers and how to define dataflows between individual geographical locations.

The ESB cookbook: How to implement your own Enterprise Service Bus, step by step, using OpenAMQ.

Publishing contents: How to publish contents at high speed without bizarre memory issues.

Tuning OpenAMQ for low latency: How to tune your operating system and hardware to get the lowest latency, i.e. the best response times, from your OpenAMQ broker.

The mandatory and immediate flags: How to use the 'mandatory' and 'immediate' flags on the Basic.Publish method.

Load balancing: How to use OpenAMQ to distribute work between multiple applications, a technique called "load balancing".

Content based routing: How to route messages based on their header properties. It is a fast and simple way to do 'content based routing' without needing to inspect entire messages. We explain the principles and provide worked examples.

Transient or durable subscriptions: How to make subscriptions that are transient (come and go with their consuming applications) or durable (stay around).

The AMQ model: How the AMQ model works: this is a basic backgrounder for anyone starting to use OpenAMQ in their applications.

Developing on Windows: How to build OpenAMQ client applications using MSVC on Windows

Handling Ctrl-C in applications: How to properly detect an interrupt (Ctrl-C) and shut-down gracefully in C/C++ WireAPI applications.