<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>http://wiki.eijux.com/index.php?action=history&amp;feed=atom&amp;title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0</id>
	<title>RabbitMQ：Publisher Confirms实现 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.eijux.com/index.php?action=history&amp;feed=atom&amp;title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0"/>
	<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;action=history"/>
	<updated>2026-04-30T15:35:19Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=6219&amp;oldid=prev</id>
		<title>Eijux：​/* 关于 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=6219&amp;oldid=prev"/>
		<updated>2022-10-31T14:13:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;关于&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2022年10月31日 (一) 22:13的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot;&gt;第2行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第2行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 关于 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 关于 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;【以下内容来自官网：[https://www.rabbitmq.com/tutorials/tutorial-seven-java.html Publisher Confirms]】&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/ins&gt;【以下内容来自官网：[https://www.rabbitmq.com/tutorials/tutorial-seven-java.html Publisher Confirms]】&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Publisher confirms 是一个 RabbitMQ 扩展，用于实现可靠的发布。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt; &lt;/ins&gt;Publisher confirms 是一个 RabbitMQ 扩展，用于实现可靠的发布。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;当在 channel 上启用 publisher confirms 时，'''代理将异步确认客户端发布的消息'''，这意味着它们已在服务器端得到处理。【？？？】&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;当在 channel 上启用 publisher confirms 时，'''代理将异步确认客户端发布的消息'''，这意味着它们已在服务器端得到处理。【？？？】&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3940&amp;oldid=prev</id>
		<title>Eijux：​/* 策略3：异步处理发布确认 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3940&amp;oldid=prev"/>
		<updated>2021-05-26T17:31:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;策略3：异步处理发布确认&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月27日 (四) 01:31的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l87&quot;&gt;第87行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第87行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;有两个回调：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;有两个回调：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;一个用于确认消息，&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;一个用于 confirmed 消息，&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# 另一个用于 nack-ed 消息（代理可以认为丢失的消息）。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# 另一个用于 nack-ed 消息（代理可以认为丢失的消息）。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;每个回调有2个参数：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;每个回调有2个参数：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3928&amp;oldid=prev</id>
		<title>Eijux：​/* 策略2：批量发布消息 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3928&amp;oldid=prev"/>
		<updated>2021-05-25T17:50:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;策略2：批量发布消息&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月26日 (三) 01:50的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l49&quot;&gt;第49行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第49行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== 策略2：批量发布消息 ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== 策略2：批量发布消息 ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;为了改进前面的示例，我们可以发布一批消息并等待整个批消息得到确认。以下示例使用 100 个批次：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;为了改进前面的示例，我们可以发布一批消息并等待整个批消息得到确认。以下示例使用 100 个批次：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;9,14&lt;/ins&gt;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int batchSize = 100;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int batchSize = 100;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int outstandingMessageCount = 0;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int outstandingMessageCount = 0;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3927&amp;oldid=prev</id>
		<title>Eijux：​/* 策略2：异步处理发布确认 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3927&amp;oldid=prev"/>
		<updated>2021-05-25T17:50:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;策略2：异步处理发布确认&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月26日 (三) 01:50的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l75&quot;&gt;第75行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第75行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** 而且这个解决方案仍然是同步的，因为它阻止了消息的发布。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;** 而且这个解决方案仍然是同步的，因为它阻止了消息的发布。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;策略2：异步处理发布确认 &lt;/del&gt;===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;策略3：异步处理发布确认 &lt;/ins&gt;===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;代理以异步方式确认已发布的消息，只需在客户端上注册一个'''回调'''就可以得到这些确认的通知：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;代理以异步方式确认已发布的消息，只需在客户端上注册一个'''回调'''就可以得到这些确认的通知：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l96&quot;&gt;第96行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第96行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;在发布之前，可以通过 &amp;lt;code&amp;gt;Channel#getNextPublishSeqNo()&amp;lt;/code&amp;gt; 获取序列号：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;在发布之前，可以通过 &amp;lt;code&amp;gt;Channel#getNextPublishSeqNo()&amp;lt;/code&amp;gt; 获取序列号：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1&lt;/del&gt;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;: &lt;/ins&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int sequenceNumber = channel.getNextPublishSeqNo());&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;int sequenceNumber = channel.getNextPublishSeqNo());&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ch.basicPublish(exchange, queue, properties, body);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ch.basicPublish(exchange, queue, properties, body);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l104&quot;&gt;第104行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第104行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;将消息与 sequenceNumber 关联的简单方法在于使用'''映射'''。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;将消息与 sequenceNumber 关联的简单方法在于使用'''映射'''。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;: 假设我们想要发布字符串，因为它们很容易转换成字节数组进行发布。下面是一个代码示例，它使用映射将发布序列号与消息的字符串体关联起来：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;: 假设我们想要发布字符串，因为它们很容易转换成字节数组进行发布。下面是一个代码示例，它使用映射将发布序列号与消息的字符串体关联起来：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;: &amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1,4&lt;/del&gt;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;: &amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// ... code for confirm callbacks will come later&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// ... code for confirm callbacks will come later&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l112&quot;&gt;第112行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第112行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;发布代码现在'''使用映射跟踪出站消息'''。我们需要在确认信息到达时清理此 Map，并在消息未确认时记录警告：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;发布代码现在'''使用映射跟踪出站消息'''。我们需要在确认信息到达时清理此 Map，并在消息未确认时记录警告：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;1,3,8,10,14,20&lt;/ins&gt;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ConfirmCallback cleanOutstandingConfirms = (sequenceNumber, multiple) -&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ConfirmCallback cleanOutstandingConfirms = (sequenceNumber, multiple) -&amp;gt; {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     if (multiple) {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     if (multiple) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3926&amp;oldid=prev</id>
		<title>Eijux：​/* 代码示例 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3926&amp;oldid=prev"/>
		<updated>2021-05-25T17:45:18Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;代码示例&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月26日 (三) 01:45的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l165&quot;&gt;第165行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第165行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 代码示例 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 代码示例 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PublisherConfirms.java：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PublisherConfirms.java：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; line highlight=&amp;quot;37,43,57,&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;70&lt;/del&gt;,75,89,91,93,104,116&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; line highlight=&amp;quot;37,43,57,&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;69&lt;/ins&gt;,75,89,91,93,104,116&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.Channel;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.Channel;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.ConfirmCallback;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.ConfirmCallback;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3925&amp;oldid=prev</id>
		<title>Eijux：​/* 代码示例 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3925&amp;oldid=prev"/>
		<updated>2021-05-25T17:43:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;代码示例&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月26日 (三) 01:43的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l165&quot;&gt;第165行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第165行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 代码示例 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 代码示例 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PublisherConfirms.java：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;PublisherConfirms.java：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; line highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; line highlight=&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;37,43,57,70,75,89,91,93,104,116&lt;/ins&gt;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.Channel;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.Channel;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.ConfirmCallback;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;import com.rabbitmq.client.ConfirmCallback;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l203&quot;&gt;第203行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第203行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             ch.confirmSelect();&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             ch.confirmSelect();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             long start = System.nanoTime();&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             long start = System.nanoTime();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             for (int i = 0; i &amp;lt; MESSAGE_COUNT; i++) {&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;             for (int i = 0; i &amp;lt; MESSAGE_COUNT; i++) {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3924&amp;oldid=prev</id>
		<title>Eijux：​建立内容为“category:RabbitMQ  == 关于 == 【以下内容来自官网：[https://www.rabbitmq.com/tutorials/tutorial-seven-java.html Publisher Confirms]】  Publisher c…”的新页面</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=RabbitMQ%EF%BC%9APublisher_Confirms%E5%AE%9E%E7%8E%B0&amp;diff=3924&amp;oldid=prev"/>
		<updated>2021-05-25T17:36:27Z</updated>

		<summary type="html">&lt;p&gt;建立内容为“&lt;a href=&quot;/%E5%88%86%E7%B1%BB:RabbitMQ&quot; title=&quot;分类:RabbitMQ&quot;&gt;category:RabbitMQ&lt;/a&gt;  == 关于 == 【以下内容来自官网：[https://www.rabbitmq.com/tutorials/tutorial-seven-java.html Publisher Confirms]】  Publisher c…”的新页面&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[category:RabbitMQ]]&lt;br /&gt;
&lt;br /&gt;
== 关于 ==&lt;br /&gt;
【以下内容来自官网：[https://www.rabbitmq.com/tutorials/tutorial-seven-java.html Publisher Confirms]】&lt;br /&gt;
&lt;br /&gt;
Publisher confirms 是一个 RabbitMQ 扩展，用于实现可靠的发布。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
当在 channel 上启用 publisher confirms 时，'''代理将异步确认客户端发布的消息'''，这意味着它们已在服务器端得到处理。【？？？】&lt;br /&gt;
&lt;br /&gt;
== 在 channel 上启用 publisher confirms ==&lt;br /&gt;
Publisher confirms 是 AMQP 0.9.1 协议的 RabbitMQ 扩展，因此默认情况下不启用它们。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
使用 confirmSelect 方法在 channel 级别启用 Publisher confirms：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
Channel channel = connection.createChannel();&lt;br /&gt;
channel.confirmSelect();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* 必须在您希望使用的'''每个通道上调用此方法'''。&lt;br /&gt;
* 确认只需被启用一次，而不是发布每条消息时都启用。&lt;br /&gt;
&lt;br /&gt;
=== 策略1：单独发布消息 ===&lt;br /&gt;
从使用 confirms 发布消息的最简单方法开始，即发布消息并同步等待其确认：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;6&amp;quot;&amp;gt;&lt;br /&gt;
while (thereAreMessagesToPublish()) {&lt;br /&gt;
    byte[] body = ...;&lt;br /&gt;
    BasicProperties properties = ...;&lt;br /&gt;
    channel.basicPublish(exchange, queue, properties, body);&lt;br /&gt;
    // uses a 5 second timeout&lt;br /&gt;
    channel.waitForConfirmsOrDie(5_000);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
如上，使用 &amp;lt;code&amp;gt;Channel#waitForConfirmsOrDie(long)&amp;lt;/code&amp;gt; 方法等待消息的确认：&lt;br /&gt;
* 消息一经确认，该方法即返回。&lt;br /&gt;
* 如果消息在超时时间内未被确认，或者消息未被确认（意味着代理由于某种原因无法处理它），则该方法将引发异常。&lt;br /&gt;
** 异常处理通常包括：记录错误消息，重试发送消息。&lt;br /&gt;
（不同的客户机库有不同的方法来同步处理 publisher confirms）&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
这种技术非常简单，但也有一个主要缺点：它会显著减慢发布速度，因为消息的确认会阻止所有后续消息的发布。&lt;br /&gt;
: 这种方法不会提供每秒超过几百条已发布消息的吞吐量。然而，对于某些应用程序来说，这已经足够好了。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Publisher Confirms 是异步的吗？'''&lt;br /&gt;
: 我们在开头提到，代理异步确认已发布的消息。但在第一个示例中，代码同步等待，直到消息被确认。客户端实际上异步接收确认，并相应地解除对 waitforconfirmsor 的调用的阻塞。把 waitforconfirmsodie 看作一个同步的助手，它依赖于后台的异步通知。&lt;br /&gt;
: 【即：异步确认，但同步阻塞发送消息】&lt;br /&gt;
&lt;br /&gt;
=== 策略2：批量发布消息 ===&lt;br /&gt;
为了改进前面的示例，我们可以发布一批消息并等待整个批消息得到确认。以下示例使用 100 个批次：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
int batchSize = 100;&lt;br /&gt;
int outstandingMessageCount = 0;&lt;br /&gt;
while (thereAreMessagesToPublish()) {&lt;br /&gt;
    byte[] body = ...;&lt;br /&gt;
    BasicProperties properties = ...;&lt;br /&gt;
    channel.basicPublish(exchange, queue, properties, body);&lt;br /&gt;
    outstandingMessageCount++;&lt;br /&gt;
    if (outstandingMessageCount == batchSize) {&lt;br /&gt;
        ch.waitForConfirmsOrDie(5_000);&lt;br /&gt;
        outstandingMessageCount = 0;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
if (outstandingMessageCount &amp;gt; 0) {&lt;br /&gt;
    ch.waitForConfirmsOrDie(5_000);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
等待一批消息被确认大大提高了吞吐量，而不是等待单个消息的确认（对于远程RabbitMQ节点，最多可提高20-30倍）。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
一个缺点是：&lt;br /&gt;
* 我们'''不知道在失败的情况下到底出了什么问题'''，因此我们可能必须在内存中保留一整批内容来记录有意义的内容或重新发布消息。&lt;br /&gt;
** 而且这个解决方案仍然是同步的，因为它阻止了消息的发布。&lt;br /&gt;
&lt;br /&gt;
=== 策略2：异步处理发布确认 ===&lt;br /&gt;
代理以异步方式确认已发布的消息，只需在客户端上注册一个'''回调'''就可以得到这些确认的通知：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
Channel channel = connection.createChannel();&lt;br /&gt;
channel.confirmSelect();&lt;br /&gt;
channel.addConfirmListener((sequenceNumber, multiple) -&amp;gt; {&lt;br /&gt;
    // code when message is confirmed&lt;br /&gt;
}, (sequenceNumber, multiple) -&amp;gt; {&lt;br /&gt;
    // code when message is nack-ed&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
有两个回调：&lt;br /&gt;
# 一个用于确认消息，&lt;br /&gt;
# 另一个用于 nack-ed 消息（代理可以认为丢失的消息）。&lt;br /&gt;
每个回调有2个参数：&lt;br /&gt;
# '''sequenceNumber'''：序列号，用于标识 confirmed 或 nack-ed 消息的数字；&lt;br /&gt;
#* 它与已发布的消息相关联；&lt;br /&gt;
# '''multiple'''：这是一个布尔值。如果为 false，则只一条消息被 confirmed/nack-ed；如果为 true，则sequenceNumber较低或相等的所有消息都被 confirmed/nack-ed。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
在发布之前，可以通过 &amp;lt;code&amp;gt;Channel#getNextPublishSeqNo()&amp;lt;/code&amp;gt; 获取序列号：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
int sequenceNumber = channel.getNextPublishSeqNo());&lt;br /&gt;
ch.basicPublish(exchange, queue, properties, body);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
将消息与 sequenceNumber 关联的简单方法在于使用'''映射'''。&lt;br /&gt;
: 假设我们想要发布字符串，因为它们很容易转换成字节数组进行发布。下面是一个代码示例，它使用映射将发布序列号与消息的字符串体关联起来：&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;1,4&amp;quot;&amp;gt;&lt;br /&gt;
ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;br /&gt;
// ... code for confirm callbacks will come later&lt;br /&gt;
String body = &amp;quot;...&amp;quot;;&lt;br /&gt;
outstandingConfirms.put(channel.getNextPublishSeqNo(), body);&lt;br /&gt;
channel.basicPublish(exchange, queue, properties, body.getBytes());&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
发布代码现在'''使用映射跟踪出站消息'''。我们需要在确认信息到达时清理此 Map，并在消息未确认时记录警告：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;br /&gt;
ConfirmCallback cleanOutstandingConfirms = (sequenceNumber, multiple) -&amp;gt; {&lt;br /&gt;
    if (multiple) {&lt;br /&gt;
        ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; confirmed = outstandingConfirms.headMap(&lt;br /&gt;
          sequenceNumber, true&lt;br /&gt;
        );&lt;br /&gt;
        confirmed.clear();&lt;br /&gt;
    } else {&lt;br /&gt;
        outstandingConfirms.remove(sequenceNumber);&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
channel.addConfirmListener(cleanOutstandingConfirms, (sequenceNumber, multiple) -&amp;gt; {&lt;br /&gt;
    String body = outstandingConfirms.get(sequenceNumber);&lt;br /&gt;
    System.err.format(&lt;br /&gt;
      &amp;quot;Message with body %s has been nack-ed. Sequence number: %d, multiple: %b%n&amp;quot;,&lt;br /&gt;
      body, sequenceNumber, multiple&lt;br /&gt;
    );&lt;br /&gt;
    cleanOutstandingConfirms.handle(sequenceNumber, multiple);&lt;br /&gt;
});&lt;br /&gt;
// ... publishing code&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
说明：上一个示例包含一个回调，在确认到达时清除映射（注意，这个回调处理单个和多个确认）。此回调在确认到达时使用（作为 Channel#addconfirmlister 的第一个参数）。nack-ed 消息的回调将检索消息正文并发出警告。然后，它重新使用上一个回调来清除未完成确认的映射（无论消息是已确认的还是未确认的，都必须删除映射中相应的条目）。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''如何跟踪未完成的确认？'''：&lt;br /&gt;
: 我们的样本使用 '''ConcurrentNavigableMap''' 跟踪未完成的确认。这种数据结构方便有几个原因。它允许轻松地将序列号与消息（无论消息数据是什么）关联起来，并轻松地将条目清理到给定的序列 id（以处理多个 confirmed/nack-ed）。最后，它支持并发访问，因为 confirm 回调是在客户机库拥有的线程中调用的，它应该与发布线程保持不同。&lt;br /&gt;
: 与复杂的映射实现相比，还有其他方法可以跟踪未完成的映射，例如使用简单的并发哈希映射和变量来跟踪发布序列的下限，但它们通常更复杂，不属于教程。&lt;br /&gt;
&lt;br /&gt;
==== （异步处理发布确认）总结 ====&lt;br /&gt;
总之，异步处理 publisher confirms 通常需要以下步骤：&lt;br /&gt;
# 提供将发布序列号与消息关联的方法；&lt;br /&gt;
# 在通道上注册一个确认监听器，以便在发布者 ack/nack 到达时得到通知，以执行适当的操作，如记录或重新发布 nack-ed 消息；&lt;br /&gt;
#* 序列号到消息关联机制在此步骤中可能还需要一些清理；&lt;br /&gt;
# 在发布消息之前跟踪发布序列号（sequenceNumber）；&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''重新发布 nack-ed 消息？'''：&lt;br /&gt;
: 从相应的回调重新发布 nack-ed 消息是很有诱惑力的，但这应该避免，因为确认回调是在通道不应该执行操作的 I/O 线程中调度的。&lt;br /&gt;
: 更好的解决方案是将消息放入由发布线程轮询的内存队列中。类似 '''ConcurrentLinkedQueue''' 的类是在确认回调和发布线程之间传输消息的一个很好的候选者。&lt;br /&gt;
&lt;br /&gt;
=== 总结 ===&lt;br /&gt;
在某些应用程序中，确保向代理发布消息是必不可少的。Publisher 确认有一个 RabbitMQ 特性可以帮助满足这个需求。Publisher 文件本质上是异步的，但也可以同步处理它们。没有明确的方法来实现，这通常归结为应用程序和整个系统中的约束。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
典型技术包括：&lt;br /&gt;
* 单独发布消息，同步等待确认：简单，但吞吐量非常有限。&lt;br /&gt;
* 批量发布消息，同步等待一批消息的确认：简单、合理的吞吐量，但很难解释什么时候出错。&lt;br /&gt;
* 异步处理：最佳的性能和资源利用率，在发生错误时有良好的控制能力，但能够正确实现。&lt;br /&gt;
&lt;br /&gt;
== 代码示例 ==&lt;br /&gt;
PublisherConfirms.java：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Java&amp;quot; line highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
import com.rabbitmq.client.Channel;&lt;br /&gt;
import com.rabbitmq.client.ConfirmCallback;&lt;br /&gt;
import com.rabbitmq.client.Connection;&lt;br /&gt;
import com.rabbitmq.client.ConnectionFactory;&lt;br /&gt;
&lt;br /&gt;
import java.time.Duration;&lt;br /&gt;
import java.util.UUID;&lt;br /&gt;
import java.util.concurrent.ConcurrentNavigableMap;&lt;br /&gt;
import java.util.concurrent.ConcurrentSkipListMap;&lt;br /&gt;
import java.util.function.BooleanSupplier;&lt;br /&gt;
&lt;br /&gt;
public class PublisherConfirms {&lt;br /&gt;
&lt;br /&gt;
    static final int MESSAGE_COUNT = 50_000;&lt;br /&gt;
&lt;br /&gt;
    static Connection createConnection() throws Exception {&lt;br /&gt;
        ConnectionFactory cf = new ConnectionFactory();&lt;br /&gt;
        cf.setHost(&amp;quot;localhost&amp;quot;);&lt;br /&gt;
        cf.setUsername(&amp;quot;guest&amp;quot;);&lt;br /&gt;
        cf.setPassword(&amp;quot;guest&amp;quot;);&lt;br /&gt;
        return cf.newConnection();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public static void main(String[] args) throws Exception {&lt;br /&gt;
        publishMessagesIndividually();&lt;br /&gt;
        publishMessagesInBatch();&lt;br /&gt;
        handlePublishConfirmsAsynchronously();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    static void publishMessagesIndividually() throws Exception {&lt;br /&gt;
        try (Connection connection = createConnection()) {&lt;br /&gt;
            Channel ch = connection.createChannel();&lt;br /&gt;
&lt;br /&gt;
            String queue = UUID.randomUUID().toString();&lt;br /&gt;
            ch.queueDeclare(queue, false, false, true, null);&lt;br /&gt;
&lt;br /&gt;
            ch.confirmSelect();&lt;br /&gt;
            long start = System.nanoTime();&lt;br /&gt;
            for (int i = 0; i &amp;lt; MESSAGE_COUNT; i++) {&lt;br /&gt;
                String body = String.valueOf(i);&lt;br /&gt;
                ch.basicPublish(&amp;quot;&amp;quot;, queue, null, body.getBytes());&lt;br /&gt;
                ch.waitForConfirmsOrDie(5_000);&lt;br /&gt;
            }&lt;br /&gt;
            long end = System.nanoTime();&lt;br /&gt;
            System.out.format(&amp;quot;Published %,d messages individually in %,d ms%n&amp;quot;, MESSAGE_COUNT, Duration.ofNanos(end - start).toMillis());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    static void publishMessagesInBatch() throws Exception {&lt;br /&gt;
        try (Connection connection = createConnection()) {&lt;br /&gt;
            Channel ch = connection.createChannel();&lt;br /&gt;
&lt;br /&gt;
            String queue = UUID.randomUUID().toString();&lt;br /&gt;
            ch.queueDeclare(queue, false, false, true, null);&lt;br /&gt;
&lt;br /&gt;
            ch.confirmSelect();&lt;br /&gt;
&lt;br /&gt;
            int batchSize = 100;&lt;br /&gt;
            int outstandingMessageCount = 0;&lt;br /&gt;
&lt;br /&gt;
            long start = System.nanoTime();&lt;br /&gt;
            for (int i = 0; i &amp;lt; MESSAGE_COUNT; i++) {&lt;br /&gt;
                String body = String.valueOf(i);&lt;br /&gt;
                ch.basicPublish(&amp;quot;&amp;quot;, queue, null, body.getBytes());&lt;br /&gt;
                outstandingMessageCount++;&lt;br /&gt;
&lt;br /&gt;
                if (outstandingMessageCount == batchSize) {&lt;br /&gt;
                    ch.waitForConfirmsOrDie(5_000);&lt;br /&gt;
                    outstandingMessageCount = 0;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            if (outstandingMessageCount &amp;gt; 0) {&lt;br /&gt;
                ch.waitForConfirmsOrDie(5_000);&lt;br /&gt;
            }&lt;br /&gt;
            long end = System.nanoTime();&lt;br /&gt;
            System.out.format(&amp;quot;Published %,d messages in batch in %,d ms%n&amp;quot;, MESSAGE_COUNT, Duration.ofNanos(end - start).toMillis());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    static void handlePublishConfirmsAsynchronously() throws Exception {&lt;br /&gt;
        try (Connection connection = createConnection()) {&lt;br /&gt;
            Channel ch = connection.createChannel();&lt;br /&gt;
&lt;br /&gt;
            String queue = UUID.randomUUID().toString();&lt;br /&gt;
            ch.queueDeclare(queue, false, false, true, null);&lt;br /&gt;
&lt;br /&gt;
            ch.confirmSelect();&lt;br /&gt;
&lt;br /&gt;
            ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; outstandingConfirms = new ConcurrentSkipListMap&amp;lt;&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
            ConfirmCallback cleanOutstandingConfirms = (sequenceNumber, multiple) -&amp;gt; {&lt;br /&gt;
                if (multiple) {&lt;br /&gt;
                    ConcurrentNavigableMap&amp;lt;Long, String&amp;gt; confirmed = outstandingConfirms.headMap(&lt;br /&gt;
                            sequenceNumber, true&lt;br /&gt;
                    );&lt;br /&gt;
                    confirmed.clear();&lt;br /&gt;
                } else {&lt;br /&gt;
                    outstandingConfirms.remove(sequenceNumber);&lt;br /&gt;
                }&lt;br /&gt;
            };&lt;br /&gt;
&lt;br /&gt;
            ch.addConfirmListener(cleanOutstandingConfirms, (sequenceNumber, multiple) -&amp;gt; {&lt;br /&gt;
                String body = outstandingConfirms.get(sequenceNumber);&lt;br /&gt;
                System.err.format(&lt;br /&gt;
                        &amp;quot;Message with body %s has been nack-ed. Sequence number: %d, multiple: %b%n&amp;quot;,&lt;br /&gt;
                        body, sequenceNumber, multiple&lt;br /&gt;
                );&lt;br /&gt;
                cleanOutstandingConfirms.handle(sequenceNumber, multiple);&lt;br /&gt;
            });&lt;br /&gt;
&lt;br /&gt;
            long start = System.nanoTime();&lt;br /&gt;
            for (int i = 0; i &amp;lt; MESSAGE_COUNT; i++) {&lt;br /&gt;
                String body = String.valueOf(i);&lt;br /&gt;
                outstandingConfirms.put(ch.getNextPublishSeqNo(), body);&lt;br /&gt;
                ch.basicPublish(&amp;quot;&amp;quot;, queue, null, body.getBytes());&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            if (!waitUntil(Duration.ofSeconds(60), () -&amp;gt; outstandingConfirms.isEmpty())) {&lt;br /&gt;
                throw new IllegalStateException(&amp;quot;All messages could not be confirmed in 60 seconds&amp;quot;);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
            long end = System.nanoTime();&lt;br /&gt;
            System.out.format(&amp;quot;Published %,d messages and handled confirms asynchronously in %,d ms%n&amp;quot;, MESSAGE_COUNT, Duration.ofNanos(end - start).toMillis());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    static boolean waitUntil(Duration timeout, BooleanSupplier condition) throws InterruptedException {&lt;br /&gt;
        int waited = 0;&lt;br /&gt;
        while (!condition.getAsBoolean() &amp;amp;&amp;amp; waited &amp;lt; timeout.toMillis()) {&lt;br /&gt;
            Thread.sleep(100L);&lt;br /&gt;
            waited = +100;&lt;br /&gt;
        }&lt;br /&gt;
        return condition.getAsBoolean();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
</feed>