Skip to content

Strange RabbitMQ errors #630

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

Open
akalongman opened this issue May 12, 2025 · 2 comments
Open

Strange RabbitMQ errors #630

akalongman opened this issue May 12, 2025 · 2 comments
Assignees

Comments

@akalongman
Copy link

Versions:

  • Laravel/Lumen version: 12.13.0
  • RabbitMQ version: 3.9.21
  • Package version: 14.2.0

I am getting strange errors and I dont know how to fix them. Even how to debug.

I have ran queue with supervisord:

[program:project-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/project.ge/artisan queue:work --queue=queue1,queue2,queue3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=project
numprocs=16
redirect_stderr=true
stdout_logfile=/var/www/project.ge/storage/logs/workers/queue.log
stopwaitsecs=3600

And in Sentry I have the following errors:

  1. PhpAmqpLib\Exception\AMQPRuntimeException: Lost connection: Channel connection is closed.
  2. PhpAmqpLib\Exception\AMQPProtocolChannelException: PRECONDITION_FAILED - delivery acknowledgement on channel 1 timed out. Timeout value used: 1800000 ms.
  3. PhpAmqpLib\Exception\AMQPTimeoutException: The connection timed out after 3 sec while awaiting incoming data.

Queue Config:

'rabbitmq' => [
    'driver' => 'rabbitmq',
    'queue'  => env('RABBITMQ_QUEUE', 'default'),
    'hosts' => [
        [
            'host'     => env('RABBITMQ_HOST', '127.0.0.1'),
            'port'     => env('RABBITMQ_PORT', 5672),
            'user'     => env('RABBITMQ_USER', 'guest'),
            'password' => env('RABBITMQ_PASSWORD', 'guest'),
            'vhost'    => env('RABBITMQ_VHOST', '/'),
        ],
    ],
    'options' => [
        'queue' => [
            'job' => RabbitMQJob::class,
        ],
    ],
    'connection'   => RabbitMQConnection::class,
    /*
     * Set to "horizon" if you wish to use Laravel Horizon.
     */
    'worker'       => RabbitMQQueue::class,
    'after_commit' => true,
],

The content of the RabbitMQQueue:

<?php

declare(strict_types=1);

namespace App\Libraries\Queue;

use PhpAmqpLib\Channel\AMQPChannel;
use Throwable;
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue as BaseRabbitMQQueue;

use function logger;

class RabbitMQQueue extends BaseRabbitMQQueue
{
    protected function publishBasic($msg, $exchange = '', $destination = '', $mandatory = false, $immediate = false, $ticket = null): void
    {
        try {
            parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);
        } catch (Throwable $throwable) {
            logger()->channel('queue')->warning('publishBasic: Exception occurred: ' . $throwable->getMessage() . '. Try to reconnect..');
            $this->reconnect();

            parent::publishBasic($msg, $exchange, $destination, $mandatory, $immediate, $ticket);
        }
    }

    protected function publishBatch($jobs, $data = '', $queue = null): void
    {
        try {
            parent::publishBatch($jobs, $data, $queue);
        } catch (Throwable $throwable) {
            logger()->channel('queue')->warning('publishBatch: Exception occurred: ' . $throwable->getMessage() . '. Try to reconnect..');
            $this->reconnect();

            parent::publishBatch($jobs, $data, $queue);
        }
    }

    protected function createChannel(): AMQPChannel
    {
        try {
            return parent::createChannel();
        } catch (Throwable $throwable) {
            logger()->channel('queue')->warning('createChannel: Exception occurred: ' . $throwable->getMessage() . '. Try to reconnect..');
            $this->reconnect();

            return parent::createChannel();
        }
    }
}

My current understanding of RabbitMQ is insufficient to determine the appropriate direction for further investigation.

@johnabil
Copy link

johnabil commented Jun 2, 2025

@akalongman i think this issue because your --max-time try removing it

@Xfaider48
Copy link

@akalongman First of all try to stop using queue:work and try to use rabbitmq:consume instead. And yes, you will have to create 3 workers (one per queue)

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

4 participants