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:
Once the server is running you can run chatroom window this way:
$ ./im_receiver <broker-address> <chatroom>
$ ./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>
$ ./im_sender 127.0.0.1:5672 "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.
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.