【问题标题】:How can I handle a duplicate durable Stomp subscriber?如何处理重复的持久 Stomp 订阅者?
【发布时间】:2014-07-05 04:02:14
【问题描述】:

我有多个 Ruby 进程启动并尝试使用 Stomp 通过持久订阅者连接到主题。

第一个进程成功,并读取消息(耶)。

后续进程失败,并反复尝试重新连接。

我的进程如何发现持久订阅者已经连接,然后退出尝试连接?

可能的虚码sn-p:

begin
  stomp_client.subscribe()
rescue ClientAlreadySubscribedException
  puts "No problem, let's keep doing our other code"
end

环境:

  • Ruby 1.9.3
  • stompgem 1.3.2

代码:

require 'stomp'

# Connect with durable subscription
hash = {
  hosts: [
    { host: "localhost", port: 61613, ssl: false }
  ],
  connect_headers: {
    :"client-id" => "durableRubyTest"
  }
}
stomp_client = Stomp::Client.new( hash )

stomp_client.subscribe "/topic/durable.test.dev",
    {"activemq.subscriptionName" => "devtest" } do |msg|
  puts "Message! "
  puts msg.inspect
end
puts "Connected to stomp, waiting for messages..."
stomp_client.join

【问题讨论】:

  • 您可以使用Stomp::Connection 而不是Stomp::Client,它会为您提供错误消息。为避免“反复尝试重新连接”问题,您可以在 config_hash 中使用max_reconnect_attempts 选项

标签: activemq stomp durable-subscription


【解决方案1】:

重复的持久订阅者应该收到一个指示问题的 ERROR 帧。如果您在订阅后收到 ERROR 帧,您可以在那里处理问题。

【讨论】:

  • 跺脚,是的。但是,可能需要对 Stomp Gem 进行更改才能处理此问题。在这个问题的背景下,这并不是我想要的答案。
  • StackOverflow 不是错误跟踪器。如果您需要更改 STOMP gem,请使用他们的错误报告工具。
  • 使用功能请求 - github.com/stompgem/stomp/issues/101 来跟踪。
猜你喜欢
  • 2016-11-09
  • 1970-01-01
  • 2017-01-24
  • 2015-09-01
  • 1970-01-01
  • 2017-11-08
  • 1970-01-01
  • 2012-05-30
  • 2017-02-20
相关资源
最近更新 更多