Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
188 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Queue\Message; | ||
|
||
/** | ||
* Envelope is a message container that adds additional metadata. | ||
*/ | ||
interface EnvelopeInterface extends MessageInterface | ||
{ | ||
public function getMessage(): MessageInterface; | ||
|
||
public function withMessage(MessageInterface $message): self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Queue\Message; | ||
|
||
trait EnvelopeTrait | ||
{ | ||
private MessageInterface $message; | ||
|
||
public function getMessage(): MessageInterface | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function withMessage(MessageInterface $message): self | ||
{ | ||
$instance = clone $this; | ||
$instance->message = $message; | ||
|
||
return $instance; | ||
} | ||
|
||
public function getHandlerName(): string | ||
{ | ||
return $this->message->getHandlerName(); | ||
} | ||
|
||
public function getData(): mixed | ||
{ | ||
return $this->message->getData(); | ||
} | ||
|
||
public function getMetadata(): array | ||
{ | ||
return $this->message->getMetadata(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Queue\Message; | ||
|
||
/** | ||
* ID envelope allows to identify a message. | ||
*/ | ||
final class IdEnvelope implements EnvelopeInterface | ||
{ | ||
use EnvelopeTrait; | ||
|
||
public const MESSAGE_ID_KEY = 'yii-message-id'; | ||
|
||
public function __construct( | ||
private MessageInterface $message, | ||
private string|int|null $id = null, | ||
) { | ||
} | ||
|
||
public function setId(string|int|null $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getId(): string|int|null | ||
{ | ||
return $this->id ?? $this->message->getMetadata()[self::MESSAGE_ID_KEY] ?? null; | ||
} | ||
|
||
public function getMetadata(): array | ||
{ | ||
return array_merge($this->message->getMetadata(), [ | ||
self::MESSAGE_ID_KEY => $this->getId(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Queue\Middleware\FailureHandling; | ||
|
||
use Yiisoft\Queue\Message\EnvelopeInterface; | ||
use Yiisoft\Queue\Message\EnvelopeTrait; | ||
use Yiisoft\Queue\Message\MessageInterface; | ||
|
||
final class FailureEnvelope implements EnvelopeInterface | ||
{ | ||
use EnvelopeTrait; | ||
|
||
public function __construct( | ||
private MessageInterface $message, | ||
private array $meta, | ||
) { | ||
} | ||
|
||
public function getMetadata(): array | ||
{ | ||
return array_merge($this->message->getMetadata(), $this->meta); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.