validReceiverNameNotProvided example

use Shopware\Core\Framework\MessageQueue\MessageQueueException;

/** * @internal * * @covers \Shopware\Core\Framework\MessageQueue\MessageQueueException */
class MessageQueueExceptionTest extends TestCase
{
    public function testValidReceiverNameNotProvided(): void
    {
        $exception = MessageQueueException::validReceiverNameNotProvided();

        static::assertSame('FRAMEWORK__NO_VALID_RECEIVER_NAME_PROVIDED', $exception->getErrorCode());
        static::assertSame('No receiver name provided.', $exception->getMessage());
        static::assertSame(400, $exception->getStatusCode());
    }

    public function testWorkerIsLocked(): void
    {
        $exception = MessageQueueException::workerIsLocked('test');

        static::assertSame('FRAMEWORK__WORKER_IS_LOCKED', $exception->getErrorCode());
        
private readonly int $pollInterval,
        private readonly LockFactory $lockFactory
    ) {
    }

    #[Route(path: '/api/_action/message-queue/consume', name: 'api.action.message-queue.consume', methods: ['POST'])]     public function consumeMessages(Request $request): JsonResponse
    {
        $receiverName = $request->get('receiver');

        if (!$receiverName || !$this->receiverLocator->has($receiverName)) {
            throw MessageQueueException::validReceiverNameNotProvided();
        }

        $consumerLock = $this->lockFactory->createLock('message_queue_consume_' . $receiverName);

        if (!$consumerLock->acquire()) {
            throw MessageQueueException::workerIsLocked($receiverName);
        }

        $receiver = $this->receiverLocator->get($receiverName);

        $workerDispatcher = new EventDispatcher();
        
Home | Imprint | This part of the site doesn't use cookies.