Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Message/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

abstract class Envelope implements EnvelopeInterface
{
/**
* @psalm-var array<string, mixed>|null
*/
private ?array $metadata = null;

public function __construct(protected MessageInterface $message) {}
Expand Down
4 changes: 1 addition & 3 deletions src/Message/IdEnvelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ public function __construct(

public static function fromMessage(MessageInterface $message): static
{
/** @var mixed $rawId */
$rawId = $message->getMetadata()[self::MESSAGE_ID_KEY] ?? null;

/** @var int|string|null $id */
$id = match (true) {
$rawId === null => null, // don't remove this branch: it's important for compute speed
is_string($rawId) => $rawId,
is_string($rawId),
is_int($rawId) => $rawId,
is_object($rawId) && method_exists($rawId, '__toString') => (string) $rawId,
default => null,
Expand Down
2 changes: 2 additions & 0 deletions src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ final class Message implements MessageInterface
* @param string $type A message type used to resolve the handler.
* @param mixed $data Message data, encodable by a queue adapter
* @param array $metadata Message metadata, encodable by a queue adapter
*
* @psalm-param array<string, mixed> $metadata
*/
public function __construct(
private readonly string $type,
Expand Down
4 changes: 3 additions & 1 deletion src/Message/MessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function getType(): string;
public function getData(): mixed;

/**
* Returns message metadata: timings, attempts count, metrics, etc.
* Returns message metadata: timings, attempts count, metrics, etc. Keys are always strings.
*
* @return array<string, mixed>
*/
public function getMetadata(): array;
}
1 change: 0 additions & 1 deletion src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function push(MessageInterface $message): MessageInterface
return $message;
}

/** @var string $messageId */
$messageId = $message->getMetadata()[IdEnvelope::MESSAGE_ID_KEY] ?? 'null';
$this->logger->info(
'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.',
Expand Down
Loading