An envelope is a message container that wraps another message and adds metadata.
An envelope implements Yiisoft\Queue\Message\EnvelopeInterface, which itself extends Yiisoft\Queue\Message\MessageInterface.
An envelope is transparent to callers: it delegates the wrapped message type and data unchanged.
getType()is delegated to the wrapped message.getData()is delegated to the wrapped message.
Envelopes modify the metadata returned by getMetadata() and may provide convenience methods for accessing specific metadata entries (for example, getId() in an ID envelope).
To wrap a message into an envelope, envelope classes provide:
EnvelopeInterface::fromMessage(MessageInterface $message): static
and, via MessageInterface inheritance, also support:
Envelope::fromData(string $type, mixed $data, array $metadata = []): static
Yiisoft\Queue\Message\IdEnvelope adds a message identifier into metadata under the IdEnvelope::MESSAGE_ID_KEY key ("yii-message-id").
This envelope is used to carry the adapter-provided message ID through the message lifecycle.
Yiisoft\Queue\Middleware\FailureHandling\FailureEnvelope stores failure-handling metadata.
See Errors and retryable messages for error handling concepts and Envelope metadata and stack reconstruction for details on how failure metadata is merged.