Class: Brown::Agent::AMQPMessage

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • delivery_info (Bunny::DeliveryInfo, Bunny::GetResponse)
  • properties (Bunny::MessageProperties)
  • payload (String)


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

#payloadString (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.

Returns:

  • (String)


16
17
18
# File 'lib/brown/agent/amqp_message.rb', line 16

def payload
  @payload
end

Instance Method Details

#ackObject

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