Class: Warren::Subscriber::QueueBroadcastConsumer

Inherits:
Base
  • Object
show all
Defined in:
app/warren/subscribers/queue_broadcast_consumer.rb

Overview

Warren powered queue_broadcast_consumer consumers Handles the rebroadcast of short format message into their long form equivalent Takes messages from the psd.queue_broadcast queue

Example Message

Plate,1

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#delivery_infoBunny::DeliveryInfo (readonly)

Returns mostly used internally for nack/acking messages rubybunny.info/articles/queues.html#accessing_message_properties_metadata.

Returns:


# File 'app/warren/subscribers/queue_broadcast_consumer.rb', line 11

#payloadString (readonly)

Returns the payload of the message.

Returns:

  • (String)

    the payload of the message


# File 'app/warren/subscribers/queue_broadcast_consumer.rb', line 11

#propertiesBunny::MessageProperties (readonly)

Returns:


# File 'app/warren/subscribers/queue_broadcast_consumer.rb', line 11

Instance Method Details

#extract_jsonObject


39
40
41
42
43
44
45
46
47
# File 'app/warren/subscribers/queue_broadcast_consumer.rb', line 39

def extract_json
  json = JSON.parse(payload)
  raise InvalidPayload, "Payload #{payload} is not an array" unless json.is_a?(Array)
  raise InvalidPayload, "Payload #{payload} is not the correct length" unless json.length == 2

  json
rescue JSON::ParserError => e
  raise InvalidPayload, "Payload #{payload} is not JSON: #{e.message}"
end

#jsonObject


35
36
37
# File 'app/warren/subscribers/queue_broadcast_consumer.rb', line 35

def json
  @json ||= extract_json
end

#processObject

Handles message processing. Messages are acknowledged automatically on return from the method assuming they haven't been handled already. In the event of an uncaught exception, the message will be dead-lettered.


27
28
29
30
31
32
33
# File 'app/warren/subscribers/queue_broadcast_consumer.rb', line 27

def process
  klass = json.first.constantize
  klass.find(json.last).broadcast
rescue ActiveRecord::RecordNotFound
  # This may indicate that the record has been deleted
  debug "#{payload} not found."
end