0 follower

Final Class Yiisoft\Queue\Message\GenericMessage

InheritanceYiisoft\Queue\Message\GenericMessage » Yiisoft\Queue\Message\Message
ImplementsYiisoft\Queue\Message\MessageInterface

A general-purpose immutable {@see MessageInterface} implementation that holds a message type and its payload data.

Prefer creating custom message classes that better express your domain.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Queue\Message\GenericMessage
fromData() Creates a new message instance from the given type and payload data. Yiisoft\Queue\Message\GenericMessage
getData() Returns the message payload data. Yiisoft\Queue\Message\GenericMessage
getMetadata() Yiisoft\Queue\Message\Message
getType() Returns the message type used to resolve the handler. Yiisoft\Queue\Message\GenericMessage
withMetadata() Yiisoft\Queue\Message\Message

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $type, mixed $data )
$type string

A message type used to resolve the handler.

$data mixed

Message payload data.

                public function __construct(
    private readonly string $type,
    private readonly mixed $data,
) {}

            
fromData() public static method

Creates a new message instance from the given type and payload data.

public static Yiisoft\Queue\Message\MessageInterface fromData ( string $type, mixed $data )
$type string

A message type used to resolve the handler.

$data mixed

Message payload data.

return Yiisoft\Queue\Message\MessageInterface

The created message instance.

                public static function fromData(string $type, mixed $data): MessageInterface
{
    return new self($type, $data);
}

            
getData() public method

Returns the message payload data.

public mixed getData ( )

                public function getData(): mixed
{
    return $this->data;
}

            
getMetadata() public method
public array getMetadata ( )

                final public function getMetadata(): array
{
    return $this->metadata;
}

            
getType() public method

Returns the message type used to resolve the handler.

public string getType ( )

                public function getType(): string
{
    return $this->type;
}

            
withMetadata() public method
public static withMetadata ( array $metadata )
$metadata array

                final public function withMetadata(array $metadata): static
{
    $new = clone $this;
    $new->metadata = $metadata;
    return $new;
}