Created
August 8, 2019 09:28
-
-
Save skalibog/7be98e750bf17e9d66116b237d20d27c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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