如何接收 STOMP 中丢失的消息?
How can I receive the missing messages in STOMP?
我有一个 python 脚本,它必须 运行 24/7 在 linux 服务器上,并通过 STOMP 从另一台服务器接收 ActiveMQ 推送通知。脚本可能因任何原因而失败,并且会停机一段时间,显然最多 30 分钟或平均只有几分钟。
我需要在脚本再次启动后以某种方式接收丢失的 messages-notifications(如果它之前已关闭)。据我所知,我的理解是有限的,一旦我的脚本启动,服务器就会发送它们。这是我认为是真的
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
方法收到的 headers:
{
'priority': '4',
'persistent': 'true',
'message-id': 'fdsfds',
'expires': '432432432',
'destination': '/topic/fdsfds',
'timestamp': '42343243',
'subscription': '0',
'type': 'aaaaa'
}
做 "persistent",也许 "subscription",这意味着如果我的 client-consumer 离线,那么一旦它再次上线,它将发送它错过的所有消息离线了吗?
对于 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
不,实际上持久化不会在服务器离线时发送丢失的消息; activeMQ 中的持久消息意味着当您重新启动 activeMQ 时,queue 中的消息不会丢失,它们将保留以备将来接收。
如果你想在 activemq 中使用 python 和 stomp 发送持久消息,你必须将以下 STOMP header 添加到所有 SEND 请求中:persistent:true.
而且你必须这样写:
conn.send('queue name', 'message', headers={'persistent':'true'})
我有一个 python 脚本,它必须 运行 24/7 在 linux 服务器上,并通过 STOMP 从另一台服务器接收 ActiveMQ 推送通知。脚本可能因任何原因而失败,并且会停机一段时间,显然最多 30 分钟或平均只有几分钟。
我需要在脚本再次启动后以某种方式接收丢失的 messages-notifications(如果它之前已关闭)。据我所知,我的理解是有限的,一旦我的脚本启动,服务器就会发送它们。这是我认为是真的
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
方法收到的 headers:
{
'priority': '4',
'persistent': 'true',
'message-id': 'fdsfds',
'expires': '432432432',
'destination': '/topic/fdsfds',
'timestamp': '42343243',
'subscription': '0',
'type': 'aaaaa'
}
做 "persistent",也许 "subscription",这意味着如果我的 client-consumer 离线,那么一旦它再次上线,它将发送它错过的所有消息离线了吗?
对于 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
不,实际上持久化不会在服务器离线时发送丢失的消息; activeMQ 中的持久消息意味着当您重新启动 activeMQ 时,queue 中的消息不会丢失,它们将保留以备将来接收。
如果你想在 activemq 中使用 python 和 stomp 发送持久消息,你必须将以下 STOMP header 添加到所有 SEND 请求中:persistent:true.
而且你必须这样写:
conn.send('queue name', 'message', headers={'persistent':'true'})