大道废

一切有为法,如梦幻泡影,如露亦如电,当作如是观.

0%

artemis的消息持久问题

根据How does a Queue compare to a Topic的介绍, 以下是原文:

Topics
In JMS a Topic implements publish and subscribe semantics. When you publish a message it goes to all the subscribers who are interested - so zero to many subscribers will receive a copy of the message. Only subscribers who had an active subscription at the time the broker receives the message will get a copy of the message.

Queues
A JMS Queue implements load balancer semantics. A single message will be received by exactly one consumer. If there are no consumers available at the time the message is sent it will be kept until a consumer is available that can process the message. If a consumer receives a message and does not acknowledge it before closing then the message will be redelivered to another consumer. A queue can have many consumers with messages load balanced across the available consumers.

So Queues implement a reliable load balancer in JMS.

说明, 以topic形式出现的消息在没有订阅者的情况下, 并不能持久化, 而是直接丢弃了. 只有发布在queue中才能持久化. 其表现为, 通过MQTT发布的topic, 在没有特别配置的情况下, 就是说在topic与queue都是auto-create的情况下, 消息会在没有消费者的情况下直接丢失.

通过配置storker.xml文件, 可以指定某个address生成queue, 比如:

1
2
3
4
5
<address name="sometopic">
<anycast>
<queue name="sometopic" />
</anycast>
</address>

这时, 发送到这个topic上的消息就可以持久化了.

但这里要注意, 如果是:

1
2
3
4
5
<address name="sometopic">
<multicast>
<queue name="sometopic" />
</multicast>
</address>

会形成一个publish/subscribe形式, 根据上文指出的, 就不会持久化消息.

最后, mqtt缺省的就是publish/subscribe模型, 在没有订阅者的情况下就是会丢失消息.