Skip to content

Instantly share code, notes, and snippets.

@muhammetfaik
Created October 1, 2017 12:08
Show Gist options
  • Save muhammetfaik/393f3ceef664334edb7a37fe59e04bf5 to your computer and use it in GitHub Desktop.
Save muhammetfaik/393f3ceef664334edb7a37fe59e04bf5 to your computer and use it in GitHub Desktop.
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