Worker example

$eventDispatcher->addSubscriber($this->getContainer()->get(MessageQueueStatsSubscriber::class));

        /** @var ServiceLocator<ReceiverInterface> $locator */
        $locator = $this->getContainer()->get('messenger.test_receiver_locator');

        /** @var ReceiverInterface $receiver */
        $receiver = $locator->get('async');

        /** @var MessageBusInterface $bus */
        $bus = $this->getContainer()->get('messenger.bus.test_shopware');

        $worker = new Worker([$receiver]$bus$eventDispatcher);

        $worker->run([
            'sleep' => 1000,
        ]);
    }

    abstract protected static function getContainer(): ContainerInterface;
}
$workerDispatcher->addSubscriber($listener);
        $workerDispatcher->addSubscriber($this->statsSubscriber);
        $workerDispatcher->addSubscriber($this->stopWorkerOnRestartSignalListener);
        $workerDispatcher->addSubscriber($this->earlyReturnListener);

        if ($this->memoryLimit !== '-1') {
            $workerDispatcher->addSubscriber(new StopWorkerOnMemoryLimitListener(
                MemorySizeCalculator::convertToBytes($this->memoryLimit)
            ));
        }

        $worker = new Worker([$this->defaultTransportName => $receiver]$this->bus, $workerDispatcher);

        $worker->run(['sleep' => 50]);

        $consumerLock->release();

        return new JsonResponse(['handledMessages' => $listener->getHandledMessages()]);
    }
}
Home | Imprint | This part of the site doesn't use cookies.