phpheaderamqpphp-amqplib

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?


Solution

  • 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');