5

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?

DarkMantis
  • 1,510
  • 5
  • 19
  • 40

2 Answers2

10

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');
pinepain
  • 12,453
  • 3
  • 60
  • 65
  • I did try that, but the `application_headers` is empty :/ Do you know of any reason why that would be? Am I not doing something which populates the `application_headers`? – DarkMantis Jul 25 '14 at 08:01
  • 1
    `application_headers` are populated by the library internals. If it empty (empty array) it's ok and mean that no headers are set for the message. – pinepain Jul 25 '14 at 08:03
  • Right, in which case it seems that I need to make some changes to my queues & exchanges. Thanks a lot @zaq178miami ! – DarkMantis Jul 25 '14 at 08:12
9

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'];
dickwan
  • 337
  • 4
  • 13