DarkMantis
DarkMantis

Reputation: 1516

RabbitMQ PHP AMQP Library - Get message headers

I have got a simple queueing system which, obviously, takes messages and publishes them.

However, due to a new development in the system, we now need to check for the x-death headers from the exchange, however, I can't seem any documentation on how to retrieve that through the PHP AMQP Library.

Anyone have any ideas on how to achieve this?

Upvotes: 5

Views: 6232

Answers (2)

dickwan
dickwan

Reputation: 337

Just to add some more to @pinepain's answer. You can do the following too:

/** @var AMQPMessage $message */
$props = $message->get_properties();
/** @var AMQPTable $applicationHeaders */
$applicationHeaders = $props['application_headers'];
$xdeath = $applicationHeaders->getNativeData()['x-death'];

Upvotes: 9

pinepain
pinepain

Reputation: 12859

Check for it in application_headers property.

Here is a brief modified code from example:

/**
 * @param \PhpAmqpLib\Message\AMQPMessage $msg
 */
function process_message($msg)
{
    $headers = $msg->get('application_headers');
    $props = ['x-death'];

    // OR

    $props = $msg->get_properties();
    $props['application_headers']['x-death'];

    $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
}


$ch->basic_consume($queue, $consumer_tag, false, false, false, false, 'process_message');

Upvotes: 10

Related Questions