Class: Freddy::Producers::SendAndWaitResponseProducer
- Inherits:
-
Object
- Object
- Freddy::Producers::SendAndWaitResponseProducer
- Defined in:
- lib/freddy/producers/send_and_wait_response_producer.rb
Constant Summary collapse
- CONTENT_TYPE =
'application/json'.freeze
Instance Method Summary collapse
-
#initialize(channel, logger) ⇒ SendAndWaitResponseProducer
constructor
A new instance of SendAndWaitResponseProducer.
- #produce(destination, payload, properties) ⇒ Object
Constructor Details
#initialize(channel, logger) ⇒ SendAndWaitResponseProducer
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/freddy/producers/send_and_wait_response_producer.rb', line 6 def initialize(channel, logger) @logger = logger @channel = channel @request_manager = RequestManager.new(@logger) @exchange = @channel.default_exchange @topic_exchange = @channel.topic Freddy::FREDDY_TOPIC_EXCHANGE_NAME @channel.on_no_route do |correlation_id| @request_manager.no_route(correlation_id) end @response_queue = @channel.queue("", exclusive: true) @request_manager.start @response_consumer = Consumers::ResponseConsumer.new(@logger) @response_consumer.consume(@response_queue, &method(:handle_response)) end |
Instance Method Details
#produce(destination, payload, properties) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/freddy/producers/send_and_wait_response_producer.rb', line 26 def produce(destination, payload, properties) timeout_in_seconds = properties.fetch(:timeout_in_seconds) container = SyncResponseContainer.new async_request destination, payload, properties, &container container.wait_for_response(timeout_in_seconds + 0.1) end |