cmonkey
cmonkey

Reputation: 4296

How can I handle a duplicate durable Stomp subscriber?

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

Environment:

Code:

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

Upvotes: 2

Views: 1053

Answers (1)

Tim Bish
Tim Bish

Reputation: 18376

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.

Upvotes: 1

Related Questions