Skip to content

Instantly share code, notes, and snippets.

@skalibog
Created August 8, 2019 09:28
Show Gist options
  • Save skalibog/7be98e750bf17e9d66116b237d20d27c to your computer and use it in GitHub Desktop.
Save skalibog/7be98e750bf17e9d66116b237d20d27c to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class Rabbit
attr_accessor :status, :payload
def initialize(status, payload)
self.status = status
self.payload = payload
end
def call
connection = Bunny.new(
hosts: ENV.fetch("RABBIT_HOST", "localhost"),
port: ENV.fetch("RABBIT_PORT", 5672),
username: ENV.fetch("RABBIT_USERNAME", "guest"),
password: ENV.fetch("RABBIT_PASSWORD", "guest"),
automatically_recover: false)
connection.start
channel = connection.create_channel
exchange = channel.topic("test", durable: true)
# severity = "entity.#{payload["name"]}"
queue = channel.queue("#{payload["name"]}")
message = { :"#{entity_name}" => payload }.to_json
queue.bind(exchange, routing_key: "test.#{payload["name"]}")
exchange.publish(message, routing_key: "test.#{payload["name"]}")
puts " [x] Sent #{queue.name}:#{message}"
connection.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment