Created
October 1, 2017 12:07
-
-
Save muhammetfaik/cc4af0e28e70d038f50320b8e04b8129 to your computer and use it in GitHub Desktop.
ornek.rb
This file contains 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
class Publisher | |
# In order to publish message we need a exchange name. | |
# Note that RabbitMQ does not care about the payload - | |
# we will be using JSON-encoded strings | |
def self.publish(exchange, message = {}) | |
# grab the fanout exchange | |
x = channel.fanout("dbcountermain#{exchange}") | |
# and simply publish message | |
x.publish(message.to_json) | |
end | |
def self.channel | |
@channel ||= connection.create_channel | |
end | |
# We are using default settings here | |
# The `Bunny.new(...)` is a place to | |
# put any specific RabbitMQ settings | |
# like host or port | |
def self.connection | |
@connection ||= Bunny.new.tap do |c| | |
c.start | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment