Skip to content

[Messenger] DLX configuration issue #30218

Closed
@bentcoder

Description

@bentcoder

Symfony version(s) affected: 4.2.2

Hi,

Since there is no single entry in the documentation around AMQP Dead Letter Exchange, I am asking to find out if this is a bug or not. If it is an expected behaviour then please answer the question below. Much appreciated.

I am trying to automatically configure DLX exchange image_crop_dlx_ex and a queue image_crop_dlx_qu to go with it. However, they don't seem to be created in RabbitMQ unlike others (image_crop_ex and image_crop_qu). See the configuration below please.

All I want to do is:

  • Have image_crop_dlx_ex and image_crop_dlx_qu in RabbitMQ.
  • Reject a message in the handler so that it goes DLX.

Configuration

framework:
    messenger:
        transports:
            amqp_image_crop_dlx: # This section seems to be ignored
                dsn: 'amqp://rabbitmq:rabbitmq@127.0.0.1:5672/%2f/'
                options:
                    exchange:
                        name: image_crop_dlx_ex
                        type: fanout
                    queue:
                        name: image_crop_dlx_qu
            amqp_image_crop: # This section gets created automatically which is perfect
                dsn: 'amqp://rabbitmq:rabbitmq@127.0.0.1:5672/%2f/'
                options:
                    exchange:
                        name: image_crop_ex
                        type: fanout
                    queue:
                        name: image_crop_qu
                        arguments:
                            x-dead-letter-exchange: image_crop_dlx_ex
                            x-message-ttl: 86400

        routing:
            'App\MessageBus\Message\Image\Crop': amqp_image_crop

Message Dispacher

namespace App\Service;

use App\MessageBus\Message\Image\Crop;
use Symfony\Component\Messenger\MessageBusInterface;

class CropService
{
    private $messageBus;

    public function __construct(MessageBusInterface $messageBus)
    {
        $this->messageBus = $messageBus;
    }

    public function crop(): void
    {
        $message = new Crop('ball.png');

        $this->messageBus->dispatch($message);
    }
}

Message

namespace App\MessageBus\Message\Image;

class Crop
{
    private $path;

    public function __construct(string $path)
    {
        $this->path = $path;
    }

    public function getPath(): string
    {
        return $this->path;
    }
}

Message Handler

namespace App\MessageBus\Handler\Image;

use App\MessageBus\Message\Image\Crop;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

class CropHandler implements MessageHandlerInterface
{
    public function __invoke(Crop $message)
    {
        if ($message->getPath() === 'bad_image.jpeg') {
                // How do I reject the message here so that it ends up in DLX ?
                // Important: The running terminal command below should carry on running.
        }

        // Otherwise, I'll crop the file here
    }
}

Terminal Command

$ bin/console messenger:consume-messages amqp_image_crop

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions