I am having a problem with how to use the following rabbit environment configuration.
rabbit_mq:
image: rabbitmq:3-management-alpine
container_name: 'rabbitmq'
hostname: rabbitmq
ports:
- 5672:5672
- 15672:15672
volumes:
- ./docker/rabbitmq/data/:/var/lib/rabbitmq/
- ./docker/rabbitmq/log/:/var/log/rabbitmq
- ./docker/rabbitmq/conf/:/var/conf/rabbitmq
environment:
#(I comment this now but before I used this)
# RABBITMQ_HOST: rabbitmq
# RABBITMQ_PORT: 15672
# RABBITMQ_VHOST: /
RABBITMQ_DEFAULT_USER: guest
#(I also tried to use RABBITMQ_USER)
RABBITMQ_DEFAULT_PASS: guest
#(and I also tried to use RABBITMQ_PASS & RABBITMQ_PASSWORD)
I need to use environment configuration to connect to the server. There is my PHP code:
$connection = new AMQPStreamConnection($_ENV['RABBITMQ_HOST'], $_ENV['RABBITMQ_PORT'], $_ENV['RABBITMQ_DEFAULT_USER'], $_ENV['RABBITMQ_DEFAULT_PASS']);
I tried a lot of things, for example, I created a rabbitmq.env
file, and write the config down there, but it's not working
Also, there is an error-
Fatal error: Uncaught PhpAmqpLib\Exception\AMQPIOException: stream_socket_client(): unable to connect to tcp://: (Failed to parse address ":") in /app/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:108
How to resolve this issue?
Okey, there is the answer: i had to write this config in php container, not in rabbitmq container, so there is the docker-compose code:
And also add .env file in the root directoria:
My PHP code: