Overview
Today I would like to share with you the following three parts:
- Docker install RabbitMQ
- Spring Boot and RabbitMQ demo
- RabbitMQ delay queue
Docker install RabbitMQ
Step 1: Pull the image
docker pull rabbitmq:management
Step 2: Start
docker run -d \
--name rabbitmq \
-p 5672:5672 \
-p 15672:15672 \
-v /data/rabbitmq:/var/lib/rabbitmq \
--hostname myRabbit \
-e RABBITMQ_DEFAULT_VHOST=my_vhost \
-e RABBITMQ_DEFAULT_USER=admin \
-e RABBITMQ_DEFAULT_PASS=admin \
rabbitmq:management
illustrate:
-d run the container in the background;
--name specifies the container name;
-p specifies the port on which the service runs (5672: application access port; 15672: console web port number);
-v map directory or file;
--hostname hostname (an important note of RabbitMQ is that it stores data based on the so-called "nodename", which defaults to the hostname);
-e specifies environment variables; (RABBITMQ_DEFAULT_VHOST: default virtual machine name; RABBITMQ_DEFAULT_USER: default user name; RABBITMQ_DEFAULT_PASS: default user name password)
Spring Boot and RabbitMQ demo
rely
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
configure
spring:
rabbitmq:
host: localhost
port: 5672
username: admin
password: admin
virtual-host: my_vhost
configure
send
take over
test
GET http://localhost:8080/sendMsg?key=item.test&msg=Hello
RabbitMQ delay queue
First look at a mistake:
channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no
The reason is that the delay queue is a plugin of RabbitMQ, which is not installed by default and needs to be installed.
Related Links:
- RabbitMQ plugin: https://www.rabbitmq.com/community-plugins.html
- Delayed plugin: https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases
Install the plugin:
- 1. Download the delay queue plugin
- 2. Copy the plugin to the /plugins directory of RabbitMQ. Copy method: docker cp rabbitmq_delayed_message_exchange-3.10.2.ez containerId:/plugins
- 3. Execute, execute in the /plugins directory: rabbitmq-plugins enable rabbitmq_delayed_message_exchange
- 4. Restart RabbitMQ
Configuration:
send
Receive message:
test:
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。