php.net |  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
Votes:3
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vvu at whalesharkmedia dot com
New email:
PHP Version: OS:

 

 [2012-08-09 15:05 UTC] vvu at whalesharkmedia dot com
Description:
------------
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->setName(self::$exchangename);
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. 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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.

Briefly:
<?php

$queue = new AMQPQueue( $channel );
$queue->setFlags( (AMQP_AUTOACK | AMQP_AUTODELETE) );
$queue->declare();
$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 '..feedback handler..'; } );
   $queue->delete();

}

?>

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] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-10 15:34 UTC] cmb@php.net
The amqp bug tracker is now on Github[1].  If this is still an
issue, please report there.

[1] <https://github.com/php-amqp/php-amqp/issues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC