对这两个术语有点困惑,我在想拥有持久消息但瞬态(非持久)队列的目的是什么?毕竟,如果代理重新启动并且队列未恢复,则恢复的消息将被浪费。
1 回答
You can have durable queue but "mortal" messages, so after broker restarts you can still have queue but it will be empty and vice versa, but as you sad, yes, you'll lose all messages in the queue.
In the combination you provided message persistence option is really useless but will cause no error.
But if you bind alternate exchange to exchange you are publishing messages to and it is durable, after restart, your can route messages to it if you don't have transient queue declared.
Example:
Assume we have such combination and properly bound queues, Q*1
receive messages M*1
and Q*2
- M*2
.
[ Exchange-main/durable ] + [Exchange-alternate/durable]
[Qm1/transient][Qm2/transient] [Qax1/durable][Qax2/durable]
Let's publish messages [Mt1/transient]
and `[Md1/durable], we'll get such situation:
[ Exchange-main/durable ] + [Exchange-alternate/durable]
[Qm1/transient][Qm2/transient] [Qax1/durable][Qax2/durable]
[Mt1/transient]
[Md1/durable]
After restart we'll get
[ Exchange-main/durable ] + [Exchange-alternate/durable]
[Qax1/durable][Qax2/durable]
Let's publish two messages again, [Mt1/transient]
and `[Md1/durable]:
[ Exchange-main/durable ] + [Exchange-alternate/durable]
[Qax1/durable][Qax2/durable]
[Mt1/transient]
[Md1/durable]
So, restart broker again:
[ Exchange-main/durable ] + [Exchange-alternate/durable]
[Qax1/durable][Qax2/durable]
[Md1/durable]