|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62786 AMQP_MANDATORY not working
Submitted: 2012-08-09 15:05 UTC Modified: 2021-06-10 15:34 UTC
Avg. Score:4.3 ± 0.9
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: vvu at whalesharkmedia dot com Assigned: cmb (profile)
Status: Closed Package: amqp (PECL)
PHP Version: 5.3.15 OS: OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: vvu at whalesharkmedia dot com
New email:
PHP Version: OS:


 [2012-08-09 15:05 UTC] vvu at whalesharkmedia dot com
When we use AMQPExchange::publish with a AMQP_MANDATORY flag, it always returns 
true regardless if the exchange or queue exists.

Test script:
self::$channel = new AMQPChannel(self::$connection);
self::$exchange = new AMQPExchange(self::$channel);
self::$exchange->publish($message, self::$routingkey, AMQP_MANDATORY, $options);

(We are using a exchange name that does not exist)

Expected result:
We always get true regardless of what is put into the exchangename field. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-09 10:30 UTC] webmaster at wp dot pl
As I know this is correct. Publish return true/false as a result of transporting message to a broker and nothing more. AMQP_MANDATORY flag tells the broker you want this 
message to be correctly routed to a queue if not send me an error info.
this library doesn't have this implemented yet but based on a protocol you should get that information as a separate message directed from a broker to you on a same 
channel. This are two different things - transporting that to a broker and what broker does with a message.

You can do a trick by doing this (this is a trick not a right way of doing this. this will only show you how it works):
- declare a temporary queue (it doesn't need a name etc, just don't do it durable)
- publish a message with that flag
- right after that consume on that "virtual" queue.

If  your message was not correctly routed the broker on the same channel will reply with an error and you'll get that with that consume.

in order to stop consume use use pcntl_alarm and pcntl_signal with a timeout.


$queue = new AMQPQueue( $channel );
$queue->setFlags( (AMQP_AUTOACK | AMQP_AUTODELETE) );
$reply_to_routing_key = $queue->getName();

$queue->bind( $exchange->getName(), $reply_to_routing_key );

if( $exchange->publish( $payload, $routing_key, AMQP_MANDATORY, array( "reply_to" => $reply_to_routing_key ) ) )
   declare(ticks = 1);
   pcntl_signal(SIGALRM, function ($signal) {} , true);
   pcntl_alarm( 1 );

   $queue->consume( function ($m,$q) { echo ' handler..'; } );



Please note that this is not a right way of handling this feedbacks from a broker. We all will have to wait for a right implementation that is still missing. Maybe they 
will decide to do that different way e.g. by hooking callback functions to a publish etc...
 [2021-06-10 15:34 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-10 15:34 UTC]
The amqp bug tracker is now on Github[1].  If this is still an
issue, please report there.

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 21:01:24 2021 UTC