Symfony Messenger
repository·8.2·Indexed 22 days ago
https://github.com/symfony/messengerA component for sending and receiving messages to enable asynchronous processing and communication between applications via message queues. Includes tools for consuming messages (messenger:consume), debugging configurations (debug:messenger), managing failed messages (messenger:failed:show, retry, remove), and setting up transport infrastructure (messenger:setup-transports).
What's inside symfony-messenger
- The Messenger component is designed to help applications send and receive messages. This can be used to communicate with other applications or to manage asynchronous processing via message queues.
How to consume from all receivers or exclude specific ones
8.2To consume from every configured transport, use the
--alloption. If you want to consume from all transports except a specific one, combine--allwith--exclude-receivers.Note: The
--exclude-receiversoption cannot be used without--all.php bin/console messenger:consume --all # Consume from all except 'failed_messages' php bin/console messenger:consume --all --exclude-receivers=failed_messagesHow to use regular expressions for receivers
8.2You can pass a regular expression as an argument to match multiple receivers. The order of receivers will match their order in your configuration.
To ensure a specific priority order when using multiple receivers, pass each name or regular expression as a separate argument instead of a single regex.
# Match multiple receivers via regex php bin/console messenger:consume "receiver1|receiver2" # Explicit priority: receiver2 first, then receiver1 php bin/console messenger:consume receiver2 receiver1Reference: messenger:consume arguments and options
8.2The following arguments and options are available for the
messenger:consumecommand:Arguments
receivers(array): Names or regular expression patterns of the receivers/transports to consume in order of priority.
Options
--limit <number>(-l): Limit the number of received messages.--failure-limit <number>(-f): The number of failed messages the worker can consume before stopping.--memory-limit <limit>(-m): Stop the worker if it exceeds a given memory usage limit. Supports shorthand byte values like128M,1G, etc.--time-limit <seconds>(-t): Stop the worker after the given time limit in seconds. The worker will finish processing the current message before exiting.--sleep <seconds>: Seconds to sleep before asking for new messages after no messages were found (default:1).--bus <name>(-b): Name of the bus to which received messages should be dispatched. If not provided, the bus is determined automatically.--queues <queue-name>(array): Limit receivers to only consume from the specified queues (supported by some receivers).--no-reset [number]: Prevents resetting container services after each message. If a number is passed, services are reset every N messages.--all: Consume messages from all receivers.--exclude-receivers <receiver-name>(array): Exclude specific receivers from consumption (only usable with--all).--keepalive <seconds>: Whether to use the transport's keepalive mechanism if implemented (default:5).--fetch-size <number>: The number of messages to fetch per call to the transport (default:1).
php bin/console messenger:consume receiver1 --limit=10 --memory-limit=128M --bus=event_busReference: messenger:setup-transports command arguments
8.2The
messenger:setup-transportscommand accepts the following argument:| Argument | Required | Description | |----------|----------|-------------| | `transport` | No | Name of the specific transport to setup. If omitted, all transports are processed. |Reference: messenger:stats options and arguments
8.2The
messenger:statscommand accepts the following input configuration:Arguments
transport_names(array, optional): List of transports' names to query.
Options
--format(string, required): The output format. Available options aretxtandjson.
Arguments: transport_names List of transports' names Options: --format=VALUE The output format ("txt", "json") [default="txt"]Reference: messenger:failed:retry options and arguments
8.2The following arguments and options are available for the
messenger:failed:retrycommand.Arguments: id (array) Specific message id(s) to retry Options: --force Force action without confirmation --transport (string) Use a specific failure transport (default: the global failure transport) --keepalive (int) Whether to use the transport's keepalive mechanism if implemented (default: 5) --class-filter (string) Filter by a specific class name --failed-after (string) Only select messages that failed at or after this date --failed-before (string) Only select messages that failed at or before this dateReference: messenger:failed:show options and arguments
8.2The
messenger:failed:showcommand accepts the following arguments and options:Type Name Description Argument idSpecific message id to show Option --max=<value>Maximum number of messages to list (default: 50)Option --transport=<name>Use a specific failure transport Option --statsDisplay the message count by class Option --class-filter=<name>Filter by a specific class name Option --failed-after=<date>Only select messages that failed at or after this date (accepts DateTimeImmutableexpressions)Option --failed-before=<date>Only select messages that failed at or before this date (accepts DateTimeImmutableexpressions)Reference: debug:messenger arguments
8.2The
debug:messengercommand accepts the following argument:Argument Required Description busNo The ID of the specific message bus you want to inspect. If omitted, all buses are shown. php bin/console debug:messenger [bus]Reference: messenger:failed:remove options
8.2The following options and arguments are available for the
messenger:failed:removecommand:Arguments: id (optional, array) Specific message id(s) to remove Options: --all Remove all failed messages from the transport --force Force the operation without confirmation --transport (required) Use a specific failure transport --show-messages Display messages before removing it (if multiple ids are given) --class-filter (required) Filter by a specific class name --failed-after (required) Only select messages that failed at or after this date --failed-before (required) Only select messages that failed at or before this datePrepare transport infrastructure with messenger:setup-transports
8.2The
messenger:setup-transportscommand prepares the required infrastructure (such as database tables, queues, or other external resources) for your configured Messenger transports.It can be used to set up all configured transports at once, or you can specify a single transport name to target only one.
Note that a transport can only be set up via this command if it implements the
Symfony\Component\Messenger\Transport\SetupableTransportInterface.# Setup all configured transports php bin/console messenger:setup-transports # Setup a specific transport by name php bin/console messenger:setup-transports <transport> # Example: Setup the 'async' transport php bin/console messenger:setup-transports asyncDebug Messenger configuration with debug:messenger
8.2The
debug:messengercommand allows you to inspect your Messenger configuration. It lists all messages that can be dispatched via your configured message buses and shows which handlers are responsible for processing them.Usage
To list all messages for all available buses:
php bin/console debug:messengerTo list messages for a specific bus only, provide the bus ID as an argument:
php bin/console debug:messenger <bus_id>Output Information
For each bus, the command displays a table containing:
- Message Class: The FQCN (Fully Qualified Class Name) of the message.
- Description: If the message class has a docblock, it is displayed as a comment.
- Handlers: The class name of the handler(s) responsible for the message.
- Conditions: If a handler is restricted by specific conditions (e.g., using
when()), these are displayed as(when key=value, ...).
php bin/console debug:messenger # Or for a specific bus: php bin/console debug:messenger command_bus