我有多个 Ruby 进程启动并尝试使用 Stomp 通过持久订阅者连接到主题。
第一个进程成功,并读取消息(耶)。
后续进程失败,并反复尝试重新连接。
我的进程如何发现持久订阅者已经连接,并退出尝试连接?
可能的虚构代码片段:
begin
stomp_client.subscribe()
rescue ClientAlreadySubscribedException
puts "No problem, let's keep doing our other code"
end
环境:
- 红宝石 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