使用Docker-Compose搭建Rabbitmq集群

1.使用镜像搭建集群,docker-compose.xml配置见下面的github具体配置

https://github.com/bijukunjummen/docker-rabbitmq-cluster

2.如果需要跨服务器,参考

https://www.cnblogs.com/cheyunhua/p/8362200.html

具体变更如下:

说完端口,下面提供一个三节点的docker-compose文件。

rabbit1(10.106.136.7)

 

1

2

3

4

5

6

7

8

9

10

11

12

rabbit1:

  image: bijukunjummen/rabbitmq-server

  hostname: rabbit1

  ports:

    - "5672:5672"

    - "4369:4369"

    - "1883:1883"

    - "15672:15672"

    - "25672:25672"

  environment:

    - RABBITMQ_DEFAULT_USER=myuser

    - RABBITMQ_DEFAULT_PASS=mypass

rabbit2(10.106.136.8)

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

rabbit2:

  image: bijukunjummen/rabbitmq-server

  hostname: rabbit2

  extra_hosts:

    - "rabbit1:10.106.136.7"

  environment:

   - CLUSTERED=true

   - CLUSTER_WITH=rabbit1

   - RAM_NODE=true

  ports:

      - "5672:5672"

      - "4369:4369"

      - "1883:1883"

      - "15672:15672"

      - "25672:25672"

rabbit3(10.106.136.9)

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

rabbit3:

  image: bijukunjummen/rabbitmq-server

  hostname: rabbit3

  extra_hosts:

    - "rabbit1:10.106.136.7"

    - "rabbit2:10.106.136.8"

  environment:

   - CLUSTERED=true

   - CLUSTER_WITH=rabbit1

   - RAM_NODE=true

  ports:

        - "5672:5672"

        - "4369:4369"

        - "1883:1883"

        - "15672:15672"

        - "25672:25672"

好了,集群环境搭建好了,具体spring boot连接说明,POM文件增加


    org.springframework.boot
    spring-boot-starter-amqp

yml文件

rabbitmq:
  addresses: 192.168.30.45:5672,192.168.30.57:5672
  username: root
  password: 123456
  publisher-confirms: true
  publisher-returns: true
  listener:
    simple:
      acknowledge-mode: manual
      concurrency: 1
      max-concurrency: 10
      retry:
        enabled: true

你可能感兴趣的:(环境搭建)