Answer the question
In order to leave comments, you need to log in
How to implement multiple RabbitMQ consumers?
Let's say I have a worker (consumer):
$connection = new AMQPConnection($config['rabbitmq']);
$connection->connect();
$channel = new AMQPChannel($connection);
$exchange = new AMQPExchange($channel);
$exchange->setName('exchange_name');
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->declareExchange();
$queue = new AMQPQueue($channel);
$queue->setName('queue_name');
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
$queue->bind($exchange->getName(), $queue->getName());
while (true) {
$envelope = $queue->get();
if ($envelope) {
var_dump($envelope->getBody());
$queue->nack($envelope->getDeliveryTag());
}
}
$connection->disconnect();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question