Class: RMB::StompSubscriber

Inherits:
Subscriber show all
Defined in:
lib/stomp_subscriber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def connection
  @connection
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def logger
  @logger
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def password
  @password
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def port
  @port
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def url
  @url
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/stomp_subscriber.rb', line 7

def user
  @user
end

Instance Method Details

#connectObject

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

#receiveObject

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
    message = @connection.receive
  rescue Exception
    logger.fatal "#{__FILE__}:#{__LINE__} Exception #{$!}"
    raise
  end
  logger.info "Received message: #{message.inspect}"
  message
end