Class: RMB::StompSubscriber
- Inherits:
-
Subscriber
- Object
- Subscriber
- RMB::StompSubscriber
- Defined in:
- lib/stomp_subscriber.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#host ⇒ Object
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#connect ⇒ Object
connect
Opens a connection with the message broker, and then subscribes on the url. -
#properties=(hash) ⇒ Object
properties=(hash) Accepts a hash object containing all of the configuration properties required.
-
#receive ⇒ Object
receive
Executes a receive on the connection, thus blocking the daemon until a message arrives.
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def connection @connection end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def logger @logger end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def port @port end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
7 8 9 |
# File 'lib/stomp_subscriber.rb', line 7 def user @user end |
Instance Method Details
#connect ⇒ Object
connect
Opens a connection with the message broker, and then subscribes on the url
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/stomp_subscriber.rb', line 11 def connect super begin @connection = Stomp::Connection.open(user, password, host, port) @connection.subscribe url, { :ack => 'auto' } rescue Exception logger.fatal "#{__FILE__}:#{__LINE__} Exception #{$!}" raise end logger.info "Waiting for messages in #{url}." end |
#properties=(hash) ⇒ Object
properties=(hash) Accepts a hash object containing all of the configuration properties required. These properties are copied into instance variables.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stomp_subscriber.rb', line 25 def properties=(hash) subscriber = hash[:subscriber] @url = subscriber[:url] || "/queue/something" @host = subscriber[:host] || "" @port = subscriber[:port] || 61613 @user = subscriber[:user] || "" @password = subscriber[:password] || "" @connection = nil super end |
#receive ⇒ Object
receive
Executes a receive on the connection, thus blocking the daemon until a message arrives. Then answers the message.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/stomp_subscriber.rb', line 38 def receive super begin = @connection.receive rescue Exception logger.fatal "#{__FILE__}:#{__LINE__} Exception #{$!}" raise end logger.info "Received message: #{message.inspect}" end |