Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple workers / consumers are consuming the same message twice? #1338

Open
MrSnoozles opened this issue Feb 21, 2024 · 0 comments
Open

Multiple workers / consumers are consuming the same message twice? #1338

MrSnoozles opened this issue Feb 21, 2024 · 0 comments

Comments

@MrSnoozles
Copy link

Hi,

I noticed that when I start multiple consumers the same messages are executed by the consumers. Is there a way to "reserve" a message? I'm using Dbal to store the messages in a MariaDB database.

How I dispatch the messages

$queue = $context->createQueue('default');
$message = $context->createMessage($messageContent);
$producer = $context->createProducer();
$producer->send($queue, $message);

How I consume the messages

// bin/start-worker.php

/* @var $context DbalContext */
$subscriptionConsumer = $context->createSubscriptionConsumer();
$queue    = $context->createQueue('default');
$consumer = $context->createConsumer($queue);

$subscriptionConsumer->subscribe(
    $consumer,
    function (Message $message, Consumer $consumer) {
        $job = unserialize($message->getBody());
        $job->handle();

        $consumer->acknowledge($message);
    }
);

$subscriptionConsumer->consume(0);

Now running php bin/start-worker.php multiple times will lead to the same messages being picked up several times. Am I understanding something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant