python - 如何接收 STOMP 中丢失的消息?

标签 python activemq publish-subscribe stomp

我有一个 python 脚本,它必须在 Linux 服务器上 24/7 运行,并通过 STOMP 从另一台服务器接收 ActiveMQ 推送通知。脚本可能会因任何原因失败并关闭一段时间,显然最多 30 分钟,平均只有几分钟。

如果脚本之前已关闭,我需要在脚本再次启动后以某种方式接收丢失的消息通知。据我了解,我的理解是有限的,这是可能的,一旦我的脚本启动,服务器就会发送它们。这就是我相信的事实

https://activemq.apache.org/apollo/documentation/stomp-manual.html#Topic_Durable_Subscriptions

A durable subscription is a queue which is subscribed to a topic so that even if the client which created the durable subscription is not online, he can still get a copy of all the messages sent to the topic when he comes back online. Multiple clients can subscribe to the same durable subscription and since it's backed by a queue, those subscribers will have the topic's messages load balanced across them.

在Python中:

import stomp

# ....
conn.subscribe(destination="/topic/some_topic", id=1, ack="auto", headers={"activemq.subscriptionName": "SampleSubscription"})

是我想的那样吗?

我的脚本再次启动后会收到丢失的消息吗?

“id”总是等于 1 吗?

更新:

以下是我在 Python 中的 on_message 方法中收到的 header :

{
'priority': '4', 
'persistent': 'true', 
'message-id': 'fdsfds', 
'expires': '432432432', 
'destination': '/topic/fdsfds', 
'timestamp': '42343243', 
'subscription': '0', 
'type': 'aaaaa'
}

“持久”和“订阅”是否意味着如果我的客户端消费者处于离线状态,那么一旦它再次上线,它将发送离线时错过的所有消息?

最佳答案

对于 Apache ActiveMQ,请查看 http://activemq.apache.org/stomp.html 上的文档。它指定 SUBSCRIBE 帧上的 header 必须是 activemq.subscriptionName。

对于 ActiveMQ Apollo,请检查 https://activemq.apache.org/apollo/documentation/stomp-manual.html#Topic_Durable_Subscriptions

关于python - 如何接收 STOMP 中丢失的消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35122782/

相关文章:

apache - activemq 未启动

node.js - 让 Node.js WAMP.IO 服务器订阅客户端发布以测量延迟

javascript - Addy Osmanis pub/sub,难以理解代码

python - 如何执行算术对列表列表进行排序

python - 有没有一种简单的方法来编写随时间比较网页的脚本?

尝试将参数传递给unittest子类时出现Python TypeError

spring - 让一个简单的 Spring JMS 客户端确认工作

python - 从类中获取/循环变量树

java - 在队列中保留和锁定消息的策略,其中一个消费者隐藏多个用户

php - 如何从 codeigniter 中的 rabbitmq php 消费者回调调用模型?