2

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:

  • Ruby 1.9.3
  • stompgem 1.3.2

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
cmonkey
  • 4,256
  • 1
  • 26
  • 46
  • Instead of `Stomp::Client` you can use `Stomp::Connection` which gives you error messages. To avoid "repeatedly try to reconnect" issue, You can use `max_reconnect_attempts` option in config_hash – Chimed Palden Mar 04 '20 at 16:19

1 Answers1

1

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.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • Stomp-wise, yes. However, a change to the Stomp Gem may be required in order to handle this. In the context of this question, it's not quite the answer I was going for. – cmonkey May 23 '14 at 22:26
  • StackOverflow is not a bug tracker. If you need changes to STOMP gem then use their bug reporting tool. – Tim Bish May 24 '14 at 11:12
  • Using feature request - https://github.com/stompgem/stomp/issues/101 to track this. – cmonkey May 28 '14 at 18:47