Class: Warren::Subscriber::QueueBroadcastConsumer
- Inherits:
-
Base
- Object
- Base
- Warren::Subscriber::QueueBroadcastConsumer
- Defined in:
- app/models/warren/subscriber/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
-
#delivery_info ⇒ Bunny::DeliveryInfo
readonly
Mostly used internally for nack/acking messages rubybunny.info/articles/queues.html#accessing_message_properties_metadata.
-
#payload ⇒ String
readonly
The payload of the message.
-
#properties ⇒ Bunny::MessageProperties
readonly
Additional message properties.
Instance Method Summary collapse
- #extract_json ⇒ Object
- #json ⇒ Object
-
#process ⇒ Object
Handles message processing.
Instance Attribute Details
#delivery_info ⇒ Bunny::DeliveryInfo (readonly)
Returns mostly used internally for nack/acking messages rubybunny.info/articles/queues.html#accessing_message_properties_metadata.
|
# File 'app/models/warren/subscriber/queue_broadcast_consumer.rb', line 11
|
#payload ⇒ String (readonly)
Returns the payload of the message.
|
# File 'app/models/warren/subscriber/queue_broadcast_consumer.rb', line 11
|
#properties ⇒ Bunny::MessageProperties (readonly)
Returns additional message properties. rubybunny.info/articles/queues.html#accessing_message_properties_metadata.
|
# File 'app/models/warren/subscriber/queue_broadcast_consumer.rb', line 11
|
Instance Method Details
#extract_json ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'app/models/warren/subscriber/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.}" end |
#json ⇒ Object
35 36 37 |
# File 'app/models/warren/subscriber/queue_broadcast_consumer.rb', line 35 def json @json ||= extract_json end |
#process ⇒ Object
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/models/warren/subscriber/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 |