class RubyRabbitmqJanus::Rabbit::Publisher::Base
@author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
This publisher send and read an message in queues
Attributes
message[RW]
reply[R]
Public Class Methods
new(exchange)
click to toggle source
Intialize a publisher for sending and reading a message
@param [String] exchange Determine type exchange used for all
transaction between gem and rabbitmq
Calls superclass method
RubyRabbitmqJanus::Rabbit::BaseEvent::new
# File lib/rrj/rabbit/publisher/base.rb, line 16 def initialize(exchange) super() @exchange = exchange.default_exchange @message = nil end
Public Instance Methods
publish(request)
click to toggle source
Publish an message in queue
@param [String] request JSON request sending to rabbitmq queue
@raise [Errors::RabbitPublishMessage] If request is false the
execption is calling
# File lib/rrj/rabbit/publisher/base.rb, line 28 def publish(request) @message = request @exchange.publish(@message.to_json, request.options.merge!(reply_to: reply.name)) end
Private Instance Methods
m_correlation()
click to toggle source
# File lib/rrj/rabbit/publisher/base.rb, line 44 def m_correlation @message.correlation end
p_correlation(propertie)
click to toggle source
# File lib/rrj/rabbit/publisher/base.rb, line 48 def p_correlation(propertie) propertie.correlation_id end
subscribe_to_queue()
click to toggle source
# File lib/rrj/rabbit/publisher/base.rb, line 36 def subscribe_to_queue reply.subscribe do |_delivery_info, propertie, payload| test_correlation(m_correlation, p_correlation(propertie)) do synchronize(payload) end end end
synchronize(payload)
click to toggle source
# File lib/rrj/rabbit/publisher/base.rb, line 59 def synchronize(payload) lock.synchronize do responses.push(JSON.parse(payload)) end semaphore.signal end
test_correlation(m_cor, p_cor) { || ... }
click to toggle source
# File lib/rrj/rabbit/publisher/base.rb, line 52 def test_correlation(m_cor, p_cor) raise Errors::Rabbit::Publisher::Base::TestCorrelation, m_cor, p_cor \ unless m_cor.eql?(p_cor) yield end