Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[messenger] Rabbitmq message does not get moved to the failure Q after all the retries have failed #20304

Open
billgsm opened this issue Oct 7, 2024 · 0 comments

Comments

@billgsm
Copy link

billgsm commented Oct 7, 2024

Hi there,
I'm using symfony/messenger and I'd like to have the following behavior for a specific Q:

if the message fails and all the retries fail too ===> the message should be move to a specific queue created specifically for failed messages for further investigations.

The documentation saving-retrying-failed-messages seems to be explaining exactly what I need.

However, the behavior I'm getting is the following:

  1. if a message fails, the retries are executed
  2. if all the retries fail too
    2.a. my failed message is "sent to the failure transport" based on the logs
    2.b. the retries are executed again
    2.c if those retries fail too, my message gets discarded
composer.json
{
    "name": "symfony/skeleton",
    "type": "project",
    "license": "MIT",
    "description": "A minimal Symfony project recommended to create bare bones applications",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": "^8.1",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "runtime/frankenphp-symfony": "^0.2.0",
        "symfony/amqp-messenger": "^6.0",
        "symfony/console": "^6.0",
        "symfony/dotenv": "^6.0",
        "symfony/flex": "^2",
        "symfony/framework-bundle": "^6.0",
        "symfony/messenger": "^6.0",
        "symfony/runtime": "^6.0",
        "symfony/yaml": "^6.0"
    },
    "config": {
        "allow-plugins": {
            "php-http/discovery": true,
            "symfony/flex": true,
            "symfony/runtime": true
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*",
        "symfony/polyfill-php73": "*",
        "symfony/polyfill-php74": "*",
        "symfony/polyfill-php80": "*",
        "symfony/polyfill-php81": "*",
        "symfony/polyfill-php82": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "^6.0",
            "docker": true
        }
    },
    "require-dev": {
        "symfony/maker-bundle": "^1.61",
        "symfony/var-dumper": "^6.0"
    }
}
config/packages/messenger.yaml
framework:
    messenger:
        failure_transport: failed

        transports:
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                retry_strategy:
                    max_retries: 3
                    delay: 1000
                    multiplier: 2
                    max_delay: 0

            failed:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'

        routing:
            'App\Message\DoATestMessage': async
App\MessageHandler\DoATestMessageHandler
<?php

namespace App\MessageHandler;

use App\Message\DoATestMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
final class DoATestMessageHandler
{
    public function __invoke(DoATestMessage $message): void
    {
        throw new \Exception('This is a test exception');
    }
}

Here is the command to run my worker ==> bin/console messenger:consume async -vvv

And here is the output

Worker output
> bin/console messenger:consume async -vvv


 [OK] Consuming messages from transports "async".


 // The worker will automatically exit once it has received a stop signal via the messenger:stop-workers command.

 // Quit the worker with CONTROL-C.

[info] Received message App\Message\DoATestMessage
[warning] Error thrown while handling message App\Message\DoATestMessage. Sending for retry #1 using 1000 ms delay. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"
[info] Received message App\Message\DoATestMessage
[warning] Error thrown while handling message App\Message\DoATestMessage. Sending for retry #2 using 2000 ms delay. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"
[info] Received message App\Message\DoATestMessage
[warning] Error thrown while handling message App\Message\DoATestMessage. Sending for retry #3 using 4000 ms delay. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"
[info] Received message App\Message\DoATestMessage


[critical] Error thrown while handling message App\Message\DoATestMessage. Removing from transport after 3 retries. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"

[info] Rejected message App\Message\DoATestMessage will be sent to the failure transport Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpTransport.
[info] Received message App\Message\DoATestMessage


[warning] Error thrown while handling message App\Message\DoATestMessage. Sending for retry #1 using 1000 ms delay. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"
[info] Received message App\Message\DoATestMessage
[warning] Error thrown while handling message App\Message\DoATestMessage. Sending for retry #2 using 2000 ms delay. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"
[info] Received message App\Message\DoATestMessage
[warning] Error thrown while handling message App\Message\DoATestMessage. Sending for retry #3 using 4000 ms delay. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"
[info] Received message App\Message\DoATestMessage
[critical] Error thrown while handling message App\Message\DoATestMessage. Removing from transport after 3 retries. Error: "Handling "App\Message\DoATestMessage" failed: This is a test exception"

What am I missing ? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants