If your queue has already been created, you do not need to create it (using the declare method) and contact Exchange again. IMHO, you should not do this, because :) these actions require administrative privileges; b) enough for this only once; c) you may not have administrative rights to the production, and your code will be violated. I believe that itβs better to create and link all the required queues to the management console or any other tool that you like, and then receive messages this way.
// consider using connection more than once. that only for illustration purposes. $connection = new AMQPConnection([ put your credentials here ]); $connection->connect(); if(!$connection->isConnected()) { throw new Exception('Connection failed.'); } $chnlObj = new AMQPChannel($connection); $queObj = new AMQPQueue($chnlObj); $queObj->setName('yourQueueName'); echo $queObj->get(AMQP_AUTOACK)->getBody(); // consider using connection more than once. that only for illustration purposes. $connection->disconnect();
source share