Skip to content

[Consumer] Doesn't respond to SIGINT when there are no new messages #260

Closed
@ruudk

Description

@ruudk

So I noticed that the Consumer can only be stopped when a new message arrives (#89). I think this is because of this line https://github.com/videlalvaro/RabbitMqBundle/blob/b546af972552a43c1fd3e23226df793b6f709d5e/RabbitMq/Consumer.php#L47

So I was thinking about how to fix this. What if we'd run that while with a AMQPTimeout inside another while(true)? This is how PHP Resque solves this.

Something like this:

    public function consume($msgAmount)
    {
        $this->target = $msgAmount;

        $this->setupConsumer();

        while(true) {
            $this->maybeStopConsumer();

            try {
                while (count($this->getChannel()->callbacks)) {
                    $this->maybeStopConsumer();
                    $this->getChannel()->wait(null, false, $this->getIdleTimeout());
                }
            } catch(\PhpAmqpLib\Exception\AMQPTimeoutException $exception) {
                echo "Timeout, restart\n";
            }
        }
    }
``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions