main
 1namespace :rabbitmq do
 2  desc "setup rabbitmq routing"
 3  task setup: :environment do
 4    require "bunny"
 5    connection = Bunny.new
 6    connection.start
 7    channel = connection.create_channel
 8
 9    # single malwer topic exchange
10    # routing keys:
11    # * commands.command_type.(agent_id/fingerprint)
12      # * commands can be issued for specific agents
13      # * commands can be issued globally. (e.g. poke a dispostion)
14    # * events.event_type.agent_id
15
16    channel.topic("malwer").tap do |exchange|
17      # event intake bindings
18      queue = channel.queue("worker.events", durable: true)
19      queue.bind(exchange, routing_key: "events.#")
20
21      # poke bindings
22      queue = channel.queue("worker.poke", durable: true)
23      queue.bind(exchange, routing_key: "commands.poke.#")
24
25      # cloud queries bindings
26      queue = channel.queue("worker.queries", durable: true)
27      queue.bind(exchange, routing_key: 'events.scanned.#')
28    end
29
30    connection.close
31  end
32end