Skip to content

Commit

Permalink
Remove dead messages + docs update (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
melroy89 authored Sep 19, 2024
1 parent 6091824 commit 701388b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 15 deletions.
8 changes: 8 additions & 0 deletions docs/02-admin/04-running-mbin/messenger.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ We created a simple command to clean-up all the failed messages from the databas
```bash
./bin/console mbin:messenger:failed:remove_all
```

And to remove the dead messages from the database at once:

```bash
./bin/console mbin:messenger:dead:remove_all
```

However, most messages stored in the database are most likely failed messages. So it is advised to regularly run the `./bin/console mbin:messenger:failed:remove_all` command to clean-up the database.
28 changes: 13 additions & 15 deletions docs/02-admin/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ RabbitMQ will now have new queues being added for the different delays (so a mes
The global overview from RabbitMQ shows the ready messages for all queues combined. Messages in the retry queues count as ready messages the whole time they are in there,
so for a correct ready count you have to go to the queue specific overview.

| Overview | Queue Tab | "Message" Queue Overview |
| --------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------- |
| Overview | Queue Tab | "Message" Queue Overview |
| ------------------------------------------------------- | ------------------------------------------------- | ----------------------------------------------------------------- |
| ![Queued messages](../images/rabbit_queue_overview.png) | ![Queue overview](../images/rabbit_queue_tab.png) | ![Message Queue Overview](../images/rabbit_messages_overview.png) |

## RabbitMQ Prometheus exporter
Expand Down Expand Up @@ -134,23 +134,19 @@ scrape_configs:
## How to clean-up all failed messages?
If you wish to **delete all messages** (`dead` and `failed`) at once, execute the following PostgreSQL query (assuming you're connected to the correct PostgreSQL database):
If you want to delete all failed messages (`failed` queue) you can execute the following command:

```sql
DELETE FROM messenger_messages;
```bash
./bin/console mbin:messenger:failed:remove_all
```

If you want to delete only the messages that are no longer being worked (`dead`) on you can execute this query:
And if you want to delete the dead messages (`dead` queue) you can execute the following command:

```sql
DELETE FROM messenger_messages WHERE queue_name = 'dead';
```bash
./bin/console mbin:messenger:dead:remove_all
```

To free up the disk space used by the now deleted messages, execute the following query:

```sql
VACUUM messenger_messages;
```
_Hint:_ Most messages that are stored in the database are most likely in the `failed` queue, thus running the first command (`mbin:messenger:failed:remove_all`) will most likely delete all messages in the `messenger_messages` table. Regularly running this command will keep your database clean.

## Where can I find my logging?

Expand Down Expand Up @@ -208,12 +204,14 @@ first, so any updates to the keys requires a `DEL instance_private_key instance_
First thing you should do to debug the issue is looking at the "Queues and Streams" tab to find out what queues have the high publishing rate.
If the queue/s in question are `inbox` and `resolve` it is most likely a circulating `ChainActivityMessage`.
To verify that assumption:

1. stop all messengers
- if you're on bare metal, as root: `supervisorctl stop messenger:*`
- if you're on docker, inside the `docker` folder : `docker compose down messenger*`
- if you're on bare metal, as root: `supervisorctl stop messenger:*`
- if you're on docker, inside the `docker` folder : `docker compose down messenger*`
2. look again at the publishing rate. If it has gone down, then it definitely is a circulating message

To fix the problem:

1. start the messengers if they are not already started
2. go to the `resolve` queue
3. open the "Get Message" panel
Expand Down
52 changes: 52 additions & 0 deletions src/Command/RemoveDeadMessagesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'mbin:messenger:dead:remove_all',
description: 'This command removes all dead messages from the dead queue (database).',
)]
class RemoveDeadMessagesCommand extends Command
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
) {
parent::__construct();
}

protected function configure(): void
{
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$this->removeDeadMessages();

return Command::SUCCESS;
}

/**
* Remove all dead messages from database.
*/
private function removeDeadMessages()
{
$this->entityManager->getConnection()->executeQuery(
'DELETE FROM messenger_messages WHERE queue_name = ?',
['dead']
);

// Followed by vacuuming the messenger_messages table.
$this->entityManager->getConnection()->executeQuery('VACUUM messenger_messages');
}
}
3 changes: 3 additions & 0 deletions src/Command/RemoveFailedMessagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ private function removeFailedMessages()
'DELETE FROM messenger_messages WHERE queue_name = ?',
['failed']
);

// Followed by vacuuming the messenger_messages table.
$this->entityManager->getConnection()->executeQuery('VACUUM messenger_messages');
}
}

0 comments on commit 701388b

Please sign in to comment.