小编aka*_*kou的帖子

PHP如何在RabbitMQ中取消消费者?

我有下一个代码:

<?php

// callback function for recive the message and canceling consumer
function consumer(\AMQPEnvelope $envelope, \AMQPQueue $queue)
{
    $queue->ack($envelope->getDeliveryTag());
    $queue->cancel($envelope->getCorrelationId());
    echo "Message was recived and consumer will be canceled by consumer tag: {$envelope->getCorrelationId()}\n";
}

// generating uniqie exchange and queue
$correlationId = uniqid(str_replace('.', '', (string)microtime(TRUE)) . '_');
$queueName = "databus_response_{$correlationId}";
$consumerTag = "consumer_tag_{$correlationId}";

// establesh connection
$connection = new \AMQPConnection(array('host'=>'127.0.0.1', 'user'=>'guest', 'password'=>'guest'));
$connection->connect();
$channel = new \AMQPChannel($connection);

// declare exchange
$exchange = new \AMQPExchange($channel);
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->setType(AMQP_EX_TYPE_TOPIC);
$exchange->setName($queueName);
$exchange->declareExchange();

// declare …
Run Code Online (Sandbox Code Playgroud)

php message-queue command-line-interface rabbitmq

3
推荐指数
1
解决办法
3392
查看次数