[rabbitmq-discuss] RabbitMQ + PHP and RPC

Simon MacMullen simon at rabbitmq.com
Thu Jun 21 11:29:11 BST 2012


Oh, of course. I'm being slow today.

You just don't need to declare the queue on the RPC server, the client 
will already have declared it. And the server can publish to it by 
publishing to the default exchange (named "") with a routing key of the 
queue's name. Does this make sense?

Cheers, Simon

On 21/06/12 11:19, Dennis wrote:
> Hi, Simon
>
> I'm just using approach described at
> http://www.rabbitmq.com/tutorials/tutorial-six-python.html which says
> exclusive=True
>
> AMQP_AUTODELETE constant from here:
> http://www.php.net/manual/en/amqp.constants.php seems not working
> properly also. Queue remains empty after all messages are consumed and
> after both client and server disconnected from server. It's probably
> again the issue of PECL php library.
> Will dig this further and write the results
>
>
> On Thu, Jun 21, 2012 at 2:10 PM, Simon MacMullen <simon at rabbitmq.com
> <mailto:simon at rabbitmq.com>> wrote:
>
>     Hi Dennis.
>
>     The whole point of an exclusive queue is that it is accessible
>     solely by the connection that declares it. You don't want to declare
>     a queue as exclusive if it is going to be used by more than one
>     connection.
>
>     So I'm not sure why you are declaring it exclusive? If you are
>     trying to make sure that it goes away when the client connection
>     does, you probably want to make it autodelete - then it will be
>     deleted when the client connection stops consuming from it.
>
>     Cheers, Simon
>
>     On 21/06/12 10:48, Denis wrote:
>
>         Sorry for me writing here: I can't figure out how to use mailing
>         list
>         for replies =/
>
>
>         My Client.php declares callback queue php-object as following:
>
>         |$callbackQueue=  new  \AMQPQueue($channel);
>
>         $callbackQueue->setFlags(AMQP___EXCLUSIVE);  // set EXCLUSIVE flag
>         $callbackQueue->declare();|
>
>         After that I pass it's name at an envelope to server like this
>         ($callbackQueue->getName at 'reply_to')
>
>         |$exchange->publish(
>                 json_encode(array('process me!')),
>         'temp_action',
>                 AMQP_MANDATORY,
>                 array(
>         'reply_to'  =>  $callbackQueue->getName(),  // pass callback
>         queue name
>         'correlation_id'  =>  $correlationId
>                 )
>         );|
>
>
>         And my Server.php creates a new Queue php-object (in an anonymous
>         function that handles consuming) as following:
>
>         |        $callbackQueue=  new  \AMQPQueue($channel);
>
>                 $callbackQueue->setName($__envelope->getReplyTo());
>                 $callbackQueue->setFlags(AMQP___EXCLUSIVE);  // set
>         EXCLUSIVE flag|
>
>         Right after that moment I'm trying to bind newly created
>         $callbackQueue
>         object to an exchange - and this causes blocking issue.
>
>
>         I'm not sure which exact options are different (exclusive looks
>         for me
>         to be the only flag I set in both cases).
>         Setting name in Server.php is necessary and name is taken from
>         envelope's 'reply_to' setting.
>
>         As far as I can see no extra declaration of callback queue is
>         happening
>         on a Server.php side. (Although tempQueue Server consumes
>         messages from
>         is extra declared, but this is made for server to be able to
>         listen that
>         queue even when before any client exists)
>
>         On Thursday, June 21, 2012 12:33:42 PM UTC+4, Alvaro Videla wrote:
>
>             While not using the same library here you have the official
>             tutorials ported to PHP
>
>         https://github.com/rabbitmq/__rabbitmq-tutorials/tree/__master/php
>         <https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/php>
>         <https://github.com/rabbitmq/__rabbitmq-tutorials/tree/__master/php
>         <https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/php>>
>
>             The problem in your code is that you declare queues with
>         different
>             options.
>
>             So as one reply say, if you declare queue A as durable, then
>         every
>             other declaration of that queue must be durable. The same
>         for the
>             exclusive flag.
>
>             Also you don't need to redeclare a queue to publish messages
>         to it.
>             As an RPC server you assume that the address sent in the
>         'reply_to'
>             property is already present. I think is the responsibility
>         of the
>             RpcClient to make sure the queue where it is waiting for replies
>             exists already.
>
>             Regards,
>
>             Alvaro
>
>             And you can indeed do RPC over RabbitMQ by using different
>         connections.
>
>             On Wed, Jun 20, 2012 at 8:03 PM, Denis wrote:
>
>                 Hello guys.
>
>                 I'm trying to build RPC using PHP, here is my description of
>                 problem:
>         http://stackoverflow.com/____questions/11104004/rabbitmq-____rpc-exclusive-queues-locking-____php
>         <http://stackoverflow.com/__questions/11104004/rabbitmq-__rpc-exclusive-queues-locking-__php>
>
>         <http://stackoverflow.com/__questions/11104004/rabbitmq-__rpc-exclusive-queues-locking-__php
>         <http://stackoverflow.com/questions/11104004/rabbitmq-rpc-exclusive-queues-locking-php>>
>
>                 The main issue I suspect is that Client.php and
>         Server.php try
>                 to connect to RabbitMQ server using different
>         connections, which
>                 leads to inability of using EXCLUSIVE queue (that is
>         declared in
>                 CLient.php) from Server.php
>
>                 Can u give me a way I can dig to? I'm out of ideas ...
>
>                 _________________________________________________
>                 rabbitmq-discuss mailing list
>         rabbitmq-discuss at lists.__rabbitmq.com
>         <mailto:rabbitmq-discuss at lists.rabbitmq.com>
>         <mailto:rabbitmq-discuss at __lists.rabbitmq.com
>         <mailto:rabbitmq-discuss at lists.rabbitmq.com>>
>         https://lists.rabbitmq.com/__cgi-bin/mailman/listinfo/__rabbitmq-discuss
>         <https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss>
>         <https://lists.rabbitmq.com/__cgi-bin/mailman/listinfo/__rabbitmq-discuss
>         <https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss>>
>
>
>
>
>         _________________________________________________
>         rabbitmq-discuss mailing list
>         rabbitmq-discuss at lists.__rabbitmq.com
>         <mailto:rabbitmq-discuss at lists.rabbitmq.com>
>         https://lists.rabbitmq.com/__cgi-bin/mailman/listinfo/__rabbitmq-discuss
>         <https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss>
>
>
>
>     --
>     Simon MacMullen
>     RabbitMQ, VMware
>
>


-- 
Simon MacMullen
RabbitMQ, VMware


More information about the rabbitmq-discuss mailing list