On 01/21/2014 07:28 AM, Xiong Zou wrote:
Hi All,
I am thinking to have a message source to publish messages to exchange
amq.topic with a routing key like USA.news, thus all client subscribers to
this exchange with routing key USA.news will receive a copy of each message
of USA.news.
Now I would like to have the client subscribers to be able to recover all
published USA.news messages once any of them re-started. How can I achieve
this purpose?
[...]
Can I use qpid-config to do following?
1. add a persistent queue "Persistent.USA.news",
qpid-config --durable add queue Persistent.USA.news
2. then bind this queue to exchange amq.topic
qpid-config bind amq.topic Persistent.USA.news USA.news
3. like ./drain 'Persistent.USA.news; {mode: browse}' to browse all existing
messages for recovery.
The problem with that is that if all the client subscribers browse the
queue, then the messages will never be deleted and the queue will grow
without limit.
Depending on use case, there are a couple of ways around that if this
approach is otherwise attractive. You can limit the queue to a certain
number of messages, with older ones discarded. That way the queue always
has the last N messages and subscribers can browse them all.
Another possible downside though is that when a subscriber restarts, it
will get all N messages, regardless of whether it already saw them.
Another possible solution to the growing queue is to use a 'last value
queue'. This works if the messages can be viewed as updates to some
previous message. You choose a logical key and when a new message with a
given key arrives, it causes the last message with the same key to be
removed.
and how to ensure messages delivered to queue "Persistent.USA.news" to be
persistent even if qpidd restarted?
You need to make sure the publisher(s) mark(s) the messages as
persistent. Unfortunately at present the c++ broker doesn't provide a
way to override that on the broker side.
Or is there any other ways to achieve the same?
Which API are you using?
With JMS there is a specific durable subscriber API that you can use.
With the Qpid messaging API, you can just specify an appropriate address
when creating the receiver. E.g.
amq.topic/USA.news; {link:{name:my-subscription, durable:True}}
That will result in a persistent queue being bound to amq,topic with key
USA.news. You need to ensure that each subscriber chooses a unique name
for their subscription, as this will be used to identify the appropriate
queue when restarting.
Be aware that if a subscriber is inactive for a long period, or never
restarts for some reason, the queue will remain and will keep growing,
which may eventually cause problems.
One way to work around that problem is to add a timeout to the queue,
such that if it is inactive for a certain period it will be cleaned up.
You can do this using the qpid.auto_delete_timeout property, e.g. to
clean up after 5 minutes:
amq.topic/USA.news; {link:{name:my-subscription, durable:True,
x-declare:{auto-delete:True, arguments:{qpid,auto_delete_timeout:350}}}}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]