Class: Freddy::Producers::SendAndForgetProducer
- Inherits:
-
Object
- Object
- Freddy::Producers::SendAndForgetProducer
- Defined in:
- lib/freddy/producers/send_and_forget_producer.rb
Constant Summary collapse
- CONTENT_TYPE =
'application/json'.freeze
Instance Method Summary collapse
-
#initialize(channel, logger) ⇒ SendAndForgetProducer
constructor
A new instance of SendAndForgetProducer.
- #produce(destination, payload, properties) ⇒ Object
Constructor Details
#initialize(channel, logger) ⇒ SendAndForgetProducer
Returns a new instance of SendAndForgetProducer.
6 7 8 9 10 |
# File 'lib/freddy/producers/send_and_forget_producer.rb', line 6 def initialize(channel, logger) @logger = logger @exchange = channel.default_exchange @topic_exchange = channel.topic Freddy::FREDDY_TOPIC_EXCHANGE_NAME end |
Instance Method Details
#produce(destination, payload, properties) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/freddy/producers/send_and_forget_producer.rb', line 12 def produce(destination, payload, properties) span = OpenTracing.start_span("freddy:notify:#{destination}", child_of: Freddy.trace, tags: { 'message_bus.destination': destination, 'component': 'freddy', 'span.kind': 'producer' # Message Bus } ) span.log event: 'Sending message', payload: payload properties = properties.merge( routing_key: destination, content_type: CONTENT_TYPE ) OpenTracing.global_tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, TraceCarrier.new(properties)) json_payload = Payload.dump(payload) # Connection adapters handle thread safety for #publish themselves. No # need to lock these. @topic_exchange.publish json_payload, properties.dup @exchange.publish json_payload, properties.dup ensure # We don't know how many listeners there are and we do not know when # this message gets processed. Instead we close the span immediately. # Listeners should use FollowsFrom to add trace information. # https://github.com/opentracing/specification/blob/master/specification.md span.finish end |