Sha256: 6e1ff2e55fe4b4a11aeb69c48b054da8af4d2aa34124f4022b7eee207d84fc3e
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require 'bunny' require 'json' module EasyBunnyRPC class Worker def initialize(options={}) @options = options end private def subscribe queue.subscribe(block: true) do |delivery_info, properties, payload| @delivery_info, @properties, @payload = delivery_info, properties, payload yield JSON.parse(payload).first end end def publish(success, payload) obj = { 'success' => success, 'payload' => payload }.to_json exchange.publish(obj, routing_key: @properties.reply_to, correlation_id: @properties.correlation_id) end def publish_success(payload) publish true, payload end def publish_failure(payload) publish false, payload end def connection return @connection if defined?(@connection) @connection = Bunny.new(@options[:bunny]) @connection.start @connection end def channel return @channel if defined?(@channel) @channel = connection.create_channel @channel.prefetch(1) @channel end def queue @queue ||= channel.queue(@options[:queue]) end def exchange @exchange ||= channel.default_exchange end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
easy_bunny_rpc-0.1.0.alpha | lib/easy_bunny_rpc/worker.rb |