Class: SongkickQueue::Producer
- Inherits:
-
Object
- Object
- SongkickQueue::Producer
- Defined in:
- lib/songkick_queue/producer.rb
Instance Method Summary collapse
-
#initialize ⇒ Producer
constructor
A new instance of Producer.
-
#publish(queue_name, payload, options = {}) ⇒ Object
Serializes the given message and publishes it to the default RabbitMQ exchange.
Constructor Details
Instance Method Details
#publish(queue_name, payload, options = {}) ⇒ Object
Serializes the given message and publishes it to the default RabbitMQ exchange
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/songkick_queue/producer.rb', line 14 def publish(queue_name, payload, = {}) = .fetch(:message_id) { SecureRandom.hex(6) } produced_at = .fetch(:produced_at) { Time.now.utc.iso8601 } = { message_id: , produced_at: produced_at, payload: payload } = JSON.generate() routing_key = [config.queue_namespace, queue_name].compact.join('.') client .default_exchange .publish(, routing_key: routing_key) logger.info "Published message #{} to '#{routing_key}' at #{produced_at}" end |