php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61512 Testing Dead-Lettered Message
Submitted: 2012-03-26 14:07 UTC Modified: 2021-06-10 15:34 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: admin at sulehosting dot co dot za Assigned: cmb (profile)
Status: Closed Package: amqp (PECL)
PHP Version: Irrelevant OS: ubuntu 10.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: admin at sulehosting dot co dot za
New email:
PHP Version: OS:

 

 [2012-03-26 14:07 UTC] admin at sulehosting dot co dot za
Description:
------------
PHP 5.3.3-1ubuntu9.10 with Suhosin-Patch (cli) (built: Feb 11 2012 06:40:29)
amqp - 1.0.1

Description:

My queue gets deleted when I call AMQPQueue::nack


<?php

/**
 * Consume
 */
//create connection
$resConnection = new AMQPConnection(array(
          'host' => 'localhost' ,
          'vhost' => '/the_programmer' ,
          'port' => '5672' ,
          'login' => 'admin' ,
          'password' => 'admin'
        )) ;


try {
  //connect to server
  $resConnection->connect() ;

  //create an amqp channel
  $resChannel = new AMQPChannel($resConnection) ;

  /**
   * Create an exchange - please refer to the rabbitmq documentation about 
exchanges
   * 
   * - it will create a new exchange with the given parameters if such an 
   *   exchange does not exist or it will bind itself to an existing it one if 
one
   *   already exist.
   */
  $resExchange = new AMQPExchange($resChannel) ;
  $resExchange->setName('async_exchange') ;
  $resExchange->setType(AMQP_EX_TYPE_DIRECT) ;
  $resExchange->setFlags(AMQP_AUTODELETE) ;
  $resExchange->declare() ;

  /**
   * Create a queue - please refer to the rabbitmq documentation about queues
   * 
   * - it will create a new queue with the given parameters if such a 
   *   queue does not exist or it will bind itself to an existing it one if one
   *   already exist.
   */
  $resQueue = new AMQPQueue($resChannel) ;
  $resQueue->setName('my_queue') ;
  $resQueue->setFlags(AMQP_DURABLE) ;
  $resQueue->setArguments(array('x-dead-letter-routing-key' => 'async.dead' ,
    //'x-message-ttl' => 6000,
    'x-dead-letter-exchange' => 'async_dead')) ;
  $resQueue->declare() ;
  $resQueue->bind('async_exchange' , 'async.key') ;

  $objMessage = $resQueue->get() ;

  if ($objMessage) {
    //process message
    print $objMessage->getBody() ;

    $resQueue->nack($objMessage->getDeliveryTag()) ;
  }
}
catch (AMQPException $e) {
  echo $e->getMessage() ;
}
catch (AMQPConnectionException $e) {
  echo $e->getMessage() ;
}
catch (AMQPExchangeException $e) {
  echo $e->getMessage() ;
}
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-10 15:34 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-06-10 15:34 UTC] cmb@php.net
The amqp bug tracker is now on Github[1].  If this is still an
issue, please report there.

[1] <https://github.com/php-amqp/php-amqp/issues>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 06:01:38 2025 UTC