Download the PHP package rasuvaeff/yii3-outbox without Composer

On this page you can find all versions of the php package rasuvaeff/yii3-outbox. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii3-outbox

rasuvaeff/yii3-outbox

Stable Version Total Downloads Build Static analysis Psalm Level PHP License Русская версия

Transactional outbox pattern implementation for Yii3. Provides a stateless core for reliably publishing messages with configurable retry policies.

Using an AI coding assistant? llms.txt has a compact API reference you can use. Projects using the llm/skills Composer plugin also get this package's agent skill synced into .agents/skills/ automatically on install.

Requirements

Installation

Usage

Recording a message

The transactional guarantee

The pattern is only worth its name when the outbox write commits atomically with the business write it describes. The core cannot enforce this: it opens no transaction and knows nothing about your connection. Two obligations are therefore yours:

  1. Call record() inside the same database transaction as the business write.
  2. Use a storage that writes through the same connection as your business tables — rasuvaeff/yii3-outbox-db takes a ConnectionInterface for exactly this reason.

Break either obligation and the guarantee is void: commit the order without the message and the event is lost forever; commit the message without the order and consumers observe an event that never happened. A storage backed by a different database — or by a message broker — cannot provide this guarantee at all, and InMemoryStorage is a test double, not a durable one.

Message ids

The message id is the primary key of the outbox table and, when messages are exported to ClickHouse, the deduplication key of the ReplacingMergeTree. Two ways to control it:

Pass the domain event's id — the right choice whenever the message mirrors an event that already has an identifier. Republishing the same event then cannot mint a second id, so the consumer has something stable to deduplicate on:

Bind a generator for messages that have no domain id. The default RandomHexIdGenerator keeps the historical format (32 random hex characters); a time-ordered id makes inserts append instead of scattering across InnoDB pages and gives batches a stable order:

The package ships no UUID implementation and depends on no UUID library — id is VARCHAR(255) in rasuvaeff/yii3-outbox-db, so any format fits and the choice stays yours.

Implementing storage

claim() is the primitive the whole polling loop rests on — Processor calls it, never findPending(). It must atomically move messages to Processing and return them, so that two workers polling the same table never receive the same message. findPending() is the read-only counterpart: safe for dashboards and diagnostics, unsafe as a worker's fetch.

Letting the storage apply the retry policy

claim() returns every Pending message, so Processor receives the ones still waiting out their backoff and writes each of them straight back as Pending. That is two writes per backing-off message per iteration, and each one occupies a slot in batchSize that a message ready to go could have used — with a large retry queue, fresh messages wait behind it.

A storage that can express the predicate in its own query language implements RetryAwareStorageInterface, and Processor claims through it automatically:

The attempts >= :maxAttempts clause is not an optimisation and must not be dropped. A message out of attempts cannot be retried, and the only thing left to do with it is mark it Failed — which Processor can only do to a message the storage handed it. Filter it out and nothing ever terminates it: it stays Pending, invisible to an alert watching Failed, forever.

$readyThreshold comes from RetryPolicy::readyThreshold($now) — the delay is the core's business, and an implementation must not reconstruct it. The interface exists separately from StorageInterface because adding the parameter to claim() itself would break every third-party implementation.

rasuvaeff/yii3-outbox-db implements it. A storage that does not is still correct: Processor falls back to claim() and filters in PHP, exactly as before.

Two consequences worth knowing before you alert on them:

Implementing a publisher

Processing the outbox

Retry behaviour

When a publish fails:

Every message a batch claims leaves Processing. A message that is claimed with its attempts already spent — restored from a backup, or left behind by a markFailed() that never reached the database — is marked Failed on sight rather than saved back as Pending, which would make it circle claim → skip → save forever with no alert on Failed ever firing.

A publisher that throws something other than PublishException is a bug, and process() rethrows it: the failure is not silently retried as if it were a delivery problem. Before the exception propagates, the current message is persisted per the retry policy and every message the batch had claimed but not yet attempted is released back to Pending (or failed, if it too was out of attempts), so nothing is left in Processing for a human to find with raw SQL.

The same applies when the storage — not the publisher — is what fails. If markPublished() throws after publish() succeeded, the message reached its consumer and only the record of that did not: it goes back to Pending and a later run publishes it again. This package delivers at least once, and the message id is what a consumer deduplicates on; leaving the row Processing instead would be a row nothing in this API can move. That branch logs Outbox message was published but could not be marked published, not the publisher warning — during a storage incident an operator should not be sent to debug the publisher.

The release is best-effort by construction: it reaches for the same storage that may be the reason the batch aborted, and a storage that is down cannot be told anything. What it does guarantee is that its own failures are logged (Failed to release a claimed outbox message) rather than thrown — the exception you catch is always the one that aborted the batch, never a symptom raised while reacting to it.

Using InMemoryStorage for tests

API reference

Outbox

Method Description
__construct(storage, clock, idGenerator?) Main entry point; default generator = RandomHexIdGenerator
record(type, payload, aggregateId?, id?) Create and persist message, returns OutboxMessage. id = the domain event's id; omitted → generator. Call inside the business transaction

StorageInterface

Method Description
save(message) Persist. Must commit with the business write — see The transactional guarantee
claim(types = [], limit = 1000) Atomically moves up to limit Pending messages to Processing and returns them. What Processor uses; safe for concurrent workers
findPending(types = [], limit = 1000) Read-only listing of Pending messages. No atomicity — for dashboards, not for workers
markPublished(message) Terminal success
markFailed(message) Terminal failure
getById(id) ?OutboxMessage

types filters by message type (empty = all), which is how several consumers share one outbox. Since claim() hands a message to exactly one caller, the type sets of independent consumers must not overlap — otherwise each message reaches only whichever worker claimed it first.

RetryAwareStorageInterface

Extends StorageInterface. Optional: implement it when the backend can apply the retry policy inside the claim itself — see Letting the storage apply the retry policy.

Method Description
claimReady(readyThreshold, maxAttempts, types = [], limit = 1000) Like claim(), but skips messages still waiting for their next attempt. Takes a message when it has never been attempted, was last attempted at or before readyThreshold, or has already spent maxAttempts attempts

OutboxMessage

Method Description
create(type, payload, aggregateId?, createdAt?, id?) Factory; id omitted → 32-char hex
getId() Message ID (32-char hex)
getType() Message type
getPayload() Raw payload string
getStatus() OutboxStatus enum
getCreatedAt() DateTimeImmutable
getAttempts() Number of publish attempts
getLastAttemptAt() ?DateTimeImmutable
getAggregateId() ?string
withStatus(status) Returns new instance with status
withAttempt(at) Returns new instance with incremented attempts and timestamp

MessageIdGeneratorInterface

Implementation Produces
RandomHexIdGenerator (default) 32 hex characters, 128 random bits
your own anything non-empty; id is VARCHAR(255) in the DB adapter

OutboxStatus

Case Value Meaning
Pending 'pending' Awaiting publication, including retries with attempts > 0
Processing 'processing' Claimed by a worker; no other worker may take it
Published 'published' Terminal success
Failed 'failed' Terminal failure, retries exhausted

RetryPolicy

Method Description
__construct(maxAttempts, delaySeconds) Default: 3 attempts, 60s delay
shouldRetry(message) Checks attempt count
isReadyForRetry(message, now) Checks attempts + delay elapsed
readyThreshold(now) now - delaySeconds: the same check as a boundary a storage can filter on. Feeds RetryAwareStorageInterface::claimReady()

Processor

Method Description
__construct(storage, publisher, retryPolicy, clock, batchSize, logger) Default batch: 100
process() Returns ProcessingResult

ProcessingResult

Property/Method Description
$published Count of successfully published messages
$failed Count of publish failures this run, plus messages claimed with no attempts left
$skipped Count of claimed messages not ready for retry. 0 against a RetryAwareStorageInterface, which never claims them
total() Sum of all counters

Serializer

Serializer implements SerializerInterface — the extension point a storage backend or transport uses to move a message across a boundary as a string. Swap in your own implementation for a different wire format; the interface is the contract, Serializer is the JSON default.

Method Description
serialize(message) Message to JSON
deserialize(data) JSON to Message

deserialize() rejects every malformed input with InvalidArgumentException — missing fields, wrong types, an unknown status, an unparsable or empty datetime. A caller catching "bad input" never has to also catch ValueError or DateMalformedStringException from a field the parser forgot to guard.

Security

Examples

See examples/ for complete usage examples.

Development

make test-coverage and make mutation bootstrap pcov inside the composer:2 container because the base image has no coverage driver.

License

BSD-3-Clause. See LICENSE.md.


All versions of yii3-outbox with dependencies

PHP Build Version
Package Version
Requires php Version 8.3 - 8.5
ext-json Version *
psr/clock Version ^1.0
psr/log Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rasuvaeff/yii3-outbox contains the following files

Loading the files please wait ...