Skip to content

Instantly share code, notes, and snippets.

@olegsobchuk
Created August 19, 2016 13:35
Show Gist options
  • Save olegsobchuk/88bd6ebacd5ad7ddb7e2b3d0487fcc21 to your computer and use it in GitHub Desktop.
Save olegsobchuk/88bd6ebacd5ad7ddb7e2b3d0487fcc21 to your computer and use it in GitHub Desktop.
class Mq::RabbitService
attr_reader :queue_name
def initialize(queue_name)
@queue_name = queue_name
end
def connection
@connection ||= Bunny.new(host: '192.168.1.67', port: 5672, user: 'oleg', password: '111111').start
end
def channel
@channel ||= connection.create_channel
end
def queue
channel.queue(queue_name, auto_delete: true)
end
def publish(message)
queue.status
exchange = channel.default_exchange
exchange.publish(message, routing_key: queue_name)
end
def subscribe
queue.subscribe do |delivery_info, properties, message|
# do with message what you want
p message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment