class Freddy::Producers::SendAndForgetProducer
Constants
- CONTENT_TYPE
Public Class Methods
new(channel, logger)
click to toggle source
# 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
Public Instance Methods
produce(destination, payload, properties)
click to toggle source
# 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