RabbitMq使用总结

RabbitMq使用总结:

一: rabbitMq相关的介绍:

镇楼的官网:https://www.rabbitmq.com

https://www.cnblogs.com/xiangyuqi/p/8603993.html

概念介绍:https://www.jianshu.com/p/3ba4c1883c3d

RabbitMQ的基础介绍https://www.cnblogs.com/bigberg/p/8136201.html

RabbitMQ消息确认机制之Confirm模式总结:https://blog.csdn.net/Weixiaohuai/article/details/94961012

确认机制:https://my.oschina.net/u/1860901/blog/968273/print

Spring-rabbit 说明文档:https://my.oschina.net/u/1045177/blog/408656

RabbitMQ注解方式配置说明:https://blog.csdn.net/zh350229319/article/details/52230674/

二:项目使用总结,先来一个坑,测试环境没问题,到了线上出问题,报下面的错:

RabbitMQ异常注意 reply-code=404, reply-text=NOT_FOUND - no exchange 'topic' in vhost '/', class-id=50, method-id=

Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no queue 'album.free.topaid.transcode.success..queue' in vhost '/', class-id=50, method-id=20)

1.看到这个报错,第一想到的是,应该是queue没有创建,一般测试环境都是设置的默认自动创建,仿真和线上是运维人员创建,那就找运维人员确认下,是不是创建了,创建的类型对不对,对下queue的名称,type类型是fanout还是topic,确认几个属性,auto-declare="true" auto-delete="false" durable="true" exclusive="false"是否一致,一般auto-declare="true"是不配置的,其他是默认的,确认了这些都没问题,陷入坑里了,什么原因那;

2.会不会是创建好的queue被服务再次重申覆盖,或者声明的有问题;这时候想到declared-by="admin"这个属性,在有多个admin的情况下exchange以及queue都需要声明是哪个管理的,原因找到了,测试和仿真没有问题是因为这两个环境,多个admin地址都是同一个,线上却是多个,在有多个地址的时候,不能确认是哪个admin管理的。

3.可能报403,406,530等,这些可以根据报错直接看出问题,比如

530:connection error; protocol method: #method<connection.close>(reply-code=530, reply-text=NOT_ALLOWED - access to vhost '/' refused for user 'kumas', class-id=10, method-id=40)

说明:账户kumas没有对 “/” 的权限,在 mq 管理页面上添加权限即可

406:com.rabbitmq.client.AlreadyClosedException: channel is already closed due to channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'test_data' in vhost '/': received 'true' but current is 'false', class-id=50, method-id=10

翻译过来就是exchange的durable已经true了不能改为false。所以使用的时候要注意如果exchange和queue的durable已经定义好了是不能更改的。除非客户端删掉exchange,queue然后重新启动。

RabbitMQ Cluster 常见错误码原因与解决办法:https://www.jianshu.com/p/1c4c42ff5114

下面是一个服务里配置的2个mq地址:

application-rabbitmq-context-v2.xml:

<util:properties id="rabbitmq2" location="classpath:rabbitmq2.properties"/>

<rabbit:connection-factory id="rabbitConnectionFactoryV2"
                           host="#{rabbitmq2['rabbit.connect.host.v2']}" port="#{rabbitmq2['rabbit.connect.port.v2']}"
                           username="#{rabbitmq2['rabbit.connect.username.v2']}"
                           password="#{rabbitmq2['rabbit.connect.password.v2']}"/>
<rabbit:admin connection-factory="rabbitConnectionFactoryV2" id="rabbitAdmin2"/>

<rabbit:template id="rabbitTemplate2" connection-factory="rabbitConnectionFactoryV2"/>

<bean id="TransCodeSuccessV2Listener" class="com.ximalaya.album.free.topiad.listener.TransCodeV2SuccessListener"/>
<!--转码完成消息监听-->
<rabbit:queue id="transCodeSuccessV2Queue" name="#{rabbitmq2['album.free.topaid.queue']}" declared-by="rabbitAdmin2"/>
<rabbit:topic-exchange name="#{rabbitmq2['album.free.topaid.exchange']}" declared-by="rabbitAdmin2">
        <rabbit:exchange-arguments>
        </rabbit:exchange-arguments>
        <rabbit:bindings>
                <rabbit:binding queue="transCodeSuccessV2Queue" pattern="free_paid"/>
        </rabbit:bindings>
</rabbit:topic-exchange>

<rabbit:listener-container connection-factory="rabbitConnectionFactoryV2" acknowledge="auto">
        <rabbit:listener queues="transCodeSuccessV2Queue" ref="TransCodeSuccessV2Listener"/>
</rabbit:listener-container>

application-rabbitmq-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
       xmlns:rabbit="http://www.springframework.org/schema/rabbit"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                  http://www.springframework.org/schema/rabbit
                  http://www.springframework.org/schema/rabbit/spring-rabbit-1.3.xsd
                  http://www.springframework.org/schema/util
                  http://www.springframework.org/schema/util/spring-util-3.0.xsd"
       default-lazy-init="false">
<util:properties id="rabbitmq" location="classpath:rabbitmq.properties"/>

<rabbit:connection-factory id="rabbitConnectionFactory"
                           host="#{rabbitmq['rabbit.connect.host']}" port="#{rabbitmq['rabbit.connect.port']}"
                           username="#{rabbitmq['rabbit.connect.username']}"
                           password="#{rabbitmq['rabbit.connect.password']}"/>
<rabbit:admin connection-factory="rabbitConnectionFactory" id="admin"/>

<rabbit:template id="rabbitTemplate" connection-factory="rabbitConnectionFactory"/>

<!--转码消息发送-->
<rabbit:fanout-exchange name="#{rabbitmq['album.free.topaid.transcode.exchange']}" declared-by="admin">
</rabbit:fanout-exchange>

<bean id="auditApprovedListener" class="com.ximalaya.album.free.topiad.listener.AuditApprovedListener"/>
<!--审核通过消息监听-->
<rabbit:queue id="auditApprovedQueue" name="#{rabbitmq['album.free.topaid.approved.queue']}" declared-by="admin"/>
<rabbit:fanout-exchange name="#{rabbitmq['album.free.topaid.approved.exchange']}" declared-by="admin">
    <rabbit:bindings>
        <rabbit:binding queue="auditApprovedQueue"/>
    </rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:listener-container connection-factory="rabbitConnectionFactory" acknowledge="auto">
    <rabbit:listener queues="auditApprovedQueue" ref="auditApprovedListener"/>
</rabbit:listener-container>

<bean id="creationListener" class="com.ximalaya.album.free.topiad.listener.CreationListener"/>
<!--创建消息监听-->
<rabbit:queue id="createQueue" name="#{rabbitmq['album.free.topaid.create.queue']}" declared-by="admin"/>
<rabbit:fanout-exchange name="#{rabbitmq['album.free.topaid.create.exchange']}" declared-by="admin">
    <rabbit:bindings>
        <rabbit:binding queue="createQueue"/>
    </rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:listener-container connection-factory="rabbitConnectionFactory" acknowledge="auto">
    <rabbit:listener queues="createQueue" ref="creationListener"/>
</rabbit:listener-container>

<bean id="transCodeSuccessListener" class="com.ximalaya.album.free.topiad.listener.TransCodeSuccessListener"/>
<!--转码完成消息监听-->
<rabbit:queue id="transCodeSuccessQueue" name="#{rabbitmq['album.free.topaid.transcode.success.queue']}" declared-by="admin"/>
<rabbit:fanout-exchange name="#{rabbitmq['album.free.topaid.transcode.success.exchange']}"  declared-by="admin">
    <rabbit:bindings>
        <rabbit:binding queue="transCodeSuccessQueue"/>
    </rabbit:bindings>
</rabbit:fanout-exchange>
<rabbit:listener-container connection-factory="rabbitConnectionFactory" acknowledge="auto">
    <rabbit:listener queues="transCodeSuccessQueue" ref="transCodeSuccessListener"/>
</rabbit:listener-container>
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Ruoyi框架中,可以使用RabbitMQ作为消息队列服务。RabbitMQ在消息的发送、传输和接收过程中,可以保证消息成功发送不会丢失,并且能够确认被消费。它提供了消息的高可用性和消费确认功能。 然而,在实际应用中,如果配置和使用不当,可能会遇到一些问题。例如,发送出去的消息可能未能成功到达目的地,这可能是由于消息模型不存在的原因导致的(比如交换机、路由和队列绑定结构错误)。此外,如果RabbitMQ服务发生宕机或崩溃,还可能导致未被消费的消息在重启过程中丢失。另外,消费者在监听和处理消息时可能会出现失败或崩溃的情况,导致消息重新入队并被重复消费的问题。 在Ruoyi中,可以使用RabbitReceiverService类来监听订单消息。这个类使用@RabbitListener注解来指定监听的队列,并在方法中处理接收到的消息。在具体的实现中,可以根据消息的内容执行相应的业务逻辑。例如,在监听到用户秒杀成功后超时未支付的消息时,可以根据消息中的信息更新数据库中的订单状态。 总结来说,Ruoyi框架可以使用RabbitMQ作为消息队列服务,并通过监听器来接收和处理消息。这个功能可以用于实现一些异步处理或解耦的需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Spring Boot 整合RabbitMQ](https://blog.csdn.net/qq_38828776/article/details/103971951)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [RabbitMQ死信队列处理超时未支付的订单](https://blog.csdn.net/weixin_38982591/article/details/111404721)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值