Search by

componenta / cqrs-retry

Shelamkoff

Retry middleware for Componenta CQRS commands

Package info

github.com/componenta/cqrs-retry

pkg:composer/componenta/cqrs-retry

Statistics

Installs: 53

Dependents: 0

Suggesters: 1

Stars: 0

Open Issues: 0

v3.0.0 2026-09-13 23:19 UTC

This package is auto-updated.

Last update: 2026-09-13 23:22:41 UTC


README

Retry middleware for CQRS v4 commands marked with #[Componenta\CQRS\Retry\Attribute\Retry].

composer require componenta/cqrs-retry

Register the CQRS and retry providers and add RetryMiddleware to the command middleware chain where transient failures may be retried.

return [
    new Componenta\CQRS\ConfigProvider(),
    new Componenta\CQRS\Retry\ConfigProvider(),
];

The provider registers RetryMiddleware. The middleware reads Retry through the core CommandMetadataProviderInterface. Its default Reflection implementation creates fresh metadata on each call, independently of handler maps and application environment.

Middleware ordering is controlled by the application. With transaction middleware, the two common compositions have different semantics:

RetryMiddleware
  TransactionMiddleware
    handler

creates a fresh transaction for every retry attempt. By contrast:

TransactionMiddleware
  RetryMiddleware
    handler

keeps all attempts inside one surrounding transaction. The package does not reject either topology; choose the one that matches the desired transaction semantics.

RetryableExceptionInterface marks transient exceptions that may be retried. Additional throwable classes can be configured explicitly in the middleware constructor. Retry attempts, delay, multiplier, maximum delay, and jitter are controlled by #[Retry] and middleware configuration.

For controlled waiting and randomness, the constructor also accepts optional closures:

  • sleep(int $milliseconds): void waits between attempts.
  • randomInt(int $min, int $max): int returns an integer within the inclusive range.

The defaults use PHP's usleep() and random_int(). The registered factory uses these defaults. Supplying the closures supports deterministic tests of actual retry attempts and delays without sleeping or calling private methods.