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: -
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:
Status: Open Package: amqp (PECL)
PHP Version: Irrelevant OS: ubuntu 10.4
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 15:01:28 2019 UTC