Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 845
DarkMantis Avatar asked Jul 24 '14 14:07

DarkMantis


2 Answers

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');
like image 143
pinepain Avatar answered Oct 23 '22 17:10

pinepain


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'];
like image 9
dickwan Avatar answered Oct 23 '22 19:10

dickwan