Skip to content

Instantly share code, notes, and snippets.

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