I have multiple Ruby processes that start up and try to connect to a topic via a durable subscriber using Stomp.
The first process succeeds, and reads messages (yay).
Subsequent processes fail, and repeatedly try to reconnect.
How can my processes discover that the durable subscriber is already connected, and quit trying to connect?
Possible imaginary code snippet:
begin
stomp_client.subscribe()
rescue ClientAlreadySubscribedException
puts "No problem, let's keep doing our other code"
end
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
Duplicate durable subscribers should receive an ERROR frame that indicates the problem. If you receive an ERROR frame after the subscribe you can handle the problem there.