Class: Threatinator::Plugins::Output::Amqp
- Defined in:
- lib/threatinator/plugins/output/amqp.rb,
lib/threatinator/plugins/output/amqp/config.rb
Defined Under Namespace
Classes: Config
Instance Method Summary collapse
- #finish ⇒ Object
- #handle_event(event) ⇒ Object
-
#initialize(config) ⇒ Amqp
constructor
A new instance of Amqp.
Constructor Details
#initialize(config) ⇒ Amqp
Returns a new instance of Amqp.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/threatinator/plugins/output/amqp.rb', line 16 def initialize(config) bunny_config = { recover_from_connection_close: true, network_recovery_interval: 5.0 } @bunny = Bunny.new(config.url, bunny_config) @bunny.start @channel = @bunny.create_channel @exchange = @channel.topic("threats") end |
Instance Method Details
#finish ⇒ Object
35 36 37 38 |
# File 'lib/threatinator/plugins/output/amqp.rb', line 35 def finish @exchange = nil @bunny.close end |
#handle_event(event) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/threatinator/plugins/output/amqp.rb', line 27 def handle_event(event) # Routing keys are dynamic event_types #@routing_key = config.routing_key || 'threatinator.' + event.type.to_s @routing_key = 'threatinator.' + event.type.to_s @exchange.publish(MultiJson.dump(event.to_serializable_hash), routing_key: @routing_key) end |