feature #38135 [AmazonSqsMessenger] Added the count message awareness on the transport (raphahardt)

This PR was merged into the 5.2-dev branch.

Discussion
----------

[AmazonSqsMessenger] Added the count message awareness on the transport

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | /
| License       | MIT
| Doc PR        | /

Added the possibility of have message count awareness of the receiver on the transport.

Commits
-------

96b63b83bf [AmazonSqsMessenger] Added the count message awareness on the transport
This commit is contained in:
Fabien Potencier 2020-09-10 14:42:05 +02:00
commit 4c873fe501
2 changed files with 18 additions and 1 deletions

View File

@ -16,6 +16,7 @@ use Symfony\Component\Messenger\Bridge\AmazonSqs\Tests\Fixtures\DummyMessage;
use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsTransport; use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\AmazonSqsTransport;
use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection; use Symfony\Component\Messenger\Bridge\AmazonSqs\Transport\Connection;
use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportInterface; use Symfony\Component\Messenger\Transport\TransportInterface;
@ -50,6 +51,13 @@ class AmazonSqsTransportTest extends TestCase
$this->assertSame($decodedMessage, $envelopes[0]->getMessage()); $this->assertSame($decodedMessage, $envelopes[0]->getMessage());
} }
public function testTransportIsAMessageCountAware()
{
$transport = $this->getTransport();
$this->assertInstanceOf(MessageCountAwareInterface::class, $transport);
}
private function getTransport(SerializerInterface $serializer = null, Connection $connection = null) private function getTransport(SerializerInterface $serializer = null, Connection $connection = null)
{ {
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock(); $serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Messenger\Bridge\AmazonSqs\Transport;
use AsyncAws\Core\Exception\Http\HttpException; use AsyncAws\Core\Exception\Http\HttpException;
use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\TransportException; use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface;
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer; use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface; use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\SetupableTransportInterface; use Symfony\Component\Messenger\Transport\SetupableTransportInterface;
@ -23,7 +24,7 @@ use Symfony\Contracts\Service\ResetInterface;
/** /**
* @author Jérémy Derussé <jeremy@derusse.com> * @author Jérémy Derussé <jeremy@derusse.com>
*/ */
class AmazonSqsTransport implements TransportInterface, SetupableTransportInterface, ResetInterface class AmazonSqsTransport implements TransportInterface, SetupableTransportInterface, MessageCountAwareInterface, ResetInterface
{ {
private $serializer; private $serializer;
private $connection; private $connection;
@ -60,6 +61,14 @@ class AmazonSqsTransport implements TransportInterface, SetupableTransportInterf
($this->receiver ?? $this->getReceiver())->reject($envelope); ($this->receiver ?? $this->getReceiver())->reject($envelope);
} }
/**
* {@inheritdoc}
*/
public function getMessageCount(): int
{
return ($this->receiver ?? $this->getReceiver())->getMessageCount();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */