Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Help for Laravel / Sail / RabbitMQ - Unable to connect to tcp://localhost:5672

Hello,

I'm trying to use Laravel with Sail and RabbitMQ.

I'm using this package.

vladimir-yuldashev/laravel-queue-rabbitmq

I have configured the .env file correctly with the queue connection with rabbitmq and the credentials like this.

'rabbitmq' => [
    'driver' => 'rabbitmq',
    // 'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
    // 'queue' => env('RABBITMQ_QUEUE', 'default'),
    'hosts' => [
        [
            'user' => env('RABBITMQ_USER', 'guest'),
            'password' => env('RABBITMQ_PASSWORD', 'guest'),
            'host' => env('RABBITMQ_HOST', '127.0.0.1'),
            'port' => env('RABBITMQ_PORT', 5672),
            'vhost' => env('RABBITMQ_VHOST', '/'),
        ],
    ],
    'options' => [
        'queue' => [
            // 'job' => VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob::class,
        ],
    ],
],

I have created a job and dispatched it.

I get this error message.

"message": "stream_socket_client(): Unable to connect to tcp://localhost:5672 (Cannot assign requested address)",

All works fine except dispatching the job to RabbitMQ.

What do you suggest me to look at ?

Thanks for your help.

V

0 likes
1 reply
vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

This was exactly the problem.

Host Configuration: Since you're using Docker, localhost might not point to the host you expect. If RabbitMQ is running as a separate service within Docker, you should use the service name defined in docker-compose.yml as the host instead of localhost or 127.0.0.1.

I have set the host to the rabbitmq placeholder instead of localhost and it works fine now.

1 like

Please or to participate in this conversation.