本文整理汇总了PHP中AMQPQueue::ack方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue::ack方法的具体用法?PHP AMQPQueue::ack怎么用?PHP AMQPQueue::ack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPQueue
的用法示例。
在下文中一共展示了AMQPQueue::ack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ack
/**
* This method allows the acknowledgement of a message that is retrieved without
* the AMQP_AUTOACK flag through AMQPQueue::get() or AMQPQueue::consume()
*
* @return bool
*/
public function ack()
{
if (!$this->consumed) {
return $this->consumed = $this->queue->ack($this->getDeliveryTag());
}
return $this->consumed;
}
示例2: process
/**
* @param \AMQPEnvelope $envelope
* @param \AMQPQueue $queue
* @param PushPipe $pushPipe
* @param string $errorQueue
* @param ReceiveCancellationToken $cancellationToken
* @param EndpointControlToken $endpointControlToken
*
* @return bool
*/
public function process(\AMQPEnvelope $envelope, \AMQPQueue $queue, PushPipe $pushPipe, $errorQueue, ReceiveCancellationToken $cancellationToken, EndpointControlToken $endpointControlToken)
{
try {
$messageId = '';
$headers = [];
$pushMessage = false;
try {
$messageId = $this->messageConverter->retrieveMessageId($envelope);
$headers = $this->messageConverter->retrieveHeaders($envelope);
$pushMessage = true;
} catch (\Exception $e) {
$this->routingTopology->sendToQueue($this->brokerModel, $errorQueue, $envelope->getBody(), ['headers' => $envelope->getHeaders()]);
}
if ($pushMessage) {
$pushPipe->push(new PushContext($messageId, $headers, $envelope->getBody() ?: '', $cancellationToken, $endpointControlToken));
}
if ($cancellationToken->isCancellationRequested()) {
$queue->reject($envelope->getDeliveryTag(), AMQP_REQUEUE);
} else {
$queue->ack($envelope->getDeliveryTag());
}
} catch (CriticalErrorException $e) {
// just ... die
throw $e;
} catch (\Exception $e) {
$queue->reject($envelope->getDeliveryTag(), AMQP_REQUEUE);
}
if ($endpointControlToken->isShutdownRequested()) {
return false;
}
return true;
}
示例3: ack
/**
* @param string $deliveryTag
* @param int $flags
*
* @return bool
*/
public function ack($deliveryTag, $flags = Client::NOPARAM)
{
try {
return $this->rawQueue->ack($deliveryTag, $flags);
} catch (\Exception $e) {
ClientHelper::throwRightException($e);
}
}
示例4: read
/**
* @param \AMQPQueue $queue
* @return bool|string
*/
public static function read(\AMQPQueue $queue)
{
usleep(10000);
$envelope = $queue->get(\AMQP_NOPARAM);
if ($envelope) {
$message = $envelope->getBody();
$queue->ack($envelope->getDeliveryTag());
return $message;
}
return false;
}
示例5: publish
/**
* @param \AMQPEnvelope $envelope
* @param \AMQPQueue $queue
* @param string $m
*/
public function publish($envelope, $queue, $m)
{
if ($m instanceof AmqpResp) {
$m = Json::encode($m->getData());
} elseif (is_object($m) || is_array($m)) {
$m = Json::encode($m);
}
$chanel = $this->getChanel();
// Точка доступа
// Точка обмена
$exchange = new \AMQPExchange($chanel);
$exchange->setFlags(AMQP_AUTODELETE | AMQP_DURABLE);
$attributes = array('correlation_id' => $envelope->getCorrelationId());
$routingKey = $envelope->getReplyTo();
if ($exchange->publish($m, $routingKey, AMQP_NOPARAM, $attributes)) {
$queue->ack($envelope->getDeliveryTag());
}
}
示例6: callback
function callback(AMQPEnvelope $message, AMQPQueue $q)
{
//say that message received
$q->ack($message->getDeliveryTag());
}
示例7: AMQPConnection
$rabbit = new AMQPConnection(array('host' => '127.0.0.1', 'port' => '5672', 'login' => 'guest', 'password' => 'guest'));
$rabbit->connect();
$channel = new AMQPChannel($rabbit);
$queue = new AMQPExchange($channel);
$queue->setName('amq.direct');
/**
* Добавляем очередь откуда будем брать страницы
*/
$q = new AMQPQueue($channel);
$q->setName('images_to_scan');
$q->declare();
$q->bind('amq.direct', 'analyze_image');
/**
* Обрабатываем пока в очереди не закончатся сообщения
*/
while (true) {
$image = $q->get();
if ($image) {
$url = $image->getBody();
echo "Checking: {$url}\n";
$analyzer = new ImageAnalyzer($url);
/**
* Если картинка еще не была проанализирована, обрабатываем и добавляем в индекс
*/
$analyzer->analyze();
$q->ack($image->getDeliveryTag());
} else {
sleep(1);
}
}
$rabbit->disconnect();
示例8: readAll
/**
* Read all messages
*
* @access public
*
* @param string $chat name chat room
* @param string $route name route
* @param string $nameReader name queue
*
* @return array
* @throws \AMQPConnectionException
* @throws \AMQPQueueException
* @throws \AMQPChannelException
*/
public function readAll($chat, $route, $nameReader)
{
$queue = new \AMQPQueue($this->channel);
$queue->setName($nameReader);
/** @noinspection PhpUndefinedMethodInspection */
$queue->declare();
$queue->bind($chat, $route);
$result = [];
while ($envelop = $queue->get()) {
$queue->ack($envelop->getDeliveryTag());
$result[] = $envelop;
}
return $result;
}
示例9: AMQPConnection
$exchange_name = 'example.fanout';
$queue_name = 'example.fanout.default';
$route_key = 'ignored-for-fanout';
// establish connection
$connection = new AMQPConnection();
if (!$connection->connect()) {
echo "Failed to establish connection", PHP_EOL;
die;
}
// create channel
$channel = new AMQPChannel($connection);
// create exchange
$exchange = new AMQPExchange($channel);
$exchange->setType(AMQP_EX_TYPE_FANOUT);
$exchange->setName($exchange_name);
$exchange->declareExchange();
// if exchange already exists it will not be redeclared
// here we definitely need queue to be declared before we'll use it
$queue = new AMQPQueue($channel);
$queue->setName($queue_name);
$queue->declareQueue();
// same for queue, if already declared will not be redeclared
$queue->bind($exchange_name, $route_key);
// NOTE: if exchange doesn't exists you can't bind queue to it, which is
// although quite obvious
$queue->consume(function (AMQPEnvelope $envelope, AMQPQueue $queue) {
$message = $envelope->getBody();
echo "Received '{$message}' at " . date(DATE_RFC822), PHP_EOL;
$queue->ack($envelope->getDeliveryTag());
});
示例10: ack
/**
* @inheritdoc
*/
public function ack(int $deliveryTag, int $flags = Constants::AMQP_NOPARAM)
{
$this->queue->ack($deliveryTag, $flags);
}
示例11: ack
/**
* @inheritdoc
*/
public function ack($deliveryTag, $flags = null)
{
return $this->delegate->ack($deliveryTag, self::convertToDelegateFlags($flags));
}
示例12: ack
/**
* {@inheritDoc}
*/
public function ack(Message $message)
{
$this->queue->ack($message->getId());
}
示例13: basic_ack
/**
* @param string $deliveryTag
* @return mixed
*/
public function basic_ack($deliveryTag)
{
$this->queue->ack($deliveryTag);
}
示例14: consume
/**
* Consumes next message from queue and passes its payload to callback when it arrives
*
* @param string $queueName Queue name to consume message from
* @param callable $callback Callback to pass payload to
*
* @throws \AMQPException
*/
public function consume($queueName, callable $callback)
{
try {
$queue = new \AMQPQueue($this->getChannel());
$queue->setName($queueName);
$queue->consume(function (\AMQPEnvelope $envelope, \AMQPQueue $queue) use($callback) {
switch ($callback($envelope->getBody())) {
case self::MESSAGE_ACK:
$queue->ack($envelope->getDeliveryTag());
break;
case self::MESSAGE_NACK:
$queue->nack($envelope->getDeliveryTag());
break;
case self::MESSAGE_REQUEUE:
$queue->nack($envelope->getDeliveryTag(), AMQP_REQUEUE);
break;
}
});
} catch (\AMQPException $e) {
$this->channel = null;
throw $e;
}
}
示例15: removeMessage
/**
* Remove message from MQ
* @param object $queue
* @param array $inputArray
* @return void
* @access public
*/
public function removeMessage(\AMQPQueue $queue, $inputArray = array())
{
$queue->bind($this->exchangeOptions['name'], $this->queueOptions['routing_key']);
foreach ($inputArray as $deliveryTag) {
if (isset($deliveryTag)) {
$queue->ack($deliveryTag);
}
}
}