Class: Brown::Agent::AMQPMessage
- Inherits:
-
Object
- Object
- Brown::Agent::AMQPMessage
- Defined in:
- lib/brown/agent/amqp_message.rb
Overview
A message received from an AMQP broker.
This is what you will get passed to you when you use amqp_listener to point a shell-like at an exchange. It allows you to get the message itself, all of the message's metadata, and also act on the message by acknowledging it so the broker can consider it "delivered".
Instance Attribute Summary collapse
-
#payload ⇒ String
readonly
The raw body of the message.
Instance Method Summary collapse
-
#ack ⇒ Object
Acknowledge that this message has been processed.
-
#initialize(delivery_info, properties, payload) ⇒ AMQPMessage
constructor
Create a new message.
Constructor Details
#initialize(delivery_info, properties, payload) ⇒ AMQPMessage
Create a new message. The arguments are a straight copy of what you
get yielded from Bunny::Queue#subscribe
, or what gets returned from
Bunny::Queue#pop
.
28 29 30 |
# File 'lib/brown/agent/amqp_message.rb', line 28 def initialize(delivery_info, properties, payload) @delivery_info, @properties, @payload = delivery_info, properties, payload end |
Instance Attribute Details
#payload ⇒ String (readonly)
The raw body of the message. No translation is done on what was sent, so any serialisation that might have been applied to the message will have to be undone manually.
16 17 18 |
# File 'lib/brown/agent/amqp_message.rb', line 16 def payload @payload end |
Instance Method Details
#ack ⇒ Object
Acknowledge that this message has been processed.
The broker needs to know that each message has been processed, before it will remove the message from the queue entirely. It also won't send more than a certain number of messages at once, so until you ack a message, you won't get another one.
39 40 41 |
# File 'lib/brown/agent/amqp_message.rb', line 39 def ack @delivery_info.channel.ack(@delivery_info.delivery_tag) end |