Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Extract the failed-message logic out of the console commands - #66002

Open
nicolas-grekas wants to merge 1 commit into
symfony:8.2from
nicolas-grekas:messenger-failed-message-repository
Open

[Messenger] Extract the failed-message logic out of the console commands#66002
nicolas-grekas wants to merge 1 commit into
symfony:8.2from
nicolas-grekas:messenger-failed-message-repository

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member
Q A
Branch? 8.2
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #60151
License MIT

AbstractFailedMessagesCommand mixes three concerns: transport-facing logic that has nothing to do with the console, console input parsing, and rendering. Only the first is what a web UI or any other non-console caller needs, and today it can only be reached by extending an @internal command.

This extracts that first group:

  • FailedMessageRepository resolves the failure transports and exposes getTransportNames(), count(), supportsListing(), find(), all(), remove() and redispatch(). It is registered as messenger.failed_message_repository and aliased for autowiring, so a controller can inject it directly. It is removed from the container when no failure transport is configured.
  • FailedMessageFilter is the class-name and failure-time selection that matchesFilter() used to implement, as a value object with a matches() method.

The commands keep their options, their rendering, their confirmations and their exact output. The net effect on the existing files is 206 lines removed for 154 added.

Answers to the three questions raised in the issue:

Retry stays out. messenger:failed:retry does not simply redispatch: it builds a real Worker, wires event listeners and handles signals, and for the by-id path it wraps each envelope in a SingleMessageReceiver so the ack goes to the wrapper rather than to the failure transport. Extracting that means deciding what a non-console caller gets in place of the worker loop, which is a design question of its own. FailedMessageRepository::redispatch() does exist, because for a listable transport it is a dispatch plus an ack and needs no worker, but the command keeps its own flow and both paths now share prepareForRedispatch() so the stamp stripping has a single definition.

No delegation shims. AbstractFailedMessagesCommand is marked @internal, so the methods that moved (getMessageIdsByFilter(), matchesFilter(), getReceiver(), getMessageId()) are removed rather than kept as delegations, and getFilters() becomes getFilter() returning the value object. Constructor signatures are untouched, so anything instantiating the concrete commands keeps working.

Location. A new Symfony\Component\Messenger\Failure\ namespace, alongside the existing Retry\ and Execution\.

The API is michaelthieulin's proposal from the issue thread, with remove() taking an Envelope rather than an id so that removing every message does not re-find() each one.

The listing, inspection and removal of failed messages lived inside
AbstractFailedMessagesCommand, mixed with console input parsing and
rendering, so a web UI had to reimplement it.

FailedMessageRepository now holds the transport-facing half and
FailedMessageFilter the class and failure-time selection. The commands
keep their options, their rendering and their confirmations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Messenger] Move failed messages commands into services

2 participants