Example #1
0
 /**
  * Mark a message as explicitly not acknowledged.
  * RabbitMQ supports the nack method that provides all the functionality of
  * basic.reject whilst also allowing for bulk processing of messages.
  * To reject messages in bulk, clients set the multiple flag of the basic.nack method
  * to true. The broker will then reject all unacknowledged, delivered messages up to
  * and including the message specified in the delivery_tag field of the
  * basic.nack method. In this respect, basic.nack complements the bulk acknowledgement
  * semantics of basic.ack.
  *
  * @param integer $flags AMQP_MULTIPLE to nack all previous unacked messages as well.
  *                       AMQP_REQUEUE to requeue the message(s),
  *
  * @return bool
  */
 public function nack($flags = AMQP_REQUEUE)
 {
     if (!$this->consumed) {
         return $this->consumed = $this->queue->nack($this->getDeliveryTag(), $flags);
     }
     return $this->consumed;
 }
Example #2
0
 /**
  * @param string $deliveryTag
  * @param int    $flags
  *
  * @return bool
  */
 public function nack($deliveryTag, $flags = Client::NOPARAM)
 {
     try {
         return $this->rawQueue->nack($deliveryTag, $flags);
     } catch (\Exception $e) {
         ClientHelper::throwRightException($e);
     }
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function nack(int $deliveryTag, int $flags = Constants::AMQP_NOPARAM)
 {
     $this->queue->nack($deliveryTag, $flags);
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function nack($deliveryTag, $flags = AMQP_NOPARAM)
 {
     $this->delegate->nack($deliveryTag, self::convertToDelegateFlags($flags));
 }
 /**
  * {@inheritDoc}
  */
 public function nack(Message $message, $requeue = false)
 {
     $this->queue->nack($message->getId(), $requeue ? AMQP_REQUEUE : null);
 }
Example #6
0
 /**
  * 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;
     }
 }