Class: Snoopit::Notifiers::Stomp
Instance Attribute Summary
#configuration, #klass, #name
Instance Method Summary
collapse
Constructor Details
#initialize(config = nil) ⇒ Stomp
The name ‘stomp’ is used by the Snooper to identify type of notifier to create The empty constructor is used to initialize the class when loaded dynamically After loaded dynamically the method set_config is called by the base class to set the configuration
13
14
15
16
17
18
19
20
|
# File 'lib/snoopit/notifiers/stomp.rb', line 13
def initialize(config=nil)
super config, 'stomp'
@host = config['host'] || 'localhost'
@port = config['port'] || 61613
@login = config['login']
@passcode = config['passcode']
@headers = config['headers']
end
|
Instance Method Details
#get_connect_params ⇒ Object
33
34
35
36
37
38
|
# File 'lib/snoopit/notifiers/stomp.rb', line 33
def get_connect_params
params = { host: @host, port: @port }
params[:login] = @login unless @login.nil?
params[:passcode] = @passcode unless @passcode.nil?
params
end
|
#get_connection ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/snoopit/notifiers/stomp.rb', line 22
def get_connection
params = { hosts: [ get_connect_params ] }
params
::Stomp::Connection.new params
rescue => e
Snoopit.logger.warn 'Stomp failed to connect: ' + params.to_json
Snoopit.logger.warn 'Stomp failed to connect: ' + e.message
Snoopit.logger.warn 'Stomp failed to connect: ' + e.backtrace.join('\n')
nil
end
|
#notify(found, notify_params) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/snoopit/notifiers/stomp.rb', line 44
def notify(found, notify_params)
conn = get_connection
send_message(conn, found, notify_params) unless conn.nil?
rescue => e
Snoopit.logger.warn e.message
Snoopit.logger.warn e.backtrace.join('\n')
ensure
conn.disconnect unless conn.nil?
end
|
#send_message(conn, found, notify_params) ⇒ Object
54
55
56
|
# File 'lib/snoopit/notifiers/stomp.rb', line 54
def send_message(conn, found, notify_params)
conn.publish notify_params['queue'], found.to_json, notify_params['headers']
end
|
40
41
42
|
# File 'lib/snoopit/notifiers/stomp.rb', line 40
def (params)
params[:connect_headers] = @headers unless @headers.nil?
end
|