1024programmer Asp.Net Some experiences and pitfall records of using Docker Compose to deploy RabbitMQ

Some experiences and pitfall records of using Docker Compose to deploy RabbitMQ

Some experiences and pitfall records of using Docker Compose to deploy RabbitMQ

Some experiences and pitfall records of using Docker Compose to deploy RabbitMQ
Preface: Mature features, stable message persistence, flexible message routing, high performance, high availability, and high scalability. Support plug-in system: RabbitMQ has a rich plug-in system, and its functions can be expanded by installing plug-ins, such as management interface, message tracking, message tracking, etc. conversion etc.

Foreword

RabbitMQ is a powerful open source message queuing system that implements efficient message communication and asynchronous processing.

This article mainly introduces its deployment and installation based on Docker-Compose and some experience in use.

Features

  • Mature and stable
  • Message persistence
  • Flexible message routing
  • High performance, high availability, high scalability
  • Support plug-in system: RabbitMQ has a rich plug-in system, and its functions can be expanded by installing plug-ins, such as management interface, message tracking, message conversion, etc.
  • Officially provides .NET/Java SDK

usage

  • Used in the project for logging, message sending, data synchronization, etc., stable and reliable
  • Initialization of business modules, asynchronous processing of data import
  • Do idempotent processing and use different confirmation methods in different scenarios to prevent repeated consumption of messages
  • RabbitMQ does not support delayed messages by default. You can use the delayed message plug-in to implement it (Limited, only supports delayed messages up to one or two days)
  • Use .NET SDK: RabbitMQ.Client, and I will share the secondary encapsulation usage later

Practice

Use Docker Compose V2 to install rabbitmq v3.12.6

Preparation

  • Current version: v3.12.6
  • Use mirror: rabbitmq:3.12.6-management (with web management interface)
  • Default port: 5672: application connection port 15672: web console

Install using Docker Compose

This article is based on Docker V24 and Docker Compose V2. For installation, please refer to previous articles

Configuration instructions

  • Fixed the image version: rabbitmq:3.12.6-management
  • Specified host name: rabbitserver
  • Specify the virtual machine name: admin_vhost
  • Specify account password: root devops666
  • Specified port: 5672: application connection port 15672: web management interface
  • Mount data directory: ./data:/var/lib/rabbitmq
  • Mount additional plug-in directories: ./myplugins:/myplugins The default plug-in directory in the RabbitMQ container is /plugins and mounting is not recommended
  • Mount ./myplugins into the container and add it to the directory where plugins are searched: RABBITMQ_PLUGINS_DIR: '/plugins:/myplugins'
  • Specify the network: devopsnetwork (docker network create devopsnetwork)

Configuration file compose.yml

  • Get ready to copy compose.yml to the server

  • Then run docker compose up -d

     version: '3.1'
      services:
        rabbitmq:
          image: rabbitmq:3.12.6-management
          container_name: rabbitmq_3_12
          restart: always
          # Node name rabbit@rabbitserver, otherwise the container ID will be used
          hostname: rabbitserver
          environment:
            #Default virtual machine name
            RABBITMQ_DEFAULT_VHOST: admin_vhost
            # username
            RABBITMQ_DEFAULT_USER: root
            # password
            RABBITMQ_DEFAULT_PASS: devops666
            #Specify custom plug-in directory
            RABBITMQ_PLUGINS_DIR: '/plugins:/myplugins'
          ports:
            - "5672:5672"
            - "15672:15672"
          volumes:
            - ./data:/var/lib/rabbitmq
            - ./myplugins:/myplugins
          networks:
            -devopsnetwork
    
      networks:
        devopsnetwork:
          external: true
      ```
    
     

Deployment successful

Deployment machine IP: 192.168.123.214

Install plug-in: delayed message plug-in

Note: Plug-in message publishing delay only supports seconds, minutes or hours, up to one or two days, please note! ! !

Original text: This plugin was designed for delaying message publishing for a number of seconds, minutes, or hours. A day or two at most.

! ! ! The previous compose.yml defaults to . /myplugins is mounted to the container and multiple plug-in directories are specified. System: /plugins. Add it yourself: /myplugins optimizes the process. Installing plug-ins does not require copying files and restarting the container

  1. You need to download the plug-in first: rabbitmq_delayed_message_exchange-3.12.0.ez, and download the corresponding version. ez file: Github Releases

  2. Put the downloaded plug-in file into . /myplugins folder Myplugins was mounted to the container earlier

  3. Connect the container to execute the enable plug-in: docker exec -it rabbitmq_3_12 /bin/bash -c "rabbitmq-plugins enable rabbitmq_delayed_message_exchange"

  4. Because myplugins has been mounted and set as the plug-in directory, you will find the ez files corresponding to /plugins and /myplugins for installation

  5. Activation successful, can be viewed on the Exchanges page

The pit that has been stepped on

  • According to the above configuration, the following problems will no longer occur. If you encounter the same problem, you can refer to it

  • Delayed messages only support delayed messages of up to one or two days. The project has a function of sending messages regularly. If the appropriate time setting exceeds the threshold, it cannot be consumed. Note

  • Do not mount the /plugins plug-in directory. You can use RABBITMQ_PLUGINS_DIR: '/plugins:/myplugins' to specify multiple directories, so you only need to execute the document

  • If hostname is not specified, the node name will be the container ID

  • Using the rabbitmq:3.x-management image (with the function of web management page) but mounting an empty plug-in directory will result in an error: {"init terminating in do_boot",{undef,[{rabbit, boot,[],[]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}

  • The Admin page prompts an error: Upgrade the version issues. I started using 3.9.29-management (the tags list is sorted with 3.9 at the front, (╯□╰)), and reported this error

  • You need to go through it before switching versions. /data data is cleared, otherwise it cannot be started

  • Exchanges page error: I changed the version to 3.12.6-management and reported this error. I didn’t log out. I just needed Ctrl+F5 and logged in again

use

.NET SDK

Official: RabbitMQ.Client

Connection configuration

var factory = new ConnectionFactory
 {
     HostName = "192.168.123.214",
     Port = 5672,
     VirtualHost = "admin_vhost",
     UserName = "root",
     Password = "devops666",
 };
 

Demo example

I built a demo to test and use the Demo address. I will expand on how to encapsulate and use it during the subsequent secondary encapsulation

  • RabbitMQ project repository
  • DockerHub Image
  • Official Documents
  • Delay message plug-in download
  • .NET SDK repository

后语

The installation is relatively simple, choose the right version, and more importantly, you need to choose the appropriate solution according to the business when using it

The installation of the plug-in took a while, and the process was optimized after research

Author: Yi Mo

Github:yimogit

Pure static tool site: metools

Note: Welcome to make bricks, please point out any shortcomings;

Confusion is probably because you think too much and do too little.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/some-experiences-and-pitfall-records-of-using-docker-compose-to-deploy-rabbitmq/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索