1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
--TEST--
AMQPQueue::nack
--SKIPIF--
<?php
if (!extension_loaded("amqp")) print "skip AMQP extension is not loaded";
elseif (!getenv("PHP_AMQP_HOST")) print "skip PHP_AMQP_HOST environment variable is not set";
?>
--FILE--
<?php
ini_set('amqp.auto_ack', false);
$cnn = new AMQPConnection();
$cnn->setHost(getenv('PHP_AMQP_HOST'));
$cnn->connect();
$ch = new AMQPChannel($cnn);
// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->setName('testnack' . bin2hex(random_bytes(32)));
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declareExchange();
$exchangeName = $ex->getName();
// Create a new queue
$q = new AMQPQueue($ch);
$q->setName('testnack' . bin2hex(random_bytes(32)));
$q->declareQueue();
$q->bind($exchangeName, '#');
// Bind it on the exchange to routing.key
// Publish a message to the exchange with a routing key
$ex->publish('message', 'foo');
$env = $q->get(AMQP_NOPARAM);
echo $env->getBody() . PHP_EOL;
echo $env->isRedelivery() ? 'true' : 'false';
echo PHP_EOL;
// send the message back to the queue
$q->nack($env->getDeliveryTag(), AMQP_REQUEUE);
// read again
$env2 = $q->get(AMQP_NOPARAM);
if (false !== $env2) {
$q->ack($env2->getDeliveryTag(), null);
echo $env2->getBody() . PHP_EOL;
echo $env2->isRedelivery() ? 'true' : 'false';
echo PHP_EOL;
} else {
echo "could not read message" . PHP_EOL;
}
$ex->delete();
$q->delete();
--EXPECT--
message
false
message
true
|