createFromAmqpEnvelope example

if (isset($encodedMessage['headers']['Content-Type'])) {
            $contentType = $encodedMessage['headers']['Content-Type'];
            unset($encodedMessage['headers']['Content-Type']);

            if (!$amqpStamp || !isset($amqpStamp->getAttributes()['content_type'])) {
                $amqpStamp = AmqpStamp::createWithAttributes(['content_type' => $contentType]$amqpStamp);
            }
        }

        $amqpReceivedStamp = $envelope->last(AmqpReceivedStamp::class);
        if ($amqpReceivedStamp instanceof AmqpReceivedStamp) {
            $amqpStamp = AmqpStamp::createFromAmqpEnvelope(
                $amqpReceivedStamp->getAmqpEnvelope(),
                $amqpStamp,
                $envelope->last(RedeliveryStamp::class) ? $amqpReceivedStamp->getQueueName() : null
            );
        }

        try {
            $this->connection->publish(
                $encodedMessage['body'],
                $encodedMessage['headers'] ?? [],
                $delay,
                


    public function testCreateFromAmqpEnvelope()
    {
        $amqpEnvelope = $this->createMock(\AMQPEnvelope::class);
        $amqpEnvelope->method('getRoutingKey')->willReturn('routingkey');
        $amqpEnvelope->method('getDeliveryMode')->willReturn(2);
        $amqpEnvelope->method('getPriority')->willReturn(5);
        $amqpEnvelope->method('getAppId')->willReturn('appid');
        $amqpEnvelope->method('getCorrelationId')->willReturn('foo');

        $stamp = AmqpStamp::createFromAmqpEnvelope($amqpEnvelope);

        $this->assertSame($amqpEnvelope->getRoutingKey()$stamp->getRoutingKey());
        $this->assertSame($amqpEnvelope->getDeliveryMode()$stamp->getAttributes()['delivery_mode']);
        $this->assertSame($amqpEnvelope->getPriority()$stamp->getAttributes()['priority']);
        $this->assertSame($amqpEnvelope->getAppId()$stamp->getAttributes()['app_id']);
        $this->assertSame($amqpEnvelope->getCorrelationId()$stamp->getAttributes()['correlation_id']);
        $this->assertSame(\AMQP_NOPARAM, $stamp->getFlags());
    }

    public function testCreateFromAmqpEnvelopeWithPreviousStamp()
    {
        


    public function testItRetriesTheMessage()
    {
        $delayExchange = $this->createMock(\AMQPExchange::class);
        $delayExchange->expects($this->once())
            ->method('publish')
            ->with('{}', 'delay_messages__5000_retry', \AMQP_NOPARAM);
        $connection = $this->createDelayOrRetryConnection($delayExchange, '', 'delay_messages__5000_retry');

        $amqpEnvelope = $this->createMock(\AMQPEnvelope::class);
        $amqpStamp = AmqpStamp::createFromAmqpEnvelope($amqpEnvelope, null, '');
        $connection->publish('{}', [], 5000, $amqpStamp);
    }

    public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
    {
        $amqpConnection = $this->createMock(\AMQPConnection::class);
        $amqpChannel = $this->createMock(\AMQPChannel::class);

        $factory = $this->createMock(AmqpFactory::class);
        $factory->method('createConnection')->willReturn($amqpConnection);
        $factory->method('createChannel')->willReturn($amqpChannel);
        
Home | Imprint | This part of the site doesn't use cookies.