blob: bc8ca61582a02e98cc7749282ffb836e8e678d8f [file] [log] [blame]
<!doctype html>
<html lang="zh" dir="ltr" class="docs-wrapper docs-doc-page docs-version-5.0 plugin-docs plugin-id-default docs-doc-id-featureBehavior/05sendretrypolicy" data-has-hydrated="false">
<head>
<meta charset="UTF-8">
<meta name="generator" content="Docusaurus v2.4.3">
<title data-rh="true">消息发送重试和流控机制 | RocketMQ</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://your-docusaurus-test-site.com/zh/docs/featureBehavior/05sendretrypolicy"><meta data-rh="true" name="docusaurus_locale" content="zh"><meta data-rh="true" name="docsearch:language" content="zh"><meta data-rh="true" name="docusaurus_version" content="5.0"><meta data-rh="true" name="docusaurus_tag" content="docs-default-5.0"><meta data-rh="true" name="docsearch:version" content="5.0"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-5.0"><meta data-rh="true" property="og:title" content="消息发送重试和流控机制 | RocketMQ"><meta data-rh="true" name="description" content="本文为您介绍 Apache RocketMQ 的消息发送重试机制和消息流控机制。"><meta data-rh="true" property="og:description" content="本文为您介绍 Apache RocketMQ 的消息发送重试机制和消息流控机制。"><link data-rh="true" rel="icon" href="/zh/img/favicon.ico"><link data-rh="true" rel="canonical" href="https://your-docusaurus-test-site.com/zh/docs/featureBehavior/05sendretrypolicy"><link data-rh="true" rel="alternate" href="https://your-docusaurus-test-site.com/zh/docs/featureBehavior/05sendretrypolicy" hreflang="zh"><link data-rh="true" rel="alternate" href="https://your-docusaurus-test-site.com/docs/featureBehavior/05sendretrypolicy" hreflang="en"><link data-rh="true" rel="alternate" href="https://your-docusaurus-test-site.com/docs/featureBehavior/05sendretrypolicy" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://R2IYF7ETH7-dsn.algolia.net" crossorigin="anonymous"><link rel="alternate" type="application/rss+xml" href="/zh/blog/rss.xml" title="RocketMQ RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/zh/blog/atom.xml" title="RocketMQ Atom Feed">
<link rel="search" type="application/opensearchdescription+xml" title="RocketMQ" href="/zh/opensearch.xml">
<script>var _hmt=_hmt||[];!function(){var e=document.createElement("script");e.src="https://hm.baidu.com/hm.js?36428f2b841d08e7405724cbf7f860d2";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)}()</script>
<link rel="preconnect" href="https://www.google-analytics.com">
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-89603173-1","auto"),ga("set","anonymizeIp",!0),ga("send","pageview")</script>
<script async src="https://www.google-analytics.com/analytics.js"></script>
<link rel="alternate" type="application/rss+xml" href="/zh/events/rss.xml" title="RocketMQ RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/zh/events/atom.xml" title="RocketMQ Atom Feed">
<link rel="alternate" type="application/rss+xml" href="/zh/release-notes/rss.xml" title="RocketMQ RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/zh/release-notes/atom.xml" title="RocketMQ Atom Feed">
<link rel="alternate" type="application/rss+xml" href="/zh/news/rss.xml" title="RocketMQ RSS Feed">
<link rel="alternate" type="application/atom+xml" href="/zh/news/atom.xml" title="RocketMQ Atom Feed">
<link rel="stylesheet" href="//g.alicdn.com/mamba/assets/0.0.13/mse-arc-ui.min.css">
<script src="//g.alicdn.com/mamba/assets/0.0.13/mse-arc-ui.min.js"></script><link rel="stylesheet" href="/zh/assets/css/styles.d2e5c25b.css">
<link rel="preload" href="/zh/assets/js/runtime~main.b17b65ca.js" as="script">
<link rel="preload" href="/zh/assets/js/main.46e74ac2.js" as="script">
</head>
<body class="navigation-with-keyboard">
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
<div role="region" aria-label="跳到主要内容"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">跳到主要内容</a></div><nav aria-label="主导航" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="切换导航栏" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/zh/"><div class="navbar__logo"><img src="/zh/img/Apache_RocketMQ_logo.svg.png" alt="My Site Logo" class="themedImage_ToTc themedImage--light_HNdA"><img src="/zh/img/Apache_RocketMQ_logo.svg.png" alt="My Site Logo" class="themedImage_ToTc themedImage--dark_i4oU"></div><b class="navbar__title text--truncate">Apache RocketMQ</b></a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/apache/rocketmq" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" class="iconLanguage_nlXk"><path fill="currentColor" d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"></path></svg>简体中文</a><ul class="dropdown__menu"><li><a href="/zh/docs/featureBehavior/05sendretrypolicy" target="_self" rel="noopener noreferrer" class="dropdown__link dropdown__link--active" lang="zh">简体中文</a></li><li><a href="/docs/featureBehavior/05sendretrypolicy" target="_self" rel="noopener noreferrer" class="dropdown__link" lang="en">English</a></li></ul></div><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link">文档</a><ul class="dropdown__menu"><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/zh/docs/">5.0</a></li><li><a class="dropdown__link" href="/zh/docs/4.x/">4.x</a></li></ul></div><a class="navbar__item navbar__link" href="/zh/download">下载</a><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link">博客</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/zh/blog">用户案例</a></li><li><a class="dropdown__link" href="/zh/events">社区活动</a></li><li><a class="dropdown__link" href="/zh/release-notes">版本变化</a></li><li><a class="dropdown__link" href="/zh/news">RocketMQ新闻</a></li></ul></div><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link">社区</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/zh/contact">参与社区</a></li><li><a class="dropdown__link" href="/zh/origin">项目起源</a></li><li><a class="dropdown__link" href="/zh/team">贡献团队</a></li><li><a class="dropdown__link" href="/zh/docs/contributionGuide/01how-to-contribute">贡献说明</a></li><li><a class="dropdown__link" href="/zh/enterprise">企业用户</a></li></ul></div><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="切换浅色/暗黑模式(当前为浅色模式)" aria-label="切换浅色/暗黑模式(当前为浅色模式)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="搜索"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20" aria-hidden="true"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">搜索</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0 docsWrapper_BCFX"><button aria-label="回到顶部" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docPage__5DB"><aside class="theme-doc-sidebar-container docSidebarContainer_b6E3"><div class="sidebarViewport_Xe31"><div class="sidebar_njMd"><nav aria-label="文档侧边栏" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/">基本概念</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/quickStart/01quickstart">快速开始</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/domainModel/01main">领域模型</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" aria-expanded="true" href="/zh/docs/featureBehavior/01normalmessage">功能特性</a></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/01normalmessage">普通消息</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/02delaymessage">定时/延时消息</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/03fifomessage">顺序消息</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/04transactionmessage">事务消息</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link menu__link--active" aria-current="page" tabindex="0" href="/zh/docs/featureBehavior/05sendretrypolicy">消息发送重试和流控机制</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/06consumertype">消费者分类</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/07messagefilter">消息过滤</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/08consumerloadbalance">消费者负载均衡</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/09consumerprogress">消费进度管理</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/10consumerretrypolicy">消费重试</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/docs/featureBehavior/11messagestorepolicy">消息存储和清理机制</a></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/deploymentOperations/01deploy">部署 &amp; 运维</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/observability/01metrics">可观测</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/sdk/01overview">客户端 SDK</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/bestPractice/01bestpractice">最佳实践</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/eventbridge/01RocketMQEventBridgeConcepts">RocketMQ EventBridge</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/mqtt/01RocketMQMQTTOverview">RocketMQ MQTT</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/connect/01RocketMQ Connect Overview">RocketMQ Connect</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/streams/01RocketMQ Streams Overview">RocketMQ Streams</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/docs/contributionGuide/01how-to-contribute">贡献指南</a></div></li></ul></nav></div></div></aside><main class="docMainContainer_gTbr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="页面路径"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="主页面" class="breadcrumbs__link" href="/zh/"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_YNFT"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">功能特性</span><meta itemprop="position" content="1"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">消息发送重试和流控机制</span><meta itemprop="position" content="2"></li></ul></nav><span class="theme-doc-version-badge badge badge--secondary">版本:5.0</span><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">本页总览</button></div><div class="theme-doc-markdown markdown"><h1>消息发送重试和流控机制</h1><p>本文为您介绍 Apache RocketMQ 的消息发送重试机制和消息流控机制。</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="背景信息">背景信息<a href="#背景信息" class="hash-link" aria-label="背景信息的直接链接" title="背景信息的直接链接"></a></h2><p><strong>消息发送重试</strong></p><p>Apache RocketMQ的消息发送重试机制主要为您解答如下问题:</p><ul><li><p>部分节点异常是否影响消息发送?</p></li><li><p>请求重试是否会阻塞业务调用?</p></li><li><p>请求重试会带来什么不足?</p></li></ul><p><strong>消息流控</strong></p><p>Apache RocketMQ 的流控机制主要为您解答如下问题:</p><ul><li><p>系统在什么情况下会触发流控?</p></li><li><p>触发流控时客户端行为是什么?</p></li><li><p>应该如何避免触发流控,以及如何应对突发流控?</p></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="消息发送重试机制">消息发送重试机制<a href="#消息发送重试机制" class="hash-link" aria-label="消息发送重试机制的直接链接" title="消息发送重试机制的直接链接"></a></h2><h3 class="anchor anchorWithStickyNavbar_LWe7" id="重试基本概念">重试基本概念<a href="#重试基本概念" class="hash-link" aria-label="重试基本概念的直接链接" title="重试基本概念的直接链接"></a></h3><p>Apache RocketMQ 客户端连接服务端发起消息发送请求时,可能会因为网络故障、服务异常等原因导致调用失败。为保证消息的可靠性, Apache RocketMQ 在客户端SDK中内置请求重试逻辑,尝试通过重试发送达到最终调用成功的效果。</p><p>同步发送和异步发送模式均支持消息发送重试。</p><p><strong>重试触发条件</strong></p><p>触发消息发送重试机制的条件如下:</p><ul><li><p>客户端消息发送请求调用失败或请求超时</p></li><li><p>网络异常造成连接失败或请求超时。</p></li><li><p>服务端节点处于重启或下线等状态造成连接失败。</p></li><li><p>服务端运行慢造成请求超时。</p></li><li><p>服务端返回失败错误码</p><ul><li><p>系统逻辑错误:因运行逻辑不正确造成的错误。</p></li><li><p>系统流控错误:因容量超限造成的流控错误。</p></li></ul></li></ul><div class="theme-admonition theme-admonition-note alert alert--secondary admonition_LlT9"><div class="admonitionHeading_tbUL"><span class="admonitionIcon_kALy"><svg viewBox="0 0 14 16"><path fill-rule="evenodd" d="M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"></path></svg></span>备注</div><div class="admonitionContent_S0QG"><p>对于事务消息,只会进行<a href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md#transparent-retries" target="_blank" rel="noopener noreferrer">透明重试(transparent retries)</a>,网络超时或异常等场景不会进行重试。</p></div></div><h3 class="anchor anchorWithStickyNavbar_LWe7" id="重试流程">重试流程<a href="#重试流程" class="hash-link" aria-label="重试流程的直接链接" title="重试流程的直接链接"></a></h3><p>生产者在初始化时设置消息发送最大重试次数,当出现上述触发条件的场景时,生产者客户端会按照设置的重试次数一直重试发送消息,直到消息发送成功或达到最大重试次数重试结束,并在最后一次重试失败后返回调用错误响应。</p><ul><li><p>同步发送:调用线程会一直阻塞,直到某次重试成功或最终重试失败,抛出错误码和异常。</p></li><li><p>异步发送:调用线程不会阻塞,但调用结果会通过异常事件或者成功事件返回。</p></li></ul><h3 class="anchor anchorWithStickyNavbar_LWe7" id="重试间隔">重试间隔<a href="#重试间隔" class="hash-link" aria-label="重试间隔的直接链接" title="重试间隔的直接链接"></a></h3><ul><li><p>除服务端返回系统流控错误场景,其他触发条件触发重试后,均会立即进行重试,无等待间隔。</p></li><li><p>若由于服务端返回流控错误触发重试,系统会按照指数退避策略进行延迟重试。指数退避算法通过以下参数控制重试行为:</p><ul><li><p>INITIAL_BACKOFF: 第一次失败重试前后需等待多久,默认值:1秒。</p></li><li><p>MULTIPLIER :指数退避因子,即退避倍率,默认值:1.6。</p></li><li><p>JITTER :随机抖动因子,默认值:0.2。</p></li><li><p>MAX_BACKOFF :等待间隔时间上限,默认值:120秒</p></li><li><p>MIN_CONNECT_TIMEOUT :最短重试间隔,默认值:20秒。</p></li></ul></li></ul><p><strong>建议算法如下:</strong></p><div class="language-unknow codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_biex"><pre tabindex="0" class="prism-code language-unknow codeBlock_bY9V thin-scrollbar"><code class="codeBlockLines_e6Vv"><span class="token-line" style="color:#393A34"><span class="token plain">ConnectWithBackoff()</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> current_backoff = INITIAL_BACKOFF</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> current_deadline = now() + INITIAL_BACKOFF</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> while (TryConnect(Max(current_deadline, now() + MIN_CONNECT_TIMEOUT))!= SUCCESS)</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> SleepUntil(current_deadline)</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> current_backoff = Min(current_backoff * MULTIPLIER, MAX_BACKOFF)</span><br></span><span class="token-line" style="color:#393A34"><span class="token plain"> current_deadline = now() + current_backoff + UniformRandom(-JITTER * current_backoff, JITTER * current_backoff)</span><br></span></code></pre><div class="buttonGroup__atx"><button type="button" aria-label="复制代码到剪贴板" title="复制" class="clean-btn"><span class="copyButtonIcons_eSgA" aria-hidden="true"><svg viewBox="0 0 24 24" class="copyButtonIcon_y97N"><path fill="currentColor" d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"></path></svg><svg viewBox="0 0 24 24" class="copyButtonSuccessIcon_LjdS"><path fill="currentColor" d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"></path></svg></span></button></div></div></div><p> 更多信息,请参见<a href="https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md" target="_blank" rel="noopener noreferrer">connection-backoff 策略</a></p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="功能约束">功能约束<a href="#功能约束" class="hash-link" aria-label="功能约束的直接链接" title="功能约束的直接链接"></a></h3><ul><li><p>链路耗时阻塞评估:从上述重试机制可以看出,在重试流程中生产者仅能控制最大重试次数。若由于系统异常触发了SDK内置的重试逻辑,则服务端需要等待最终重试结果,可能会导致消息发送请求链路被阻塞。对于某些实时调用类场景,您需要合理评估每次调用请求的超时时间以及最大重试次数,避免影响全链路的耗时。</p></li><li><p>最终异常兜底: Apache RocketMQ 客户端内置的发送请求重试机制并不能保证消息发送一定成功。当最终重试仍然失败时,业务方调用需要捕获异常,并做好冗余保护处理,避免消息发送结果不一致。</p></li><li><p>消息重复问题:因远程调用的不确定性,当Apache RocketMQ客户端因请求超时触发消息发送重试流程,此时客户端无法感知服务端的处理结果,客户端进行的消息发送重试可能会产生消息重复问题,业务逻辑需要自行处理消息重复问题。</p></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="消息流控机制">消息流控机制<a href="#消息流控机制" class="hash-link" aria-label="消息流控机制的直接链接" title="消息流控机制的直接链接"></a></h2><h3 class="anchor anchorWithStickyNavbar_LWe7" id="消息流控基本概念">消息流控基本概念<a href="#消息流控基本概念" class="hash-link" aria-label="消息流控基本概念的直接链接" title="消息流控基本概念的直接链接"></a></h3><p>消息流控指的是系统容量或水位过高, Apache RocketMQ 服务端会通过快速失败返回流控错误来避免底层资源承受过高压力。</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="触发条件">触发条件<a href="#触发条件" class="hash-link" aria-label="触发条件的直接链接" title="触发条件的直接链接"></a></h3><p>Apache RocketMQ 的消息流控触发条件如下:</p><ul><li><p>存储压力大:参考<a href="/zh/docs/featureBehavior/09consumerprogress">消费进度管理</a>的原理机制,消费者分组的初始消费位点为当前队列的最大消费位点。若某些场景例如业务上新等需要回溯到指定时刻前开始消费,此时队列的存储压力会瞬间飙升,触发消息流控。</p></li><li><p>服务端请求任务排队溢出:若消费者消费能力不足,导致队列中有大量堆积消息,当堆积消息超过一定数量后会触发消息流控,减少下游消费系统压力。</p></li></ul><h3 class="anchor anchorWithStickyNavbar_LWe7" id="流控行为">流控行为<a href="#流控行为" class="hash-link" aria-label="流控行为的直接链接" title="流控行为的直接链接"></a></h3><p>当系统触发消息发送流控时,客户端会收到系统限流错误和异常,错误码信息如下:</p><ul><li><p>reply-code:530</p></li><li><p>reply-text:TOO_MANY_REQUESTS</p></li></ul><p>客户端收到系统流控错误码后,会根据指数退避策略进行消息发送重试。</p><h3 class="anchor anchorWithStickyNavbar_LWe7" id="处理建议">处理建议<a href="#处理建议" class="hash-link" aria-label="处理建议的直接链接" title="处理建议的直接链接"></a></h3><ul><li><p>如何避免触发消息流控:触发限流的根本原因是系统容量或水位过高,您可以利用可观测性功能监控系统水位容量等,保证底层资源充足,避免触发流控机制。</p></li><li><p>突发消息流控处理:如果因为突发原因触发消息流控,且客户端内置的重试流程执行失败,则建议业务方将请求调用临时替换到其他系统进行应急处理。</p></li></ul></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/apache/rocketmq-site/tree/new-official-website/versioned_docs/version-5.0/04-featureBehavior/05sendretrypolicy.md" target="_blank" rel="noreferrer noopener" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>编辑此页</a></div><div class="col lastUpdated_vwxv"></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="文件选项卡"><a class="pagination-nav__link pagination-nav__link--prev" href="/zh/docs/featureBehavior/04transactionmessage"><div class="pagination-nav__sublabel">上一页</div><div class="pagination-nav__label">事务消息</div></a><a class="pagination-nav__link pagination-nav__link--next" href="/zh/docs/featureBehavior/06consumertype"><div class="pagination-nav__sublabel">下一页</div><div class="pagination-nav__label">消费者分类</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#背景信息" class="table-of-contents__link toc-highlight">背景信息</a></li><li><a href="#消息发送重试机制" class="table-of-contents__link toc-highlight">消息发送重试机制</a><ul><li><a href="#重试基本概念" class="table-of-contents__link toc-highlight">重试基本概念</a></li><li><a href="#重试流程" class="table-of-contents__link toc-highlight">重试流程</a></li><li><a href="#重试间隔" class="table-of-contents__link toc-highlight">重试间隔</a></li><li><a href="#功能约束" class="table-of-contents__link toc-highlight">功能约束</a></li></ul></li><li><a href="#消息流控机制" class="table-of-contents__link toc-highlight">消息流控机制</a><ul><li><a href="#消息流控基本概念" class="table-of-contents__link toc-highlight">消息流控基本概念</a></li><li><a href="#触发条件" class="table-of-contents__link toc-highlight">触发条件</a></li><li><a href="#流控行为" class="table-of-contents__link toc-highlight">流控行为</a></li><li><a href="#处理建议" class="table-of-contents__link toc-highlight">处理建议</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Learn</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/zh/docs/domainModel/01main">Introduction</a></li><li class="footer__item"><a class="footer__link-item" href="/zh/docs/quickStart/01quickstart">Installation</a></li><li class="footer__item"><a class="footer__link-item" href="/zh/version">Migration from 4.x to 5.0</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://twitter.com/ApacheRocketMQ" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://github.com/apache/rocketmq" target="_blank" rel="noopener noreferrer" class="footer__link-item">Github</a></li><li class="footer__item"><a href="https://github.com/apache/rocketmq" target="_blank" rel="noopener noreferrer" class="footer__link-item">Help</a></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/zh/blog">Blog</a></li><li class="footer__item"><a class="footer__link-item" href="/zh/release-notes">Changelog</a></li><li class="footer__item"><a href="https://github.com/apache/rocketmq" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://twitter.com/docusaurus" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">Legal</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://www.apache.org/licenses/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Licenses<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://www.apache.org/security/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Security<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://www.apache.org/foundation/thanks.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Thanks<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://www.apache.org/foundation/sponsorship.html" target="_blank" rel="noopener noreferrer" class="footer__link-item">Sponsorship<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><a href="https://rocketmq.apache.org/" rel="noopener noreferrer" class="footerLogoLink_BH7S"><img src="/zh/img/Apache_RocketMQ_logo.svg.png" alt="Meta Open Source Logo" class="themedImage_ToTc themedImage--light_HNdA footer__logo"><img src="/zh/img/Apache_RocketMQ_logo.svg.png" alt="Meta Open Source Logo" class="themedImage_ToTc themedImage--dark_i4oU footer__logo"></a></div><div class="footer__copyright">Copyright © 2024 The Apache Software Foundation. Licensed under the Apache License, Version 2.0.</div></div></div></footer></div>
<script src="/zh/assets/js/runtime~main.b17b65ca.js"></script>
<script src="/zh/assets/js/main.46e74ac2.js"></script>
</body>
</html>