getQueueName example


class AmqpReceivedStampTest extends TestCase
{
    public function testStamp()
    {
        $amqpEnvelope = $this->createMock(\AMQPEnvelope::class);

        $stamp = new AmqpReceivedStamp($amqpEnvelope, 'queueName');

        $this->assertSame($amqpEnvelope$stamp->getAmqpEnvelope());
        $this->assertSame('queueName', $stamp->getQueueName());
    }
}
yield $envelope->with(new AmqpReceivedStamp($amqpEnvelope$queueName));
    }

    public function ack(Envelope $envelope): void
    {
        try {
            $stamp = $this->findAmqpStamp($envelope);

            $this->connection->ack(
                $stamp->getAmqpEnvelope(),
                $stamp->getQueueName()
            );
        } catch (\AMQPException $exception) {
            throw new TransportException($exception->getMessage(), 0, $exception);
        }
    }

    public function reject(Envelope $envelope): void
    {
        $stamp = $this->findAmqpStamp($envelope);

        $this->rejectAmqpEnvelope(
            
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,
                $amqpStamp
            );
        } catch (\AMQPException $e) {
            
return $envelopes;
    }

    private function receiveWithQueueName(AmqpReceiver $receiver)
    {
        // let RabbitMQ receive messages         usleep(100 * 1000); // 100ms
        $receivedEnvelopes = [];
        foreach ($receiver->get() as $envelope) {
            $queueName = $envelope->last(AmqpReceivedStamp::class)->getQueueName();
            $receivedEnvelopes[$queueName] = $envelope;
            $receiver->ack($envelope);
        }

        return $receivedEnvelopes;
    }
}
Home | Imprint | This part of the site doesn't use cookies.