Skip to content

Commit

Permalink
NEXT-31249 - mention overriding transport and lowering the priority
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzKrafeld committed Oct 30, 2023
1 parent 787def5 commit 85b6387
Showing 1 changed file with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nav:
## Overview

::: warning
Parts of this guide refer to the `low_priority` queue and the corresponding `AsyncLowPriorityMessageInterface` which is only available in version 6.5.7.0 and above. Configuring the messenger to consume this queue will fail, if it does not exist.
Parts of this guide refer to the `low_priority` queue and the corresponding `LowPriorityMessageInterface` which is only available in version 6.5.7.0 and above. Configuring the messenger to consume this queue will fail, if it does not exist.
:::

In this guide you'll learn how to create a message and add it to the queue.
Expand All @@ -27,7 +27,7 @@ As most guides, this guide is also built upon the [Plugin base guide](../../plug

## Create a message

First, we have to create a new message class in the directory `<plugin root>/MessageQueue/Message`. In this example, we create a `SmsNotification` that contains a string with content. By default, all messages are handled synchronously, to change the behavior to asynchronously we have to implement the `AsyncMessageInterface` interface. For messages which should also be handled asynchronously but with a lower priority, you have to implement the `AsyncLowPriorityMessageInterface` interface.
First, we have to create a new message class in the directory `<plugin root>/MessageQueue/Message`. In this example, we create a `SmsNotification` that contains a string with content. By default, all messages are handled synchronously, to change the behavior to asynchronously we have to implement the `AsyncMessageInterface` interface. For messages which should also be handled asynchronously but with a lower priority, implement the `LowPriorityMessageInterface` interface.

Here's an example:

Expand Down Expand Up @@ -98,6 +98,45 @@ public function sendMessage(string $message): void
}
```

## Lower the priority for specific async messages

You might consider using the new `low_priority` queue if you are dispatching messages that do not need to be handled immediately. To configure specific messages to be transported via the `low_priority` queue, you need to either adjust the routing or implement the `LowPriorityMessageInterface` as already mentioned:

```yaml
# config/packages/framework.yaml
framework:
messenger:
routing:
'Your\Custom\Message': low_priority
```
## Override transport for specific messages
If you explicitly configure a message to be transported via the `async` (default) queue, even though it implements the `LowPriorityMessageInterface` which would usually be transported via the `low_priority` queue, the transport is overridden for this specific message.

Example:
```php
// <plugin root>/src/MessageQueue/Message/LowPriorityMessage.php
<?php declare(strict_types=1);
namespace Your\Custom;
use Shopware\Core\Framework\MessageQueue\LowPriorityMessageInterface;
class LowPriorityMessage implements LowPriorityMessageInterface
{
}
```

```yaml
# config/packages/framework.yaml
framework:
messenger:
routing:
'Shopware\Core\Framework\MessageQueue\LowPriorityMessageInterface': low_priority
'Your\Custom\LowPriorityMessage': async
```

## Encrypted messages

As the sent messages may travel through some 3rd party services you may want to encrypt messages containing sensible information. To send encrypted messages simply use the `encrypted.messenger.bus.shopware` rather than the `messenger.bus.shopware` message bus. The encrypted bus will handle encryption and decryption for you.
Expand Down

0 comments on commit 85b6387

Please sign in to comment.