Open the docker-compose.yml
file and set the desired PHP version and other configurations.
Build the Docker image using the following command:
docker compose build
Start the Docker containers using the following command:
docker compose up -d
Check the status of the running containers using the following command:
docker compose ps
Run the following command to inspect the Docker container and copy the IPAddress from the output:
docker inspect <container-name>
Open the RabbitmqService.php
file and configure the RabbitMQ service credentials:
// Use the IPAddress obtained from Docker inspect
private array $config = [
'host' => '127.0.0.1',
'port' => 5672,
'user' => 'guest',
'pass' => 'guest',
];
or
// Use the IPAddress obtained from Docker inspect
$config = [
'host' => '172.21.0.2',
'port' => 5672,
'user' => 'admin',
'pass' => 'admin'
];
new RabbitmqService($config);
Use the following PHP script to publish a message to RabbitMQ:
$mq = new RabbitmqService();
$mq->queue("queue_name")
->publish("Hello World!");
Use the following PHP script to consume messages from RabbitMQ:
$mq = new RabbitmqService();
$mq->queue("queue_name")
->consume(function($msg) {
$str = date('Y-m-d H:i:s') . " | " . $msg->getBody(). "\n";
// Print the message
echo $str;
// Create a log
file_put_contents("./temp/log.txt", $str, FILE_APPEND);
});
http://localhost:15672
or
{Containter_IP}:15672