Skip to content

Commit

Permalink
feature #54589 [Messenger] forward a Clock instance to the created In…
Browse files Browse the repository at this point in the history
…MemoryTransport (xabbuh)

This PR was merged into the 7.1 branch.

Discussion
----------

[Messenger] forward a Clock instance to the created InMemoryTransport

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | Fix #53531 (comment)
| License       | MIT

Commits
-------

1cfd8b5 forward a Clock instance to the created InMemoryTransport
  • Loading branch information
fabpot committed Apr 17, 2024
2 parents 1d847b4 + 1cfd8b5 commit a7900e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
->tag('messenger.transport_factory')

->set('messenger.transport.in_memory.factory', InMemoryTransportFactory::class)
->args([
service('clock')->nullOnInvalid(),
])
->tag('messenger.transport_factory')
->tag('kernel.reset', ['method' => 'reset'])

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.1
---

* `InMemoryTransportFactory` creates the `InMemoryTransport` with a clock (if configured in the factory)
* Add option `redis_sentinel` as an alias for `sentinel_master`
* Add `--all` option to the `messenger:consume` command
* Add parameter `$jitter` to `MultiplierRetryStrategy` in order to randomize delay and prevent the thundering herd effect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Messenger\Transport\InMemory;

use Psr\Clock\ClockInterface;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
Expand All @@ -28,11 +29,16 @@ class InMemoryTransportFactory implements TransportFactoryInterface, ResetInterf
*/
private array $createdTransports = [];

public function __construct(
private readonly ?ClockInterface $clock = null,
) {
}

public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
['serialize' => $serialize] = $this->parseDsn($dsn);

return $this->createdTransports[] = new InMemoryTransport($serialize ? $serializer : null);
return $this->createdTransports[] = new InMemoryTransport($serialize ? $serializer : null, $this->clock);
}

public function supports(string $dsn, array $options): bool
Expand Down

0 comments on commit a7900e8

Please sign in to comment.