Giter Club home page Giter Club logo

dockerized-rabbitmq-php's Introduction

User Guide: Dockerized RabbitMQ Environment with PHP

Table of Contents

  1. Configuration
  2. Configuration of RabbitmqService.php
  3. Publish a Message
  4. Consume a Message

1. Installation

Edit Docker Compose File

Open the docker-compose.yml file and set the desired PHP version and other configurations.

Build Docker Image

Build the Docker image using the following command:

docker compose build

Run Docker Containers

Start the Docker containers using the following command:

docker compose up -d

Check Container Status

Check the status of the running containers using the following command:

docker compose ps

2. Configuration of RabbitmqService.php

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);

3. Publish a Message

Use the following PHP script to publish a message to RabbitMQ:

$mq = new RabbitmqService();

$mq->queue("queue_name")
    ->publish("Hello World!");

4. Consume a Message

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);
    });

5. Browse RabbitMQ Management

http://localhost:15672

or

{Containter_IP}:15672

dockerized-rabbitmq-php's People

Contributors

souravmsh avatar

Stargazers

Mohammad Shah Alam avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.