pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

rabbitmq 和 spring-rabbitmq 中的 DLX - 拒絕消息的一些

DLX in rabbitmq and spring-rabbitmq - some considerations of rejecting messages(rabbitmq 和 spring-rabbitmq 中的 DLX - 拒絕消息的一些注意事項)
本文介紹了rabbitmq 和 spring-rabbitmq 中的 DLX - 拒絕消息的一些注意事項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我確實閱讀了此參考:https://www.rabbitmq.com/dlx.html,但它并沒有解決我的疑問,即:
如果接受消息沒有問題 - spring-rabbitmq 發送確認并且一切都很好,DLX 不知道確認的消息.

I did read this reference: https://www.rabbitmq.com/dlx.html, however it doesn't resolve my doubts, namely:
In case of accepting message there is no problem - spring-rabbitmq send ack and everthing is fine, DLX doesn't know about acked message.

問題是如果拒絕回答,即拋出 MessageConverterException 怎么辦?此消息已刪除或移至 DLX?

The problem is in case rejecting answer, namely what about throwing MessageConverterException ? This message is removed or moved to DLX?

如果有其他異常怎么辦?例如 Exception ?它被刪除/重新排隊/移動到 DLX ?

And what about in case other exception ? For example Exception ? It is removed/requeued/moved to DLX ?

@Gary 回答后編輯
我認為,在回答@Gary 之后,我應該添加更多關于我的案例的詳細信息以及@Gary 回答的一些摘要.@Gary 完全掌握了我的用例.

Edit after answer of @Gary
I think, that after answer's @Gary I should add more details about my case and some summary of @Gary's answer. @Gary exactly grasped my use case.

我不喜歡重新排隊 - 從不(我害怕循環),但我不希望在拋出異常時丟失消息(例如失去與數據庫的連接) - 此消息應該重新發送到 DLX.另一方面,消息的轉換應該被視為致命錯誤 - 沒有重新排隊,沒有重新發送到 DLX - 只是永久刪除消息.通常,取決于異常拒絕(=重新發送到 DLX,如果已配置)或接受,從不重新排隊.

I wouldn't like requeue - never (I am afraid of looping), but I wouldn't like to lose messages when an exception was thrown (for example lost connection to database) - this message should be resend to DLX. On the other hand, conversion of message should be treated as fatal error - no requeue, no resend to DLX - simply permanent removing message. Generally, in depends on exception either reject (=resend to DLX if configured) or accept, never requeue.

簡而言之,@Gary 提出的方法.
首先:我們可以重寫ExceptionHandler來管理發送nack/ack,這給了我們一個完全的控制權.
第二:IMO更簡單,解決方案是設置defaultRequeueRejected=false并在轉換器中拋出ImmediateAcknowledgeAmqpException.它使 RabbitMQ 認為答案已被接受(與第一個解決方案的情況相同),而且不會調用偵聽器.<代碼>**結論**:使用
ImmediateAcknowledgeAmqpExceptionExceptionHandler`異常,我們可以完全控制永久拒絕消息(在后臺確認)并重新發送到DLX.

To sum up in a nutshell approach proposed by @Gary.
First: We can override ExceptionHandler to manage of sending nack/ack, which gives to us a full control.
Second: IMO simpler, solution is to set defaultRequeueRejected=false and in converter throw ImmediateAcknowledgeAmqpException. It makes that RabbitMQ think that answer was accepted (the same thing as in case of first solution), moreover listener wouldn't be invoked. **Conclusion**: UsingImmediateAcknowledgeAmqpExceptionorExceptionHandler` exception we have a full control on permanent rejecting message (under hood ack) and resending to DLX.

推薦答案

RabbitMQ 對異常一無所知.

RabbitMQ knows nothing about the exceptions.

當容器捕獲到異常時,它會調用 channel.basicReject(deliveryTag, requeue).

When the container catches an exception it calls channel.basicReject(deliveryTag, requeue).

如果 requeue 為真,則消息被重新排隊.

If requeue is true, the message is requeued.

默認情況下,對于那些提到的以外的任何異常 這里

By default, for any exception other than those mentioned here

o.s.amqp...MessageConversionException

o.s.amqp...MessageConversionException

o.s.messaging...MessageConversionException

o.s.messaging...MessageConversionException

o.s.messaging...MethodArgumentNotValidException

o.s.messaging...MethodArgumentNotValidException

o.s.messaging...MethodArgumentTypeMismatchException

o.s.messaging...MethodArgumentTypeMismatchException

java.lang.NoSuchMethodException

java.lang.NoSuchMethodException

java.lang.ClassCastException

java.lang.ClassCastException

requeue 設置為 true,因此消息被重新排隊.

requeue is set to true, so the message is requeued.

對于那些例外,傳遞被認為是致命的并且消息不會重新排隊,如果配置了一個,它將轉到 DLX/DLQ.

For those exceptions, the delivery is considered fatal and the message is NOT requeued, it will go to a DLX/DLQ if one is configured.

容器有一個標志defaultRequeueRejected,默認為true;如果您將其設置為 false;不會重新排隊任何異常.

The container has a flag defaultRequeueRejected which is true by default; if you set it to false; no exceptions will be requeued.

對于應用程序級別的異常,通常會重新排隊消息.要動態拒絕(而不是重新排隊)消息,請確保原因鏈中存在 AmqpRejectAndDontRequeueException.這指示容器不要重新排隊消息,它將轉到 DLX/DLQ(如果已配置).此行為由上面提到的 defaultRequeueRejected 標志啟用.

For application-level exceptions, generally, messages will be requeued. To dynamically reject (and not requeue) a message, make sure there is an AmqpRejectAndDontRequeueException in the cause chain. This instructs the container to not requeue the message, and it will go to the DLX/DLQ (if configured). This behavior is enabled by the defaultRequeueRejected flag mentioned above.

這一切都在文檔中進行了解釋,正如我在其他答案中所討論的那樣,您可以使用自定義錯誤處理程序來更改此行為;文檔中也對此進行了說明.

This is all explained in the documentation and, as I have discussed in other answers to you, you can change this behavior by using a custom error handler; that, too, is explained in the documentation.

無法將某些異常發送到 DLX/DLQ 而不是其他;rabbit 只有一個二元選項,requeue 或 don't requeue,對于后者,如果配置了 DLX/DLQ,所有此類被拒絕的消息都會轉到 DLX/DLQ.

It is not possible to send some exceptions to the DLX/DLQ and not others; rabbit only has a binary option, requeue or don't requeue and, for the latter, if a DLX/DLQ is configured all such rejected messages go to the DLX/DLQ.

Spring AMQP 提供了另一種異常,ImmediateAcknowledgeAmqpException.如果您的偵聽器拋出此異常,則消息將被確認,就好像它已成功處理一樣 (channel.basicAck()).這是容器提供的唯一技術,可以丟棄壞消息而不將其發送到 DLX/DLQ.

Spring AMQP provides one more exception, ImmediateAcknowledgeAmqpException. If your listener throws this exception, the message will be ack'd as if it was processed successfully (channel.basicAck()). That is the only technique provided by the container, to discard a bad message without sending it to the DLX/DLQ.

當然,您的應用程序本身可以丟棄此類消息.

Of course, your application can drop such messsages itself.

如果要DLX/DLQ所有業務異常但丟棄轉換異常,拋出AmqpRejectAndDontRequeueException(或設置defaultRequeueRejected為false),并拋出ImmediateAcknowledgeAmqpException來自您的轉換器.

If you want to DLX/DLQ all business exceptions but drop conversion exceptions, throw AmqpRejectAndDontRequeueException (or set defaultRequeueRejected to false), and throw ImmediateAcknowledgeAmqpException from your converter.

這篇關于rabbitmq 和 spring-rabbitmq 中的 DLX - 拒絕消息的一些注意事項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 聚丙烯酰胺PAM-聚合氯化铝PAC-絮凝剂-河南博旭环保科技有限公司 巨野电机维修-水泵维修-巨野县飞宇机电维修有限公司 | 贵州自考_贵州自学考试网| 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 彩超机-黑白B超机-便携兽用B超机-多普勒彩超机价格「大为彩超」厂家 | 济南品牌设计-济南品牌策划-即合品牌策划设计-山东即合官网 | 超声波清洗机_细胞破碎仪_实验室超声仪器_恒温水浴-广东洁盟深那仪器 | EFM 022静电场测试仪-套帽式风量计-静电平板监测器-上海民仪电子有限公司 | 层流手术室净化装修-检验科ICU改造施工-华锐净化工程-特殊科室建设厂家 | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | 深圳货架厂家_金丽声精品货架_广东金丽声展示设备有限公司官网 | 北京乾茂兴业科技发展有限公司| 回转窑-水泥|石灰|冶金-巩义市瑞光金属制品有限责任公司 | 深圳公司注册-工商注册代理-注册公司流程和费用_护航财税 | 模温机-油温机-电加热导热油炉-工业冷水机「欧诺智能」 | PVC地板|PVC塑胶地板|PVC地板厂家|地板胶|防静电地板-无锡腾方装饰材料有限公司-咨询热线:4008-798-128 | 办公室家具_板式办公家具定制厂家-FMARTS福玛仕办公家具 | 船用泵,船用离心泵,船用喷射泵,泰州隆华船舶设备有限公司 | 华溶溶出仪-Memmert稳定箱-上海协烁仪器科技有限公司 | 深圳工程师职称评定条件及流程_深圳职称评审_职称评审-职称网 | 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 捆扎机_气动捆扎机_钢带捆扎机-沈阳海鹞气动钢带捆扎机公司 | 自动检重秤-动态称重机-重量分选秤-苏州金钻称重设备系统开发有限公司 | 压砖机_电动螺旋压力机_粉末成型压力机_郑州华隆机械tel_0371-60121717 | 分轨 | 上传文件,即刻分离人声和伴奏 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 焊锡丝|焊锡条|无铅锡条|无铅锡丝|无铅焊锡线|低温锡膏-深圳市川崎锡业科技有限公司 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 厚壁钢管-厚壁无缝钢管-小口径厚壁钢管-大口径厚壁钢管 - 聊城宽达钢管有限公司 | 999范文网_优质范文下载写作帮手 | 包头市鑫枫装饰有限公司| 桨叶搅拌机_螺旋挤压/方盒旋切造粒机厂家-无锡市鸿诚输送机械有限公司 | 天津暖气片厂家_钢制散热器_天津铜铝复合暖气片_维尼罗散热器 | H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | 【同风运车官网】一站式汽车托运服务平台,验车满意再付款 | 雷达液位计_超声波风速风向仪_雨量传感器_辐射传感器-山东风途物联网 | 空气能暖气片,暖气片厂家,山东暖气片,临沂暖气片-临沂永超暖通设备有限公司 | 申江储气罐厂家,储气罐批发价格,储气罐规格-上海申江压力容器有限公司(厂) | PAS糖原染色-CBA流式多因子-明胶酶谱MMP-上海研谨生物科技有限公司 | 电动卫生级调节阀,电动防爆球阀,电动软密封蝶阀,气动高压球阀,气动对夹蝶阀,气动V型调节球阀-上海川沪阀门有限公司 |