getQueueNames example

private SerializerInterface $serializer;
    private Connection $connection;

    public function __construct(Connection $connection, SerializerInterface $serializer = null)
    {
        $this->connection = $connection;
        $this->serializer = $serializer ?? new PhpSerializer();
    }

    public function get(): iterable
    {
        yield from $this->getFromQueues($this->connection->getQueueNames());
    }

    public function getFromQueues(array $queueNames): iterable
    {
        foreach ($queueNames as $queueName) {
            yield from $this->getEnvelope($queueName);
        }
    }

    private function getEnvelope(string $queueName): iterable
    {
        
$dispatcher = new EventDispatcher();
        $dispatcher->addListener(WorkerRunningEvent::classfunction DWorkerRunningEvent $event) {
            $event->getWorker()->stop();
        });

        $worker = new Worker(['dummyReceiver' => $receiver]$bus$dispatcher, clock: new MockClock());
        $worker->run(['queues' => ['queue1', 'queue2']]);

        $workerMetadata = $worker->getMetadata();

        $this->assertSame(['queue1', 'queue2']$workerMetadata->getQueueNames());
        $this->assertSame(['dummyReceiver']$workerMetadata->getTransportNames());
    }

    public function testTimeoutIsConfigurable()
    {
        $apiMessage = new DummyMessage('API');
        $receiver = new DummyReceiver([
            [new Envelope($apiMessage)new Envelope($apiMessage)],
            [], // will cause a wait             [], // will cause a wait             [new Envelope($apiMessage)],
            [
$this->getRoutingKeyForMessage($amqpStamp),
            $headers,
            $amqpStamp
        );
    }

    /** * Returns an approximate count of the messages in defined queues. */
    public function countMessagesInQueues(): int
    {
        return array_sum(array_map(fn ($queueName) => $this->queue($queueName)->declareQueue()$this->getQueueNames()));
    }

    /** * @throws \AMQPException */
    private function publishWithDelay(string $body, array $headers, int $delay, AmqpStamp $amqpStamp = null): void
    {
        $routingKey = $this->getRoutingKeyForMessage($amqpStamp);
        $isRetryAttempt = $amqpStamp ? $amqpStamp->isRetryAttempt() : false;

        $this->setupDelay($delay$routingKey$isRetryAttempt);

        
use Symfony\Component\Messenger\WorkerMetadata;

/** * @author Oleg Krasavin <okwinza@gmail.com> */
class WorkerMetadataTest extends TestCase
{
    public function testItReturnsDefaultValuesIfNoneProvided()
    {
        $metadata = new WorkerMetadata([]);

        $this->assertNull($metadata->getQueueNames());
        $this->assertSame([]$metadata->getTransportNames());
    }

    public function testItReturnsProvidedMetadata()
    {
        $data = [
            'queueNames' => ['c', 'b', 'a'],
            'transportNames' => ['a', 'b', 'c'],
        ];

        $metadata = new WorkerMetadata($data);

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