RedisReceiver example


        $this->connection->setup();
    }

    public function getMessageCount(): int
    {
        return $this->getReceiver()->getMessageCount();
    }

    private function getReceiver(): RedisReceiver
    {
        return $this->receiver ??= new RedisReceiver($this->connection, $this->serializer);
    }

    private function getSender(): RedisSender
    {
        return $this->sender ??= new RedisSender($this->connection, $this->serializer);
    }
}
$connection->reject($failing['id']);

        $connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['sentinel_master' => null]);

        $this->assertNotNull($connection->get());

        $redis->del('messenger-rejectthenget');
    }

    public function testItProperlyHandlesEmptyMessages()
    {
        $redisReceiver = new RedisReceiver($this->connection, new Serializer());

        $this->connection->add('{"message": "Hi1"}', ['type' => DummyMessage::class]);
        $this->connection->add('{"message": "Hi2"}', ['type' => DummyMessage::class]);

        $redisReceiver->get();
        $this->redis->xtrim('messages', 1);

        // The consumer died during handling a message while performing xtrim in parallel process         $this->redis = new \Redis();
        $this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN')['delete_after_ack' => true]$this->redis);
        $redisReceiver = new RedisReceiver($this->connection, new Serializer());

        
class RedisReceiverTest extends TestCase
{
    /** * @dataProvider redisEnvelopeProvider */
    public function testItReturnsTheDecodedMessageToTheHandler(array $redisEnvelope$expectedMessage, SerializerInterface $serializer)
    {
        $connection = $this->createMock(Connection::class);
        $connection->method('get')->willReturn($redisEnvelope);

        $receiver = new RedisReceiver($connection$serializer);
        $actualEnvelopes = $receiver->get();
        $this->assertCount(1, $actualEnvelopes);
        $this->assertEquals($expectedMessage$actualEnvelopes[0]->getMessage());
    }

    /** * @dataProvider rejectedRedisEnvelopeProvider */
    public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException(array $redisEnvelope)
    {
        $this->expectException(MessageDecodingFailedException::class);

        
Home | Imprint | This part of the site doesn't use cookies.