Skip to content

Commit

Permalink
Added subscriber check method for connection class and added Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeeptarlekar committed Oct 15, 2020
1 parent 7b34122 commit 6879721
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in stomp.gemspec
gemspec
2 changes: 1 addition & 1 deletion lib/stomp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def closed?()
# Stomp::Client.new().subscriber?('/queue/queueName') => true
# Stomp::Client.new().subscriber?('/queue/Consumer.subscriber1.VirtualTopic.topicName') => true
#
def subscriber?(destination, headers = {})
def subscribed?(destination, headers = {})
headers = headers.symbolize_keys
headers = headers.merge(:id => build_subscription_id(destination, headers))
!@listeners[headers[:id]].nil?
Expand Down
7 changes: 7 additions & 0 deletions lib/stomp/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ def subscribe(destination, headers = {}, subId = nil)
transmit(Stomp::CMD_SUBSCRIBE, headers)
end

def subscribed?(destination, subId = nil)
return false unless @reliable

subId = destination if subId.nil?
@subscriptions[subId].present?
end

# Unsubscribe from a destination. A subscription name is required.
# For Stomp 1.1+ a session unique subscription ID is also required.
def unsubscribe(destination, headers = {}, subId = nil)
Expand Down
4 changes: 2 additions & 2 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ def original_headers
it_behaves_like 'argument-safe method'
end

describe '#subscriber?' do
subject { @client.subscriber?('/topic/topicName') }
describe '#subscribed?' do
subject { @client.subscribed?('/topic/topicName') }

context 'When subscription is present' do
before {
Expand Down

0 comments on commit 6879721

Please sign in to comment.