Skip to content

Instantly share code, notes, and snippets.

@muhammetfaik
Created October 1, 2017 12:07
Show Gist options
  • Select an option

  • Save muhammetfaik/c9ef65030179ee2f686bac8c8d798f75 to your computer and use it in GitHub Desktop.

Select an option

Save muhammetfaik/c9ef65030179ee2f686bac8c8d798f75 to your computer and use it in GitHub Desktop.

Revisions

  1. muhammetfaik created this gist Oct 1, 2017.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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