Skip to content

Commit 5269d59

Browse files
committed
Merge pull request #267 from tiborb/rabbitmq-delete-queue
added rabbitmq:delete command, used for deleting a consumer's queue
2 parents 915f68f + 13ea154 commit 5269d59

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

Command/DeleteCommand.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace OldSound\RabbitMqBundle\Command;
4+
5+
use Symfony\Component\Console\Input\InputArgument;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
/**
11+
* Command to delete a queue
12+
*/
13+
class DeleteCommand extends ConsumerCommand
14+
{
15+
protected function configure()
16+
{
17+
$this->addArgument('name', InputArgument::REQUIRED, 'Consumer Name')
18+
->setDescription('Delete a consumer\'s queue')
19+
->addOption('no-confirmation', null, InputOption::VALUE_NONE, 'Whether it must be confirmed before deleting');
20+
21+
$this->setName('rabbitmq:delete');
22+
}
23+
24+
/**
25+
* @param InputInterface $input
26+
* @param OutputInterface $output
27+
*
28+
* @return void
29+
*/
30+
protected function execute(InputInterface $input, OutputInterface $output)
31+
{
32+
$noConfirmation = (bool) $input->getOption('no-confirmation');
33+
34+
if (!$noConfirmation && $input->isInteractive()) {
35+
$confirmation = $this->getHelper('dialog')->askConfirmation($output, sprintf('<question>Are you sure you wish to delete "%s" consumer\'s queue?(y/n)</question>', $input->getArgument('name')), false);
36+
if (!$confirmation) {
37+
$output->writeln('<error>Deletion cancelled!</error>');
38+
39+
return 1;
40+
}
41+
}
42+
43+
$this->consumer = $this->getContainer()
44+
->get(sprintf($this->getConsumerService(), $input->getArgument('name')));
45+
$this->consumer->delete();
46+
}
47+
}

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ If you want to remove all the messages awaiting in a queue, you can execute this
271271
$ ./app/console rabbitmq:purge --no-confirmation upload_picture
272272
```
273273

274+
For deleting the consumer's queue, use this command:
275+
276+
```bash
277+
$ ./app/console rabbitmq:delete --no-confirmation upload_picture
278+
```
279+
274280
#### Idle timeout ####
275281

276282
If you need to set a timeout when there are no messages from your queue during a period of time, you can set the `idle_timeout` in seconds:

RabbitMq/Consumer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public function purge()
5656
{
5757
$this->getChannel()->queue_purge($this->queueOptions['name'], true);
5858
}
59+
60+
/**
61+
* Delete the queue
62+
*/
63+
public function delete()
64+
{
65+
$this->getChannel()->queue_delete($this->queueOptions['name'], true);
66+
}
5967

6068
public function processMessage(AMQPMessage $msg)
6169
{

0 commit comments

Comments
 (0)