prolic / HumusAmqp

PHP 7.4 AMQP library
https://humusamqp.readthedocs.io/
MIT License
76 stars 17 forks source link

Type hint on Envelope::getHeader breaks dead letter exchange usage #106

Closed lost-anjarrett closed 1 year ago

lost-anjarrett commented 1 year ago

Hello,

I'm upgrading from 1.4.0 to 2.1.0 and I have an error when a message is redelivered to the queue from a dead letter exchange

Return value of Humus\Amqp\Driver\PhpAmqpLib\Envelope::getHeader() must be of the type string or null, array returned
.#0 /var/www/mister-auto.com/git/maws/src/Maws/Core/Base/Bus/AMQPConsumer.php(101): Humus\Amqp\Driver\PhpAmqpLib\Envelope->getHeader()

As we can read on the official doc:

The dead-lettering process adds an array to the header of each dead-lettered message named x-death.

I also checked the message and this is the content of the x-death header:

headers:    
    x-death:    
        count:  1
        exchange:   error_dlx
        queue:  error_dlx
        reason: expired
        routing-keys:   test_queue
        time:   1686218983

        count:  1
        reason: rejected
        queue:  test_queue
        time:   1686218980
        exchange:   
        routing-keys:   test_queue

It seems to me that a header can be string or array (maybe more) and we should therefore remove the type hint in this case.
I can absolutely make the PR. But maybe am I missing something ?

PS: I run with rabbitmq in version 3.6.16 but I also tested it with 3.10.7 with same results.

basz commented 1 year ago

once #110 is ready this could be address.

I think it should be mixed as a header values may be any AMQP Data type according to https://livebook.manning.com/book/rabbitmq-in-depth/chapter-3/108

basz commented 1 year ago

112 will fix this.

Please be aware that both drivers return a different payload.

lost-anjarrett commented 1 year ago

Hey @basz thanks ! I didnt't test with the AMQP extension indeed. Maybe I should give it a try.

BTW the workaround for this issue is to call getHeaders() and access the wanted key. Pretty easy but I mention it anyway, we never know :D !