Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement