Class: Threatinator::Plugins::Output::Amqp

Inherits:
Output
  • Object
show all
Defined in:
lib/threatinator/plugins/output/amqp.rb,
lib/threatinator/plugins/output/amqp/config.rb

Defined Under Namespace

Classes: Config

Instance Method Summary collapse

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

#finishObject



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