rabbitmq docker安装和使用
安装
docker pull rabbitmq:management docker run -d -p 5672:5672 -p 15672:15672 docker.io/rabbitmq:management http://localhost:15672
默认账号guest/guest
使用
springboot中的配置
spring: rabbitmq: addresses: xx.xx.xx.xx connection-timeout: 15000 listener: simple: acknowledge-mode: manual concurrency: 2 max-concurrency: 4 retry: ####开启消费者重试 enabled: true ####最大重试次数(默认无数次) max-attempts: 3 ####重试间隔次数 initial-interval: 1000 prefetch: 4 password: guest publisher-returns: true template: mandatory: true username: guest virtual-host: / queue: test
这个参数若没有配置正确的话 就会报错
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - vhost xxx not found, class-id=10, method-id=40)
问题3
报错
Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'type' for exchange 'pay.notify.exchange' in vhost '/': received ''x-delayed-message'' but current is 'direct', class-id=40, method-id=10)
手动把这个删掉就行了 因为rabbitmq会自动创建该exchange 否则已经存在了 就会报错
问题4
没有配置延迟队列插件
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; protocol method: #method<connection.close>(reply-code=503, reply-text=COMMAND_INVALID - unknown exchange type 'x-delayed-message', class-id=40, method-id=10)
解决方法1:
a、下载插件
https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/v3.8.0/rabbitmq_delayed_message_exchange-3.8.0.ez
b、copy到docker中
docker cp rabbitmq_delayed_message_exchange-3.8.0.ez 6a56b1871ee3:/home
c、在docker中拷贝该插件到rabbitmq的插件库
在docker容器中,找到MQ插件的路径
我的是 /opt/rabbitmq/plugins , 放进去
d、在docker中启用该插件
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
即可 注意不要带上版本和.ez
e、确认该插件是否已安装
rabbitmq-plugins list
看插件列表中是否有该插件