<tbody> <tr> <td id="artContent" style="max-width: 656px;"> <div style="width: 656px; margin: 0; padding: 0; height: 0;"></div> <p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_1__wm.jpeg' data-ratio="0.675" data-s="300,640" data-type="jpeg" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_1__wm.jpeg"></p><h5 cid="n4" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机是一种工具(三个阶段)</span></h5><p cid="n6" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、手工计算阶段</span></p><p cid="n7" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、机械计算阶段</span></p><p cid="n10" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、电子计算阶段</span></p><h5 cid="n13" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">算筹:</span></h5><p cid="n16" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">起源:春秋战国时期</span></p><p cid="n17" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">木头和竹子作为计算工具、大约二百七十几枚为一束、放在一个布袋里、系在腰带随身携带、需要时可以放在桌上摆弄。</span></p><h5 cid="n19" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">算盘:</span></h5><p cid="n21" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">起源:中国公元前五六世纪</span></p><p cid="n22" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">从中国传到日本、朝鲜、西亚和欧洲</span></p><h5 cid="n24" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算尺:</span></h5><p cid="n26" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">起源:17世纪</span></p><p cid="n27" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">发明者:法国人布莱慈.帕斯卡用齿轮计算机械加法器增加了减法、乘法。第一台通用自动时序控制机械计算机。</span></p><p cid="n29" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">四则运算、简单的三角函数、对数等;</span></p><h4 cid="n36" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">电子计算机</span></h4><p cid="n38" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1946年2月,美国宾夕法尼亚大学,ENIAC(世界上第一台真正意义上电子计算机)诞生。</span></p><p cid="n39" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">创始人:约翰.冯.诺依曼 </span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">1.8万真空电子管 1500个需电器 7万个电阻 1万个电容</strong></span></p><h4 cid="n42" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">ENLAC(体型巨大)</span></h4><p cid="n44" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">长:100ft 宽:3ft 高:8ft</span></p><p cid="n45" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">ft:foo(英尺 长度单位) </span><span md-inline="code" spellcheck="false" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">约等于30cm</span></p><p cid="n49" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">长=100x30=3000cm=30m(米) 宽=3x30=90cm(厘米) 高=8x30=240cm(厘米) 总重量:30t(吨)</span></p><p cid="n51" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">采用电子管作为主要的电子器件、ENLAC一秒能执行5000次加法或400次乘法、还可以进行乘法或平方根的计算。它最初被用于军事计算、如弹道计算、原子裂变能量计算、气象预报等多个领域。</span></p><h5 cid="n53" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">ENLAC缺点:</span></h5><p cid="n57" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">采用</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">十进制</strong></span><span md-inline="plain" style="box-sizing: border-box;">而非二进制表示和计算数据、通过</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">手工设置开关和插头来编程</strong></span></p><h5 cid="n55" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">解决办法:</span></h5><p cid="n58" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">提出了“</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">程序存储</strong></span><span md-inline="plain" style="box-sizing: border-box;">”的概念:基本思想是把预先编制好的用于控制计算机工作的程序输入到计算机的存储器存储起来、计算机自动从中读取指令来控制各部分的工作。.冯.诺依曼 提出了二进制和程序存储的思想。</span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_2__wm.png' data-ratio="0.75" data-s="300,640" data-type="png" data-w="800" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_2__wm.png"></p><h4 cid="n62" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">电子计算机的结构</span><br></h4><p cid="n63" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">按照</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">约翰.冯.诺依曼</strong></span><span md-inline="plain" style="box-sizing: border-box;">的体系结构、计算机必须具备</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">五大基本组成器件</strong></span><span md-inline="plain" style="box-sizing: border-box;">:</span></p><p cid="n64" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、输入数据和程序的</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">输入设备</strong></span></p><p cid="n66" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、记忆数据和程序的</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">存储器</strong></span></p><p cid="n68" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、完成数据加工处理的</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">运算器</strong></span></p><p cid="n70" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、控制程序执行的</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">控制器</strong></span></p><p cid="n72" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、输出处理结果的</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">输出设备</strong></span></p><p cid="n76" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">按照</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">约翰.冯.诺依曼</strong></span><span md-inline="plain" style="box-sizing: border-box;">的体系结构、计算机必须具备</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">如下功能</strong></span><span md-inline="plain" style="box-sizing: border-box;">:</span></p><p cid="n77" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、把所需的</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">程序和数据发送至计算机中</strong></span></p><p cid="n79" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、必须要有</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">长期记忆</strong></span><span md-inline="plain" style="box-sizing: border-box;">程序和数据、中间结果及最终运算结果的能力。</span></p><p cid="n88" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、能够完成</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">各种运算</strong></span><span md-inline="plain" style="box-sizing: border-box;">、逻辑运算和数据传送等数据加工处理能力</span></p><p cid="n90" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、能够根据需要</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">控制程序走向</strong></span><span md-inline="plain" style="box-sizing: border-box;">、并能根据指令机器的各部件协调操作</span></p><p cid="n94" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、能够按照要求将处理</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">结果输出给用户</strong></span></p><h4 cid="n101" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">电子计算机的发展(四代)</span></h4><p cid="n104" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">第一代:电子管计算机(20世纪40中期--50年代中期)</span></p><p cid="n105" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">第二代:晶体管计算机(20世纪50中期--60年代中期)</span></p><p cid="n107" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">第三代:集成电路计算机(20世纪60中期--70年代初期)</span></p><p cid="n109" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">第四代:大规模、超大规模集成电路(20世纪70年代至今)</span></p><h5 cid="n111" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机的特点:</span></h5><p cid="n113" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算速度块(每秒几亿甚至亿亿次)、计算精度高(圆周率可精确至小数点的兆亿次)、逻辑性强(预先编译好了程序)数据处理量大(城市几百万人口户籍可以由一台服务器保管)自动化程度高(人预先把处理要求、处理步骤存储在计算机中、它可以自动运行)应用领域广泛(所有领域)</span></p><h5 cid="n116" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机的应用:</span></h5><p cid="n118" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、科学计算</span></p><p cid="n119" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、信息管理</span></p><p cid="n122" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、自动控制</span></p><p cid="n125" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、人工智能</span></p><p cid="n128" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、辅助工程</span></p><p cid="n131" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">6、学习娱乐</span></p><p cid="n134" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">7、电子商务</span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_3__wm.png' data-ratio="0.4875" data-s="300,640" data-type="png" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_3__wm.png"></p><h5 cid="n141" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机分类:</span><br></h5><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_4__wm.png' data-ratio="0.45" data-s="300,640" data-type="png" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_4__wm.png"></p><h5 cid="n144" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机的发展趋势:</span><br></h5><p cid="n145" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">网络化:</strong></span><span md-inline="plain" style="box-sizing: border-box;">计算机网络是现代通信技术和计算机技术相结合的产物、也是计算机在不断普及和应用中发展的必然趋势。</span></p><p cid="n148" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">智能化:</strong></span><span md-inline="plain" style="box-sizing: border-box;">让计算机能够模拟人类的智力活动、如学习、感知、理解、判断、推理等能力;</span></p><p cid="n151" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">巨型化和微型化:</strong></span><span md-inline="plain" style="box-sizing: border-box;">未来计算机将朝着巨型化和微型化两个方向分别发展。</span></p><h5 cid="n157" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">中央处理器:(CPU)</span></h5><p cid="n159" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">中央处理器:(CPU):专门用来完成读取指令和执行指令的部件----核心部件(计算机的大脑)</span></p><p cid="n161" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">CPU的功能:</span></p><p cid="n162" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">程序控制:</strong></span><span md-inline="plain" style="box-sizing: border-box;">程序都是一个个指令的序列、CPU的主要作用就是保证计算机按照一定的顺序来执行程序</span></p><p cid="n164" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">操作控制:</strong></span><span md-inline="plain" style="box-sizing: border-box;">一条指令的功能由若干个基本操作组成、CPU通过管理和产生这些基本操作的控制信号、并把这些信号送往相应的部件、控制这些部件按照要求进行操作。</span></p><p cid="n172" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">时间控制:</strong></span><span md-inline="plain" style="box-sizing: border-box;">计算机在工作的时候、哪些信号先发出、哪些后发出、信号持续多长时间中止、这些问题都由CPU去处理</span></p><p cid="n175" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">数据运算:</strong></span><span md-inline="plain" style="box-sizing: border-box;">对数据进行各种算术运算和逻辑运算、产生运算结果。</span></p><p cid="n173" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">微型计算机CPU由</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">运算器和控制器</strong></span><span md-inline="plain" style="box-sizing: border-box;">两个部分组成:</span></p><p cid="n182" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">运算器:</strong></span><span md-inline="plain" style="box-sizing: border-box;">算术逻辑运算单元(ALU)实现。ALU的运算包括算术运算和逻辑运算。ALU没有记忆保存功能,所以、在运算器中有若干临时存放运算结果的部件、称为寄存器。</span></p><p cid="n184" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">控制器:</strong></span><span md-inline="plain" style="box-sizing: border-box;">负责协调并控制计算机各功能部件执行程序的指令序列,整个计算机的控制指挥部件。</span></p><p cid="n186" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">CPU主要性能指标包括(</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">辨别CPU的好坏</strong></span><span md-inline="plain" style="box-sizing: border-box;">):</span></p><p cid="n190" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">时钟频率(主频):</strong></span><span md-inline="plain" style="box-sizing: border-box;">CPU内数字脉冲信号震荡的速度。主频越高CPU在一个时钟周期里所完成的指令越多、CPU的运算速度也越快。</span></p><p cid="n192" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">外频:</strong></span><span md-inline="plain" style="box-sizing: border-box;">CPU与主板之间同步运行速度、外频速度越高、CPU同时接收的外围设备传来的数据越多。</span></p><p cid="n205" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">前端总线频率:</strong></span><span md-inline="plain" style="box-sizing: border-box;">表示CPU与总线之间数据传输速度,如果CPU处理的速度很快、但是不能及时传递到总线上、整个运算的效率就会下降。</span></p><p cid="n208" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">指令系统和字长:</strong></span><span md-inline="plain" style="box-sizing: border-box;">计算机所能执行的全部指令集合,字节是CPU一次能处理二进制数的位数,字越长、CPU处理数据的能力越强。</span></p><h4 cid="n216" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">存储器---计算机的记忆装置(分类)</span></h4><p cid="n219" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">按存储介质分:</strong></span><span md-inline="plain" style="box-sizing: border-box;">半导体存储器,磁性材料存储器和光介质存储器</span></p><p cid="n221" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">按存取方式分:</strong></span><span md-inline="plain" style="box-sizing: border-box;">随机存取存取器(RAM)顺序存取存储器、直接存取存取器和按内容访问存储器</span></p><p cid="n226" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">按信息的可更改性分:</strong></span><span md-inline="plain" style="box-sizing: border-box;">读写存储器和只读存储器(ROM)</span></p><p cid="n229" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">按断电后信息的可保存性分</strong></span><span md-inline="plain" style="box-sizing: border-box;">:易失性(RAM和Cache)和非易失性存储器(ROM硬盘 光盘)</span></p><p cid="n232" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">按所处位置及功能分:</strong></span><span md-inline="plain" style="box-sizing: border-box;">内部(计算机主机内)和外部(主机外)存储器</span></p><h4 cid="n235" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机对存储器要求--容量大、速度快、成本低(兼顾困难)</span></h4><p cid="n245" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">计算机</strong></span><span md-inline="plain" style="box-sizing: border-box;">采取高速缓存存储器、主存和外存三级存储器体系结构</span></p><p cid="n246" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">高速缓冲存储器(Cache):</strong></span><span md-inline="plain" style="box-sizing: border-box;">主存和CPU之间的一个快速小容量存储器、它存取速度快、但容量小、成本高。</span></p><p cid="n248" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">主存(RAM):</strong></span><span md-inline="plain" style="box-sizing: border-box;">介于CAche和外存之间、用来保护和运行和将要运行的数据(其容量和速度是衡量计算机性能的主要指标)</span></p><p cid="n251" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、</span><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">外存:</strong></span><span md-inline="plain" style="box-sizing: border-box;">保存当前暂时不需要参与运行的程序和数据。</span></p><h5 cid="n254" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">输入输出设备:</span></h5><p cid="n261" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">常用的输入设备:键盘、鼠标、扫描仪、麦克风、摄像头、触摸屏</span></p><p cid="n262" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">常用的输出设备:显示器、打印机、音响、耳机</span></p><p cid="n265" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">主板:</strong></span><span md-inline="image" data-src="C:UsersyuduanhuDesktop423.png" style="box-sizing: border-box;min-width: 10px;min-height: 10px;word-break: break-all;font-family: monospace;vertical-align: top;"></span><span md-inline="plain" style="box-sizing: border-box;">微型计算机中最主要的一个集成电路板。</span><span md-inline="image" data-src="C:UsersyuduanhuDesktop911.png" style="box-sizing: border-box;min-width: 10px;min-height: 10px;word-break: break-all;font-family: monospace;vertical-align: top;"></span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_5_51439_wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_5_51439_wm.png"></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_6__wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_6__wm.png"></p><h5 cid="n290" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机的通信接口</span><br></h5><p cid="n291" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机的通信传输方式分为两大类:</span></p><p cid="n292" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">串行传输:</strong></span><span md-inline="plain" style="box-sizing: border-box;">通过一条传输线路,同时只能传输一个二进制位(除LPT外都是穿行)</span></p><p cid="n294" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="strong" style="box-sizing: border-box;"><strong style="box-sizing: border-box;">并行传输:</strong></span><span md-inline="plain" style="box-sizing: border-box;">通过多条传输路线、同一时间可传输多个二进制位(如:LPT)</span></p><p cid="n302" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、ps/2接口:链接鼠标和键盘(被USB取代)</span></p><p cid="n304" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、LPT接口(并行):连接打印机和扫描仪(被USB取代)</span></p><p cid="n307" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、VGA接口:(D-Sub接口):链接显示器和投影仪等外部显示设备。D形接口、有15个针孔、分为三排。</span></p><p cid="n310" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、COM1:接口:连接某些老式的针式或激光打印机、游戏手柄、工业机械设备。</span></p><p cid="n313" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、RJ-45(网络)接口:将计算机与网络相连</span></p><p cid="n316" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">6、音频接口:一般配有两个、一个用来插耳机、一个用来麦克风</span></p><p cid="n319" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">7、USB接口(Universal Serial Bus通用串行接口)用于规范计算机与外部设备的连接和通信。</span></p><h5 cid="n322" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">USB接口的优点:</span></h5><p cid="n325" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、可以热拔插:用户在使用U盘时、不需要关机再开机</span></p><p cid="n326" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、携带方便、可以连接多个设备</span></p><p cid="n329" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、标准统一:USB接口出现以前,各种外部设备必须连接相应的接口、现在就可以都用USB来连接各种设备</span></p><h4 cid="n332" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机软件分类</span></h4><p cid="n337" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">系统软件:</span></p><p cid="n338" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">能在用户管理和使用计算机提供方便的一类软件、如基本输入/输出系统)(BIOS),操作系统(window系列,UNIX)、程序设计语言处理系统(C语言编译器)、数据库管理系统(Access)</span></p><p cid="n340" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">应用软件:</span></p><p cid="n342" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">专门用于解决各种具体问题的软件程序。</span></p><p cid="n346" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">通用软件:(、 word、 ppt)</span></p><p cid="n348" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">定制软件:专门为某些领域开发的软件、如学校的教学教务管理系统。</span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_7__wm.png' data-ratio="0.41875" data-s="300,640" data-type="png" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_7__wm.png"></p><h4 cid="n354" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">微型计算机的性能与指标</span><br></h4><p cid="n355" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、CPU的性能指标</span></p><p cid="n356" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">机器字长:计算机能同时处理二进制数据的位数</span></p><p cid="n359" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">运算速度:用CPU每秒能执行指令条数表示</span></p><p cid="n361" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、内存容量:主存。CPU直接访问存储器,需要执行的程序和处理数据都是放在内存中的。内存越大,能处理的数据量就越大。</span></p><p cid="n363" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、输入输出数据传输速率:决定了可用的外设与外设交换数据的速度。CPU处理完数据,如果不能及时传输出去,整个运算速度会下降。</span></p><h5 cid="n366" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机中的数据都是以二进制的形式存储的</span></h5><p cid="n369" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">数制:数制包含两个基本要素,基数与位权</span></p><p cid="n382" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">基数:允许使用的基本数字的个数</span></p><p cid="n370" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">人们利用数字符号来计算的方法</span></p><p cid="n372" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">进位计数制:由低位向高位进位计数的方法,“逢几进一”就是几进制数,例“十进制”数就是“逢十进一”人们生活中经常用十进制计数,计算机运用二进制计数。二进制表示一个数的时候是非常长的,为了方便表示一个数,运用十六进制。</span></p><p cid="n384" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">十进制有0123......9这些符号,共有十个符号基数就是10,二进制0 1两个符号,基数就是2,十六进制有0123.....9 a b ....f 这些符号,共有16个,符号基数就是16</span></p><h5 cid="n386" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">位权:与位数有关的常数</span></h5><p cid="n390" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:十进制23591.87个位数字的位权为:</span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_8_51538_wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="884" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_8_51538_wm.png"></p><p cid="n395" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:二进制数10010.01各位数字的位权为:</span><br></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_9__wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="912" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_9__wm.png"></p><p cid="n400" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:十六进制数13A8F。9D各位数字的位权为:</span><br></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_10__wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="908" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_10__wm.png"></p><p cid="n403" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">为了方便计数,我们用(1234)10表示十进制数1234,(10110)2表示二进制数10110,(2DEA)16表示十六进制数2DEA</span><br></p><p cid="n407" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">其他进制转换为十进制(按权展开)</span></p><p cid="n411" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:将二进制数.011转换成十进制</span></p><p cid="n413" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(.011)2=1x26+0x25+1x24+1x23+0x22+1x21+1x20+0x2-1+1x2-2+1x2-3=91.37</span></p><p cid="n409" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:将十进制数7A.3C转换成十进制</span></p><p cid="n415" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(7A.3C)16=7x161+10x160+3x160+3x16-1+12x16-2=112+10+0.046875=122.</span></p><h5 cid="n417" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">十进制转换成二进制</span></h5><p cid="n419" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:将十进制数47转换成二进制(除二取余 自上而下)</span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_11__wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="902" style="" src="http://pubimage.360doc.com/wz/default.gif"></p><p cid="n425" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:将十进制数32.45转换成二进制</span><br></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_12__wm.png' data-ratio="0.19673" data-s="300,640" data-type="png" data-w="488" style="" src="http://pubimage.360doc.com/wz/default.gif"></p><p cid="n430" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">例:将十进制数32.45转换成二进制</span><br></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_13__wm.png' data-ratio="0.98031" data-s="300,640" data-type="png" data-w="914" style="" src="http://pubimage.360doc.com/wz/default.gif"></p><p cid="n434" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">g十进制转换成二进制的过程中有:</span><br></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_14__wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="962" style="" src="http://pubimage.360doc.com/wz/default.gif"></p><h5 cid="n440" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">二进制的特点:</span><br></h5><p cid="n447" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">容易实现、工作可靠、运算简单、便于逻辑运算和逻辑设计</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">二进制的特点数制的转换</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆二进制的数码只有0和1两个,一个二进制的数字称为一个位,由b表示◆ 1b代表什么信息呢? (1b太小)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">西文表示方法∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆表示一个信息最小的单位是8位二进制数,称为一个字节(byte),用B表示ASCl码</span></p><h5 cid="n441" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">计算机的信息单位∶</span></h5><p cid="n448" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 1KB(千字节)=1024B=1024x8=8192b(位)</span></p><p cid="n453" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 1MB (兆字节)=1024KB</span></p><p cid="n450" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 1GB(吉字节)=1024MB</span></p><p cid="n455" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 1TB(太字节)=1024GB</span></p><p cid="n461" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">数制的转换</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆英文在计算机中怎么存储呢?</span></p><p cid="n459" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ ASClI码∶ 美国信息互换标准代码</span></p><p cid="n462" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ ASCI码中每个字符都是以7位二进制数来表示的</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">ASCI码</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 查表可知∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">大写字母A的ASCII码是 十进制表示为65</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">小写字母a的ASCII码是 十进制表示为97小写比大写大32</span></p><h4 cid="n469" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">中文的表示方法</span></h4><h5 cid="n479" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、输入码∶</span></h5><p cid="n495" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">汉字的输入编码方案有很多(主要的)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">西文表示方法∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 数字编码∶ 用一串数字表示汉字(电报码)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 字音编码∶ 基于汉语拼音的编码(搜狗)</span></p><p cid="n476" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆字形编码∶将汉字的字形分解归类(五笔输入法)</span></p><h5 cid="n483" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、交换码∶</span></h5><p cid="n499" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">国家标准委1980年制定了"国标码"--GB2312</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">国标分为94个区,每个区有94个位、区号是01-94,位号也是01-94共有94X94=8836个、一个汉字的区号和位号组合在一起构成区位码。</span></p><h5 cid="n481" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、机内码∶</span></h5><p cid="n487" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">汉字在计算机内部以二进制的形式存储,就是汉字的机内码、不管外部用什么样的方式输入的汉字,到计算机内部的机内码都是唯一的。</span></p><h5 cid="n492" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、汉字的字形码∶</span></h5><p cid="n500" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">汉字在显示或打印输出的时候,计算机是以点阵的方式形成的图形,它用一位二进制数代表一个像素点,字形笔画经过处的亮点用1表示,没有笔画的地方用0表示。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">显示字库∶ 16X16点阵字库,每个汉字的字形码占用,32个字节的存储空间</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">打印字库∶ 24X24点阵,每个汉字的字形码占用72个,字节的存储空间</span><span md-inline="imgtag" data-src="C:UsersyuduanhuDesktop417.png" style="box-sizing: border-box;min-width: 10px;min-height: 10px;word-break: break-all;font-family: monospace;vertical-align: top;"></span></p><p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_15__wm.png' data-ratio="0." data-s="300,640" data-type="png" data-w="935" style="" src="http://pubimage.360doc.com/wz/default.gif"></p><pre spellcheck="false" lang="" cid="n597" mdtype="fences" style="box-sizing: border-box;overflow: visible;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">1. 计算机的起源与发展</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">2. 计算机的特点、应用和分类</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">3. 中央处理器、存储器、输入输出设备、主板、计算机通信接口 </span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">4. 系统软件和应用软件 </span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">5. 微型计算机的性能指标(三点) </span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">6. 数制的转换</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">7. 西文的表示方法ASCII码 </span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">8. 中文的表示方法</span></pre><h4 cid="n598" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1.25em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">操作系统</span></h4><p cid="n602" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">什么是操作系统</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 操作系统∶是计算机系统中一个不可或缺的组成部分,是一种管理计算机资源、控制程序运行、改善人际交互界面和为其他软件提供支持操作系统的系统软件。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 操作系统要管理计算机的软件和硬件资源,其设计原则∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">系统选择</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">第一∶ 使得计算机系统使用更方便第</span></p><p cid="n603" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">第二∶ 能使得计算机系统更高效地工作</span></p><p cid="n610" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 早期的电脑没有操作系统</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 1969年,贝尔实验室开发了UNIX操作系统,现在依然使用</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">操作系统</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 20世纪80年代后,微软的MS-DOS系统、 windows 95、</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">windows 98、 windows Me、windows 2000、windows XP、windows Vista、windows7、windows8等</span></p><h5 cid="n608" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">新的操作系统</span></h5><p cid="n613" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 适应计算机网络应用的网络操作系统,如windows NT</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆适用于电子设备的嵌入式操作系统如 Windows CE ARM</span></p><p cid="n617" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows 7由微软公司开发的操作系统</span></p><p cid="n625" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 是Windows Vista的升级版本</span></p><p cid="n622" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 2009年10月22日,微软在美国正式发布Windows7</span></p><p cid="n619" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 2009年10月23日,微软在中国正式发布Windows7</span></p><h5 cid="n628" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">Windows 7操作系统主要特点∶</span></h5><p cid="n632" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 更加简单、更加安全、更好的连接、更低的成本</span></p><p cid="n643" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows 7在零售市场上有4个版本∶</span></p><p cid="n640" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows 7 Home Basic(家庭普通版)</span></p><p cid="n633" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows 7 Home Premium(家庭高级版)</span></p><p cid="n636" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows 7 Professional(专业版)</span></p><p cid="n638" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows 7 Ultimate(旗舰版)</span></p><h5 cid="n646" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">Windows 7操作系统安装步骤(光盘安装)</span></h5><p cid="n649" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第一步】进入计算机的BIOS(开机启动顺序 每个品牌的计算机有所认识Windows7不同),设置开机启动顺序为光盘</span></p><p cid="n650" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第二步】将光盘插入计算机中,等待出现安装界面</span></p><p cid="n659" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第三步】设置语言。中文版本默认的安装语言是中文(简体),单击"下一步"即可</span></p><p cid="n663" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第四步】进入有界面后,点击【现在安装】,进入“许可条款”界面</span></p><p cid="n661" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第五步】选中“我接受许可条款”复选框,单击“下一步”按钮</span></p><p cid="n664" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第六步】安装磁盘的选择,通常安装在c盘</span></p><p cid="n666" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第七步】单击“下一步”按钮,进入安装界面,计算机自动安装</span></p><p cid="n668" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第八步】设置“用户名”,计算机及密码</span></p><p cid="n670" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第九步】单击“下一步”按钮,进入Window's7的更新配置界面,选择一个即可</span></p><p cid="n672" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【第十步】进入“开始配置时间和日期“窗口,点击”下一步“进入Windows7桌面,安装完成</span></p><h5 cid="n674" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">Windows 7的桌面</span></h5><p cid="n679" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、桌面背景∶桌面的图像,用于装饰桌面(F1键 Windows7帮助)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">2、桌面图标∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(1)系统图标(计算机 网络 回收站)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(2)快捷方式图标(应用程序)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">注意∶ 删除应用程序的快捷方式,并不能删除相应的应用程序</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">3、开始按钮:位于桌面的左下方</span></p><p cid="n689" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">弹出”开始“菜单的方法:单击”开始按钮“按住键盘上的Windows键 快捷键CTRL+Esc</span></p><p cid="n692" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、”开始菜单“:</span></p><p cid="n694" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”固定程序“列表</span></p><p cid="n697" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”所有程序“列表</span></p><p cid="n699" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”右窗格“,”搜索框“,”关闭“按钮</span></p><p cid="n701" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、关闭按钮:</span></p><p cid="n703" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">点击”关机“右边的三角,”切换用户“:更改用户</span></p><p cid="n706" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”注销“:结束当前系统工作</span></p><p cid="n708" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”锁定“:锁屏状态,输入密码可进入</span></p><p cid="n710" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”重新启动“重新启动系统</span></p><p cid="n712" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">”睡眠“:计算机由工作状态转为等待状态,系统所有的工作是保存在硬盘中的。</span></p><p cid="n714" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">6、任务栏:屏幕底部的水平长条(*)</span></p><h5 cid="n716" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">窗口的组成和操作</span></h5><p cid="n719" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">Windows 7的窗口分为两种:文件窗口和应用程序窗口</span></p><p cid="n721" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">Windows 7的应用程序窗口</span></p><h5 cid="n722" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">Windows 7的应用程序窗口</span></h5><p cid="n726" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"> (1)标题栏∶用于显示窗口的名称,如果用户打开多个窗口,标题栏高亮显示的那个是当前活动窗口对话框的组成</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;"> (2)自定义快速访问工具栏∶ 用户可和操作以自行定义常用的命令,与标题栏在同一行,可以对窗口进行移动、还原、最大化 最小化 关闭等操作</span></p><p cid="n731" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(3)最小化按钮∶将当前窗口从屏幕对话框的组成上去掉,但没有关闭,程序还在运行,和操作在任务栏里可以找到</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(4)最大化/还原按钮∶窗口处于非最大化状态时可以最大化窗口;窗口处于最大化状态下,可以将其还原。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(5)菜单栏∶显示当前应用程和操作序的各种命令。单击某一命令可以打开其下来菜单,执行相应的操作</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(6)工具栏∶将常用的命令以图标的形式显示,方便对命令的操作和操作对话框的组成和操作</span></p><p cid="n752" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">对窗口的操作主要包含以下几种∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(1)打开窗口(4种)∶</span></p><h5 cid="n755" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">窗口的组成和操作</span></h5><p cid="n765" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 双击程序或文档(包含快捷方式)的图标</span></p><p cid="n758" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 单击图标后按Enter键</span></p><p cid="n761" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 右键单击鼠标,在弹出的快捷菜单中选择打开命令对话框的组成</span></p><p cid="n763" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 在"开始"菜单中找到相应的程序图标并单击和操作</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(2)最大化、最小化及还原窗口∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 单击窗口右上角的"最大化"按钮 □ 可以将窗口设置为整个屏幕大小对话框的组成</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 单击窗口右上角的"最小化"按钮- 可以将窗口缩放到任务栏中和操作</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 当窗口处于最大化状态时,单击"还原" 按钮 司 ,可以将窗口还原为原始大小</span></p><p cid="n774" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">学慧网</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">第二节 Windows7的窗口和对话框收获的不止一本证书</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(3)缩放窗口∶ 当窗口处于非最大化和非最小化状态时,可以用鼠标指针移动窗口边缘进行拖拽</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;"> 垂直方向缩放对话框的组成</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">水平方向缩放和操作</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">对角线缩放</span></p><p cid="n783" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(4)切换窗口∶</span></p><p cid="n788" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Alt+tab键---平面切换</span></p><p cid="n785" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ Windows+tab键----三位切换</span></p><p cid="n793" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(5)排列窗口∶打开多个窗口时,可以将这些窗口层叠、堆叠和并排的方式排列</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">任务栏空白处右键单击---在快捷菜单中选择</span></p><pre spellcheck="false" lang="" cid="n833" mdtype="fences" style="box-sizing: border-box;overflow: visible;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">工具栏(T)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">层登窗口(D)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">堆叠显示窗口(T)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">并排显示窗口(l)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">显示桌面(S)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">启动任务管理器(K)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">锁定任务栏(L)</span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span><br><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;">属性(R)</span></pre><p cid="n800" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(6)关闭窗口∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 单击右上角的"关闭"按钮 x</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 标题栏单击鼠标右键一快捷菜单---关闭</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆单击标题栏左上角的程序图标-快捷菜单--关闭◆ 按Alt+F4键关闭当前窗口</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 鼠标右键单击任务栏中需要关闭的窗口</span></p><h5 cid="n840" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">对话框在多数都有以下要素∶</span></h5><p cid="n848" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(1)标题栏∶ 显示当前对话框的名称</span></p><p cid="n853" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(2)命令按钮∶如∶"确定""取消"按钮</span></p><p cid="n849" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(3)选择框和组合框∶选择框为用户提供了系列选项,用户只能选择其中之一进行设置组合框提供了选项外还允许用户直接输入相应内容</span></p><p cid="n858" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(4)单选框∶只能选一个,上面表示选中,下边表示没有选择</span></p><p cid="n863" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(5)复选框∶昌可以选择多个,上面表示选中,下面表示设有选择</span></p><p cid="n864" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(6)文本框∶ 供用户直接输入信息</span></p><p cid="n866" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(7)提示文字∶ 向用户提示信息</span></p><p cid="n868" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(8)选项卡∶用于区分不同的选项功能的活动区域</span></p><h5 cid="n861" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">所有文件夹选项:</span></h5><p cid="n870" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">1、标题栏</span></p><p cid="n871" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">2、选项卡</span></p><p cid="n874" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、单选框</span></p><p cid="n877" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">4、复选框</span></p><p cid="n882" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">5、命令按钮</span></p><h5 cid="n888" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">桌面图标的个性化设置:</span></h5><p cid="n901" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(1)添加桌面图标∶ 第一次启动Windows7时,桌面上只有"回收站"一个图标。我们可以在桌面上添加"系统图标"和"应用程序的快捷方式。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">添加系统图标(计算机 网络等图标)∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">步骤1∶ 桌面空白处单击鼠标右键---在弹出的"快捷菜单"中 选择"开始"菜单"个性化"</span></p><p cid="n894" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">步骤2∶单击"更改桌面图标"链接--弹出"桌面图标设置"对话框。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">系统提供了计算机、回收站、用户的文件、控制面板、网络五个应用程序的图标,选中其复选框,单击"确定"或"应用"按钮。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">添加应用程序的快捷方式图标(以"画图"程序为例)∶步骤∶"开始"--"所有程序"---"附件"--右键单击"画图”程序--选择"发送到"—"桌面快捷方式"即可在桌面上添加"画图"程序的快捷方式。</span></p><p cid="n902" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(2)排列图标∶ 用户可以根据自己的需要调整桌面图标的位置系统提出了4种桌面图标排列方式∶按名称、大小、项目类型和修改日期</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">步骤∶ 桌面空白处单击鼠标右键--选择"排列方式"一选择4种方法之一就可以</span></p><p cid="n910" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(3)更改桌面图标∶如果不喜以自己修改图标。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">步骤∶桌面空白处右键单击算机"图标-单击"更改图标"</span></p><h5 cid="n913" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">个性化任务栏和"开始"菜单</span></h5><p cid="n918" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">步骤∶任务栏空白处右键单击或"开始"菜单按钮处进入"任务栏和开始菜单属性"对话框</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(1)"开始"菜单设置∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">切换到"开始菜单"选项卡--单击"自定义"按钮--可以进行自定义设置、用户还可以设置“电源按钮”。</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">自定义通知区域∶通知区域位于任务栏的最右侧,可以告知用户计算机的某些状态信息,如网络连接情况、扬声器的打开和关闭等;</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">步骤∶ 单击"自定义"按钮,如图</span></p><h5 cid="n932" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">资源管理器的使用</span></h5><p cid="n936" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(1)资源管理器界面(如上图),左侧是任务窗格,有收藏夹 库 计算机 网络</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="em" style="box-sizing: border-box;"><em style="box-sizing: border-box;">打开"资源管理器"的方法∶</em></span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">1、鼠标右键单击"开始"按钮—选择"打开Windows资源管理器"</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">2、左键单击任务栏上的文件夹图标</span></p><p cid="n940" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">3、在任务栏"文件夹"图标上右键单击-选择"Windows资源管理器"选项</span></p><p cid="n937" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;"> 4、"开始"—"所有程序"--"附件"--"Windows资源管理器"命令</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(2)重命名文件或文件夹(3种)</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 单击需要重命名的文件或文件夹---单击工具栏中的"组织"按钮-选择"重命名"</span></p><p cid="n955" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 单击需要重命名的文件或文件夹--鼠标右键单击--选择"重命名"</span></p><p cid="n951" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 单击需要重命名的文件或文件夹--单击</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">注意∶ Windows7系统文件或文件夹的命名规则∶字母 数字 汉字 空格 标点不包括∶ /∶*?<>|这8个特殊字符 名称长度不超过256个字符</span></p><p cid="n966" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(3)选定文件或文件夹</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆选定单个文件或文件夹∶鼠标单击</span></p><p cid="n978" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 选定全部∶Ctrl+A 或"组织"---"全选"或 菜单栏中的"编辑"---"全选"</span></p><p cid="n975" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 选定相邻的文件或文件夹∶ 鼠标左键拖动</span></p><p cid="n972" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 选定多个连续的文件或文件夹∶按住shift键,单击第一个和最后一个</span></p><p cid="n969" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 选定多个不连续的文件或文件夹∶按住Ctrl键,鼠标左键单击要选择的文件</span></p><p cid="n986" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(4)复制和移动文件或文件夹</span></p><p cid="n989" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 复制的方法∶</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">选择要复制的文件…右键单击--选择复制-空白处右键单击----.选择"粘贴"</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">"资源管理器"窗口选"编辑"--复制--"编辑"--"粘贴"快捷键∶ Ctrl+C-Ctrl+V</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 移动的方法∶与复制类似,就是将所有的"复制"改为"剪切“快捷键是Ctrl+X</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">注意∶用鼠标拖拽---同一文件夹下的是移动不同文件夹在的是复制</span></p><p cid="n994" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(5)删除和恢复文件或文件夹</span></p><p cid="n997" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆删除的方法∶ 按下Delete键</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">右键单击--选择"删除"(删除到回收站中)鼠标拖拽到"回收站"、文件--织-删除</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆永久删除∶清空回收站、删除时按住"shift"键</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆ 恢复∶回收站中的文件和文件夹可以恢复(右键单击---选择"还原")</span></p><p cid="n1022" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(6)查找文件或文件夹</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">◆如果用户记不清某些文件或文件夹在</span></p><p cid="n1029" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(7)设置/显示隐藏文件或文件夹</span></p><p cid="n1032" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">◆ 选中文件或文件夹-鼠标右键单击-勾---"应用"按钮</span></p><h5 cid="n1036" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">用户账户管理 总结∶</span></h5><p cid="n1038" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(1)更改当前账户密码∶单击"用户账户"管理窗口---单击"更改密码"</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(2)删除当前账户密码∶单击"删除密码"在弹出的对话框中输入当前的密码---再次打开的时候不需要输入密码</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">设置管理器</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(3)更改当前账户显示图片∶单击 "更改图片"---选择电脑自带的或自己的图标</span></p><p cid="n1041" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(4)更改当前账户名称∶单击"更改账户名称"---输入新账户名称---"更改账户"按钮</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(5)更改当前账户类型∶ 单击"更改当前账户类型"按钮一设置"标准用户"或"管理员"类型</span></p><p cid="n1052" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">在控制面板中单击"设备管理器"图标,列出了计算机所有的硬件设备</span></p><p cid="n1060" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">控制面板-管理工具--计算机管理--存储---磁盘管理</span></p><h5 cid="n1064" mdtype="heading" style="box-sizing: border-box;break-after: avoid-page;break-inside: avoid;orphans: 4;font-size: 1em;margin-top: 1rem;margin-bottom: 1rem;font-weight: bold;line-height: 1.4;cursor: text;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">磁盘管理器:</span></h5><p cid="n1067" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(1)设置磁盘属性∶(将D盘改名为"数据文件")在"磁盘管理"界面右键单击D盘的盘符-属性一常规--输入"数据文件";</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(2)创建分区∶如果用户认为磁盘不够用,可以为计算机创建新的分区</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">步骤∶在"磁盘管理"窗口中选择有"可用空间"的磁盘区域--鼠标右键单击---选择"新建简单卷"--单击"下一步"按钮-系统给出最大和最小容量空间---"下一步"---"下一步"--"完成"</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(3)删除分区∶选中需要删除的磁盘--右键单击--删除卷—是</span><span md-inline="softbreak" style="box-sizing: border-box;"></span><span md-inline="plain" style="box-sizing: border-box;">(4)更改磁盘盘符∶右键单击要更改的磁盘--选择"更改驱动器号和路径"—单击"更改"按钮-选中"分配以下驱动器号"--选择磁盘---单击"确定"</span></p><p cid="n1085" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">(5)优化磁盘∶系统在使用一段占据了一定的硬盘空间</span></p><p cid="n1091" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;">【步骤】右键单击需要优化的磁清理"按钮一确定</span></p><p cid="n1094" mdtype="paragraph" style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;"><span md-inline="plain" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);">设备和打印机</span><span md-inline="softbreak" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"></span><span md-inline="plain" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);">控制面板窗口中单击"设备和打印机"</span><span md-inline="softbreak" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"></span><span md-inline="plain" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);">【例子】用户要在电脑上安装惠普打印机,操作步骤∶</span><span md-inline="softbreak" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"></span><span md-inline="plain" style="box-sizing: border-box;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);">步骤∶ 单击"添加打印机"一选择"本地"或网络(适合公用)一选择"添加网络--系统自动搜索已经连接在局域网内的打印机—单击"下一步"---"开始安装打印机驱动程序" --确定</span><span style="font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"></span></p> </td> </tr> </tbody> <tbody> <tr> <td id="artContent" style="max-width: 656px;"> <div style="width: 656px; margin: 0; padding: 0; height: 0;"></div> <p style="text-align: center;"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_1__wm.jpeg' data-ratio="0." data-s="300,640" data-type="jpeg" data-w="1280" style="" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_1__wm.jpeg"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">Hello,大家好。今天会为同学们介绍 RabbitMQ 中的基础核心配置文件。这些基础核心配置文件是保证我们的 RabbitMQ 服务正常运行的基础,如果我们没有根据实际情况去配置这些文件,那么我们的 RabbitMQ 服务可能就不会按照我们计划的那样去运行,也就不能达到我们预期的结果。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">理解并掌握 RabbitMQ 基础核心配置文件的配置方法,以及基础核心配置属性,是灵活配置和应用 RabbitMQ 服务的前提,我们只有掌握了 RabbitMQ 的配置手段之后,我们才能在不同场景去应用 RabbitMQ 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本节主要内容:</span></p><ul style="margin-top: 0.8em;margin-bottom: 0.8em;padding-left: 30px;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 环境相关配置文件及参数;</span></p></li><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 基础配置文件及参数;</span></p></li><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 额外配置文件及参数。</span></p></li></ul><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RabbitMQ 的环境配置文件,主要是用来对 RabbitMQ 服务所运行的环境进行配置,该配置文件根据所处的平台设置了不同的文件名称,在 Windows 平台中,该配置文件被称为 rabbitmq-env-conf.bat ,在 Centos 平台中,该配置文件被称为 rabbitmq-env.conf 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">如果同学们在安装 RabbitMQ 服务时,均采用了默认安装的方式,那么</span><strong style="box-sizing: border-box;">在 Windows 平台中,rabbitmq-env-conf.bat 配置文件的所在目录就位于 RabbitMQ 服务的安装目录下的 sbin 目录中;在 Centos 平台中,rabbitmq-env.conf 配置文件的所在目录就位于 /usr/lib/rabbitmq/bin 目录下。</strong><span style="box-sizing: border-box;"> 如果大家在安装 RabbitMQ 服务时,采用了自定义安装的方式,那么请到各自对应的目录下去寻找该配置文件。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 本着简洁明了的原则,本节所介绍的 RabbitMQ 配置文件均以 Centos 平台下的为例,这和 Windows 平台大同小异,并没有其他的特殊之处。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_NODE_IP_ADDRESS 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_NODE_IP_ADDRESS 属性是用来描述可访问 RabbitMQ 服务的主机地址,具体到我们的工作当中,就是允许哪些应用程序访问我们的 RabbitMQ 服务。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性默认值为空字符串,表示任何应用程序都可以访问我们的 RabbitMQ 服务。那么,如果我们只允许一个应用程序来访问我们的 RabbitMQ 服务,我们应该怎么来配置呢?如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 假定我们的应用程序所在地址为 192.165.22.123</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_NODE_IP_ADDRESS</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span><span style="box-sizing: border-box;color: rgb(170, 17, 17);">"192.165.22.123"</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块12</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">通过上述代码,我们可以知道,如果我们想指定应用程序访问我们的 RabbitMQ 服务,那么我们只需要将我们应用程序所在地址作为字符串的形式,来发赋给 RABBITMQ_NODE_IP_ADDRESS 属性即可。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_NODE_PORT 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_NODE_PORT 属性是用来描述 RabbitMQ 服务所使用的网络端口,即 RabbitMQ 服务在服务器上所绑定的服务端口。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性默认值为 5672 ,即 RabbitMQ 服务默认使用 5672 端口。如果我们想改变 RabbitMQ 服务所绑定的端口,我们只需要按照上述属性的设置步骤即可,如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 假定我们需要将 RabbitMQ 的服务绑定到 6672 端口上</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_NODE_PORT</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span><span style="box-sizing: border-box;color: rgb(170, 17, 17);">"6672"</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块12</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_NODENAME 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_NODENAME 属性是用来描述 RabbitMQ 服务当前所在节点的名称。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性的默认值是根据不同操作系统来定义的,</span><strong style="box-sizing: border-box;">在 Windows 系统中,RABBITMQ_NODENAME 属性的默认值为 rabbit@%COMPUTERNAME% ,即我们电脑的名称;在 Centos 系统中,RABBITMQ_NODENAME 属性的默认值为 rabbit@$HOSTNAME ,即我们主机的名称。</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">同样地,如果我们想自定义 RabbitMQ 服务的节点名称,我们可以这样来做:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 假定我们需要将当前 RabbitMQ 服务所在节点的名称修改为 rabbitmq-server-one</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_NODENAME</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span><span style="box-sizing: border-box;color: rgb(170, 17, 17);">"rabbitmq-server-one"</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块12</span></span></pre></div></pre><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 一般来说,如果我们的 RabbitMQ 服务只有一个节点,是不会修改 RabbitMQ 的服务名称的,如果我们的 RabbitMQ 服务存在多个节点,即 2个及 2 个以上节点时,我们需要根据每个 RabbitMQ 所起到的服务来为不同的 RabbitMQ 节点设置服务名称。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_USE_LONGNAME 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_USE_LONGNAME 属性是是否启用 RabbitMQ 全量名称的开关,当我们开启后,我们每个 RabbitMQ 节点的名称以及其他可命名的地方都会采用完整名称规则的方式来进行命名。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性的默认值为 false ,即不使用 RabbitMQ 全量名称规则来命名,只是用默认的正常规则来进行命名,如果我们需要打开 RabbitMQ 全量命名,我们可以这样打开:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_USE_LONGNAME</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span><span style="box-sizing: border-box;color: rgb(34, 17, 153);">true</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块1</span></span></pre></div></pre><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 在实际工作中,很少会使用 RabbitMQ 的全量命名规则,因为这种命名策略生成的名称非常长,且不易读,不利于我们对 RabbitMQ 服务节点的维护,当然,如果我们必须要使用这种命名规则,也是无可厚非的。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_SERVICENAME 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_SERVICENAME 属性用来描述 RabbitMQ 服务的服务名称。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性只对 Windows 系统起作用,其默认值为 RabbitMQ ,在 Centos 系统中,RabbitMQ 的服务名称不可修改,统一被命名为 rabbitmq-server.service 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">那么,在 Windows 系统中,如果我们想修改 RabbitMQ 的服务名称,我们只需要找到 services.msc 文件,并以文本文档的类型打开它,在里面找到 RABBITMQ_SERVICENAME 属性,将它的值修改成我们想要的名称即可,如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 假定我们需要修改服务名称为 rabbitmq-server</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_SERVICENAME</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span><span style="box-sizing: border-box;color: rgb(170, 17, 17);">"rabbitmq-server"</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块12</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_CONSOLE_LOG 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_CONSOLE_LOG 属性用来规定 RabbitMQ 服务所生成的服务日志的路径,如果没有设置该属性,则 RabbitMQ 不会生成任何服务日志。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性的默认值为空,即默认没有规定 RabbitMQ 服务日志的生成位置。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">如果我们想指定 RabbitMQ 服务所生成的位置,我们只需要将路径赋值给 RABBITMQ_CONSOLE_LOG 属性即可,如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_CONSOLE_LOG</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=/</span><span style="box-sizing: border-box;color: rgb(0, 0, 0);">usr</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">/</span><span style="box-sizing: border-box;color: rgb(0, 0, 0);">temp</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">/</span><span style="box-sizing: border-box;color: rgb(0, 0, 0);">rabbtmq</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">-</span><span style="box-sizing: border-box;color: rgb(0, 0, 0);">log</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">/</span><span style="box-sizing: border-box;color: rgb(0, 0, 0);">one</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">log</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块1</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">RABBITMQ_DIST_PORT 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RABBITMQ_DIST_PORT 属性用来描述 RabbitMQ 服务节点间进行通信的端口号。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性的默认值为 RABBITMQ_NODE_PORT + 20000 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">修改方式如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 假定我们需要修改端口号为 RABBITMQ_NODE_PORT + 20001</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_DIST_PORT</span><span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span><span style="box-sizing: border-box;color: rgb(0, 0, 0);">RABBITMQ_NODE_PORT</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">+</span> <span style="box-sizing: border-box;color: rgb(17, 102, 68);">20001</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块12</span></span></pre></div></pre><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 1. 在实际工作中,一般不会刻意去修改 RabbitMQ 服务节点间进行通信的端口号,除非我们的应用程序所绑定的端口与该端口发生了冲突。</span><span style="box-sizing: border-box;">2. 修改 RabbitMQ 服务节点间通信端口号我们可以采用一种自增的原则,即我们不要修改 RABBITMQ_NODE_PORT ,我们修改的是后面的 20000 ,将 20000 进行一次累加即可。</span><span style="box-sizing: border-box;">3.rabbitmq-env.conf 文件中的所有属性在发生变化之后,都需要重启我们的 RabbitMQ 服务才能生效。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RabbitMQ 基础配置文件主要用来对 RabbitMQ 服务本身做一些配置,从而来满足我们的业务需求。同样地,该配置文件也是根据不同的操作系统来进行命名的,</span><strong style="box-sizing: border-box;">在 Windows 系统中,该配置文件被称为 rabbitmq-conf.bat , 在 Centos 系统中,该配置文件被称为 rabbitmq.conf 。</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在 Centos 系统中,该配置文件默认的路径为 /etc/rabbitmq/ ,在 Windows 系统中,该配置文件默认的路径为 %APPDATA%RabbitMQ ,其中,APPDATA 指的是 RabbitMQ 中数据文件所在的路径。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">listeners 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">listeners 属性是 AMQP 协议用来监听 tcp 端口的监听器,完整属性名称为 listeners.tcp.default 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性的默认值为 5672 ,即 AMQP 协议默认监听 5672 端口。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">修改方式同上,这里不再赘述。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">log.file.level 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">log.file.level 属性用来定义 RabbitMQ 服务日志的打印级别,一共有 4 种日志打印级别,分别是 error 、warning 、info 、debug,这四种日志级别根据这个顺序互相包含,即 debug 级别的日志会打印出 error 、warning、info、debug 的所有数据。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">该属性默认值为 info ,即默认的服务日志打印级别为 info 级别,会打印包括 error 、warning 、info 的所有数据。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">修改方式同上,这里不再赘述。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">channel_max & channel_operation_timeout 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">channel_max 属性是用来规定具体的一个频道与客户端的最大连接数量,该数量的默认值为 2047 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">channel_operation_timeout 属性是用来规定获取具体的一个频道连接的最大超时时间,该时间默认值为 15000 毫秒。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">修改方式同上,这里不再赘述。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">max_message_size & heartbeat & default_vhost 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">max_message_size 属性用来规定一条消息的最大占用空间,该属性的单位为比特,默认值为 ,最大值为 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">heartbeat 属性用来规定 RabbitMQ 服务中心跳检测的超时时间,如果该属性的值设置为 0 ,则 RabbitMQ 服务的心跳检测机制会自动关闭,该属性的默认值为 60 秒。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">default_vhost 属性用来规定 RabbitMQ 服务中默认的虚拟主机名称,默认值为 / 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">修改方式同上,这里不再赘述。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">default_user & default_pass & default_user_tags & default_permissions 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">default_user 属性和 default_pass 属性分别用来规定 RabbitMQ 服务中默认的用户名和密码,默认值均为 guest 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">default_user_tags 属性用来对用户的角色进行设置,默认值为 administrator,即默认用户为 RabbitMQ 服务的超级管理员,如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">default_user_tags</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">administrator</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(34, 17, 153);">true</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块1</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">default_permissions 属性用来规定用户的默认权限,默认值为所有用户都可以对 RabbitMQ 进行配置,以及读写操作。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">如果我们想修改用户的权限,那么我们需要这样进行修改:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">default_permissions</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">configure</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> .<span style="box-sizing: border-box;color: rgb(152, 26, 26);">*</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">default_permissions</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">read</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> .<span style="box-sizing: border-box;color: rgb(152, 26, 26);">*</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">default_permissions</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">write</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> .<span style="box-sizing: border-box;color: rgb(152, 26, 26);">*</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块123</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">上述代码中,configure 用来设置是否允许用户对 RabbitMQ 进行配置,read 用来设置用户的读权限,write 用来设置用户的写权限。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">cluster_formation.classic_config.nodes 属性</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">cluster_formation.classic_config.nodes 属性用来设置不同 RabbitMQ 服务节点间连接,该属性会作为一个列表生效,即该列表中的所有 RabbitMQ 服务节点在 RabbitMQ 服务启动时都将被启动,且各节点间的通信通道将被打开。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">那么该如何定义我们所需要的节点呢?如下代码所示:</span></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 假定我们有两个服务节点需要通信</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">cluster_formation</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">classic_config</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">nodes</span>.<span style="box-sizing: border-box;color: rgb(17, 102, 68);">1</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">rabbit</span><span style="box-sizing: border-box;color: rgb(85, 85, 85);">@hostname1</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">cluster_formation</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">classic_config</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">nodes</span>.<span style="box-sizing: border-box;color: rgb(17, 102, 68);">2</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">rabbit</span><span style="box-sizing: border-box;color: rgb(85, 85, 85);">@hostname2</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块123</span></span></pre></div></pre><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 1. rabbitmq.conf 文件中的所有属性,一经修改,需要重启 RabbitMQ 服务才可生效。</span><span style="box-sizing: border-box;">2. 出于不同的安装方式,rabbitmq.conf 配置文件可能有的安装方式不会自动生成,如果需要,我们可以在上述指定目录新建一个 rabbitmq.conf 文件,并重启 RabbitMQ 服务。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">文件介绍</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">通过对上述 RabbitMQ 环境配置文件以及 RabbitMQ 基础配置文件及其中的核心属性的介绍,我们已经将 RabbitMQ 中的所有核心配置项全部介绍完毕了,这些核心配置项基本可以满足我们自定义 RabbitMQ 98% 的需求的需要。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RabbitMQ 额外配置文件是对上述 RabbitMQ 基础配置文件的补充,当我们对这个额外配置文件做了自定义配置之后,那么我们所配置的内容会和 RabbitMQ 基础配置文件相合并,但是这个额外配置文件是通过 erlang 语言的语法来配置的,如果我们想自定义该配置文件的话,还需要我们对 erlang 语言有所了解。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">出于本套课程的初衷考虑,本节不会对 RabbitMQ 额外配置文件做进一步的介绍,我们只需要了解 RabbitMQ 配置文件中存在这么一个额外的配置文件即可,这个配置文件在实际工作中几乎是不使用的。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RabbitMQ 额外配置文件只存在于 Centos 系统中,文件名称默认为 advanced.config 。在 Centos 系统中,该文件位于 /etc/rabbitmq 路径下;在 Windows 系统中,该文件位于 %APPDATA%RabbitMQ 路径下,其中,APPDATA 指的是 RabbitMQ 中数据文件的所在位置。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_2__wm.png' data-ratio="0." data-type="png" data-w="623" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_2__wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本小节主要对 RabbitMQ 中的配置文件,及其配置文件属性做了详细介绍。针对基础核心配置文件,例如,RabbitMQ 环境配置文件和 RabbitMQ 基础配置文件,对这些配置文件中的各个核心配置属性都做了详细介绍,对于不需要各位同学掌握的 RabbitMQ 额外配置文件 advanced.config ,各位同学只需要知道它的作用即可。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">Hello,大家好。今天会为同学们介绍 RabbitMQ 的消息发送原理,RabbitMQ 消息发送原理展开来说有太多内容了,完全可以专门作为一门独立的课程存在,所以,本节只会从宏观层面来介绍 RabbitMQ 的消息发送原理,太深的概念并不会涉及。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在了解了如何使用 RabbitMQ 来发送消息之后,简单了解 RabbitMQ 消息发送的原理是非常有必要的,它能够帮助我们定位排查一些 RabbitMQ 出现的问题,所以就让我们来看看 RabbitMQ 到底是如何来发送消息的吧。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本节主要内容:</span></p><ul style="margin-top: 0.8em;margin-bottom: 0.8em;padding-left: 30px;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 整体架构解析;</span></p></li><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 消息发送原理概述;</span></p></li></ul><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RabbitMQ 整体架构是基于 AMQP 协议的,结合 AMQP 协议的架构模型,我们可以得出 RabbitMQ 的整体架构,RabbitMQ 整体架构如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_3__wm.png' data-ratio="0.9601" data-type="png" data-w="401" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_3__wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">消息这一元素在 RabbitMQ 中虽然至关重要,但消息只是 RabbitMQ 处理的目标,并不能作为 RabbitMQ Server 的组成部分,所以,在上图中,我并没有引入消息这一概念,目的就是让各位同学能够看清楚 RabbitMQ Server 的架构到底是什么样的,即 RabbitMQ Server 都是由哪些元素或组件所组成的。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">我们都知道,RabbitMQ Server 就是我们的 RabbitMQ 服务器,在 AMQP 协议中,RabbitMQ Server 又被称为 Broker ,这点同学们需要了解。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">由图可知,</span><strong style="box-sizing: border-box;">RabbitMQ Server 由 Virtual Host 、Exchange 、Channel 、Queue 四大核心组件所组成。</strong><span style="box-sizing: border-box;"> 在核心基础概念小节中,我们已经对这四大核心组件做了相应的介绍,这里就不再赘述了,如果有不清楚的同学,可以到核心基础概念小节中做相应了解。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在一个 RabbitMQ Server 中,只有一个 Virtual Host ,在一个 Virtual Host 中,可以有多个不同名称的 Exchange ,而一个 Exchange 可以与多个 Channel 进行绑定,同时,一个 Queue 也可以和多个 Channel 进行绑定。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">即,</span><strong style="box-sizing: border-box;">在一个 RabbitMQ Server 中,有且只有一个 Virtual Host ,在一个 Virtual Host 中,存在多个 Exchange 和 Channel ,以及多个 Queue ,</strong><span style="box-sizing: border-box;"> 这个对应关系需要同学们知道。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 关于 RabbitMQ 的整体架构,我们只需要了解到这一层次即可,即我们只要知道了 RabbitMQ Server 都是由哪些元素构成的,以及这些元素的包含关系即可。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在对 RabbitMQ 的整体架构有一个宏观了解之后,我们还需要对 RabbitMQ 的消息发送原理也有所了解,知道消息在 RabbitMQ Server 是怎样流转的。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">同样地,RabbitMQ 消息的发送原理也是基于 AMQP 协议中消息的发送原理,结合 AMQP 消息的发送原理(同学们不需要知道),我们可以得出 RabbitMQ 消息的发送原理。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">我们先来看一下,结合 RabbitMQ 整体架构而得出的 RabbitMQ 消息发送原理是怎样的,如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_4__wm.png' data-ratio="0.07597" data-type="png" data-w="803" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_4__wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">由此图,我们可以得出 </span><strong style="box-sizing: border-box;">RabbitMQ 消息发送的步骤:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第一步,生产者将消息生产出来,并将消息发送到 RabbitMQ Server 上,即我们发到 RabbitMQ 中的消息,会首先置于 RabbitMQ Server 中;</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第二步,RabbitMQ Server 根据客户端所发来的连接请求,判断将消息传递到哪个 Virtual Host 中,如果我们在连接 RabbitMQ Server 时,没有设置要连接的 Virtual Host 地址,则 RabbitMQ Server 会将我们的消息传递到地址为 “/” 的 Virtual Host 中去;</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第三步,在将消息传递到对应的 Virtual Host 中后,Virtual Host 会继续解析我们的连接请求,并在这一步解析出我们需要的 Exchange 的类型,以及 Channel 的名称,Queue 的名称,以及消息和 Exchange 之间是否有 routing_key ,Channel 和 Queue 之间是否有 bidding_key 这些信息;</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第四步,Virtual Host 会根据解析出来的这些信息,将消息和 Exchange 进行匹配,相应的,Exchange 也会和对应的 Channel 进行匹配,并最终将 Queue 和 Channel 进行绑定,使消息进入到对应的消息队列中去;</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第五步,待消息进入到对应的消息队列中之后,RabbitMQ Server 会返回给我们一个确认应答(确认应答后续会进行介绍),来通知我们,消息已经成功被 RabbitMQ Server 所发送,于是,消费者变回根据一定的策略来从消息队列中获取消费,并最终将该消息消费掉,消息消费之后,也会给我们返回一个确认应答(确认应答后续会进行介绍),告诉我们消息已经成功消费掉了。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">以上就是 RabbitMQ 进行消息发送的先后步骤,为了更直观地为各位同学呈现 RabbitMQ 的消息发送原理,我做了一个流程图给大家,如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_5_51423_wm.png' data-ratio="0.80851" data-type="png" data-w="564" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_5_51423_wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">同学们可以根据上述步骤,结合流程图进行学习和验证。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_6__wm.png' data-ratio="0.24016" data-type="png" data-w="737" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_6__wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本小节为各位同学介绍了 RabbitMQ 的整体架构,以及 RabbitMQ 的消息发送原理,出于课程设计的初衷,本小节并没有从源码层面对 RabbitMQ 的消息发送原理做深入地剖析,同学们只需要对 RabbitMQ 的消息发送原理做宏观层面上的了解即可。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">通过介绍 RabbitMQ 的整体架构,同学们需要了解 RabbitMQ Server 都由哪些主要元素构成,以及他们之间的包含关系。了解 RabbitMQ 的整体结构以及 RabbitMQ Server 的消息发送步骤是应用好 RabbitMQ 的前提,希望同学们注意。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">Hello,大家好。今天会为同学们介绍 RabbitMQ 中的消息发送模式。RabbitMQ 作为一款消息队列中间件,其提供的消息发送模式必然是 RabbitMQ 的亮点所在。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">理解并掌握 RabbitMQ 中的消息发送模式,是使用 RabbitMQ 进行消息通信的基础,同时也是用好 RabbitMQ 的关键所在,所以,请大家务必掌握本节内容,话不多说,就让我们来看看 RabbitMQ 中都有哪些消息发送模式,以及消息是如何发送的吧。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本节主要内容:</span></p><ul style="margin-top: 0.8em;margin-bottom: 0.8em;padding-left: 30px;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">什么是消息发送模式;</span></p></li><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 中为我们提供了哪些消息发送模式;</span></p></li><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 消息模式详解及注意事项。</span></p></li></ul><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">希望各位同学可以理解本节内容,而不是死记硬背。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">对于消息发送模式这一名词,我们先抛开 RabbitMQ 不说,单从字面意义上去理解,很容易知道,消息发送模式指的就是:</span><strong style="box-sizing: border-box;">消息发送时,所使用的方法或者中间介质,换成大白话就是说,消息是通过什么媒介去进行发送的。</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在 RabbitMQ 中,消息发送模式我们完全可以按照上述所说的来理解,只不过,在 RabbitMQ 中,对消息传输所通过的媒介有专业的术语罢了。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">接下来就让我们来看一下,在 RabbitMQ 中都有哪些消息发送模式。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在 RabbitMQ 中,所有经过 RabbitMQ 来传输的消息,都需要经过 RabbitMQ 的队列来进行传输,至于什么是队列,我在前面的文章中已经讲过,这里不再赘述。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在介绍 RabbitMQ 中都有哪些消息发送模式之前,我们需要首先了解,在 RabbitMQ 中的消息发送模式是如何体现的。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">消息在 RabbitMQ 队列传输的过程中,根据不同的传输方式,以及所使用的队列种类的不同,一共划分了 5 个消息传输模式,而这 5 个消息传输模式,就是我们所说的消息发送模式。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">根据 RabbitMQ 所实现的消息投递方式来划分,可以将消息发送模式分为两大类,分别是点对点模式、发布订阅模式;根据 RabbitMQ 所采用的队列方式以及匹配规则的不同,可以将消息发送模式分为五大类,分别是普通队列模式、工作队列模式、发布订阅模式、直接模式、主题模式。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">由于按照消息投递方式所划分的范围较广,我们不能充分了解每个消息发送模式的内容,所以,在介绍消息发送模式时,我会按照 RabbitMQ 所采用的队列方式和匹配规则的不同来进行讲解,请同学们做好准备。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">我们知道,在 RabbitMQ 中,消息的产生是源自生产者,对应的,消费消息是依靠消费者,而在生产者生产消息到消费者最终消费消息的过程中,消息发送模式扮演着重要的角色。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">如果需要将消息发送模式结合生产者与消费者进行理解的话,那么,我们可以这样来理解:</span><strong style="box-sizing: border-box;">在生产者生产出一条消息后,需要经过 RabbitMQ 的通道来发送给消费者,消费者接收到消息,并最终对消息进行消费,这其中的通道,指的就是 RabbitMQ 的消息发送模式</strong><span style="box-sizing: border-box;">。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">接下来让我们具体来看一下,RabbitMQ 是如何把生产者生产的消息传输给消费者消费的。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">约定:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">由于在本节中所使用的消息发送模式原理图均来自官网,所以图中每个元素都代表什么意思,我在这里一并说过,后面不再赘述:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">天蓝色椭圆 + 其中的字母 P : 代表生产者。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">蓝色的椭圆 + 其中的字母 C + 数字下表 : 代表消费者。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">深蓝色椭圆 + 其中的字母 X : 代表交换机。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">交换机上方的 type : 代表交换机的类型。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">橙色小矩形块所组成的大矩形块 : 代表具体的一个队列。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">图中的箭头,不带字母标识的 : 代表消息的流向。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">图中箭头上的字母标识 : 代表特定模式下的 key 值。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">直接模式,即直接发送消息模式,指的是将消息直接发送给消费者。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">描述:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">直接模式允许将多个队列绑定到一个交换机上,在生产者发送消息给交换机时,需要携带一个 key ,而这个 key 一般被称为 routing key 或者 binding key,所以直接模式有时也被称为路由模式。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> RabbitMQ 一般将这个 key 叫做 binding key,但是在实际情况中,出于字面意思,习惯性地将 key 叫做 routing key</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">直接模式总共分为两种业务场景,我们先来看第一种业务场景,一般被叫做’单 key 绑定’,如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_7__wm.png' data-ratio="0.71642" data-type="png" data-w="670" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_7__wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">从图中我们可以看到,交换机的 type 被声明成了 direct ,这说明我们使用的交换机是直接交换机,即使用的消息发送模式是直接模式;</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">orange、black、green 分别表示不同的两个 routing key ,orange 这一个 key 绑定了一个队列,black、green、两个不同的 key 也绑定了一个队列,这种现象就是直接模式的第一种业务场景,单 key 绑定。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">单 key 绑定的队列,在生产者生产出消息之后,会根据不同 key 指向的不同队列来将消息进行分发,即使是不同的 key 绑定了同一队列。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">我们来看直接模式的最后一个业务场景,多重 key 绑定,如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_8__wm.png' data-ratio="0.98395" data-type="png" data-w="623" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_8__wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在图中我们可以看到,Q1、Q2 两个队列,分别绑定到了 routing key 均为 black 的 direct 交换机上,即名称相同的一个 key 绑定到了多个队列上面,这种现象被称为多重 key 绑定。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在多重 key 绑定下,</span><strong style="box-sizing: border-box;">生产者生产的消息均会被发送到相同 key 值所绑定的队列上面</strong><span style="box-sizing: border-box;">,这里需要同学们注意。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">实现伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 生产者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">basicPublish</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"Routing Key"</span>, ...)</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 消费者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueBind</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"Routing Key"</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们使用 channel 的 basicPublish 方法来指定第二个参数,即我们的 routing key 的名称。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 5 行,我们使用 channel 的 queueBind 方式来将消息队列绑定到名为 Routing Key 的直接模式交换机上。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;">1. 一般,我们在使用 RabbitMQ 时,默认会使用直接模式来发送消息,直接模式也是使用最多的消息发送模式,如果其他消息发送模式不能理解,则务必理解直接模式;</span><span style="box-sizing: border-box;">2. 在使用直接模式时,一定不要忘了指定 routing key ,否则,将不能使用直接模式来发送消息;</span><span style="box-sizing: border-box;">3. 当我们绑定了多个队列到交换机上时,一旦消息被发送,则符合同一 routing key 的队列都会接收到消息。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">发布订阅模式,即生产者发布消息,消费者通过订阅的方式来消费消息。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">其实,发布订阅模式在我看来,不过是给传统的发送和接收起一个高大上的名字罢了,本质上仍热是消息的生产和消费,只不过这种模式更像与发布和订阅,因此得名发布订阅模式。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">描述:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">发布订阅模式只有一种实际的业务场景,我们把他称为群发模式。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_9_.png' data-ratio="0." data-type="png" data-w="263" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_9_.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">上图所示场景也是发布订阅模式中的一种,但是这种模式没有任何存在意义,因为在这种模式下,生产者生产出一条消息之后,将消息直接发送到了交换机上,大家注意看,此时的交换机上没有绑定任何消息队列,所以,此时位于交换机上的消息将丢失,消费者无法拿到消息进行消费。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">接下来让我们看看实际上的发布订阅模式:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_10_51585_wm.png' data-ratio="0.67797" data-type="png" data-w="472" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://image109.360doc.com/DownloadImg/2022/05/0518/_10_51585_wm.png"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">生产者生产一条消息后,将消息首先发送到交换机上,交换机进行检测,发现存在两个队列都绑定在自身上面,于是,将消息全部投递到所绑定的队列上面,最后再由消费者接收消息并消费。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">发布订阅模式的特点,就是一个生产者、一个交换机、多个队列、多个消费者,由于生产者生产出来的消息会发送到绑定在交换机上的所有队列上,这种场景很类似于我们给很多人群发消息,所以,这种模式被叫做群发模式。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">实现伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 生产者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">exchangeDeclare</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"fanout"</span>)</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 消费者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueBind</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">""</span>)</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">basicConsume</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">false</span>, <span style="box-sizing: border-box;color: rgb(0, 0, 0);">consumer</span>)</span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们使用 channel 的 exchangeDeclare 方法,将交换机的类型指定为 fanout 交换机,这是使用发布订阅模式的前提。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 5 行,我们使用 channel 的 queueBind 方法,为交换机绑定一个队列,如果在发布订阅模式下,不绑定消息队列到交换机上,则消息会丢失,消费者接收不到任何消息。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 6 行,我们使用 channel 的 basicConsume 方法,来接收由消息队列发送的消息并消费。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;">1.由于没有绑定队列到交换机上的这种方式会丢失消息,所以在实际工作中,这个方法几乎从不使用,因为没有任何意义;</span><span style="box-sizing: border-box;">2.使用发布订阅模式,在给交换机绑定队列时,不要手动指定队列的 key 值,因为 RabbitMQ 会自动生成相同的 key 值;</span><span style="box-sizing: border-box;">3. 发布订阅模式一般用于不用指定特殊的 key 值,且需要消息批量发送的业务场景。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">普通队列模式,即最简单的消息发送模式,不使用任何交换机,由生产者、队列、消费者组合完成消息的发送和接收。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">描述:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">普通队列模式,由于其操作简单,所以又被称为简单模式,如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_11__wm.png' data-ratio="0." data-type="png" data-w="" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">普通队列模式,在生产者生产完消息之后,直接将消息发送到队列中去,不经过交换机进行处理,然后由消费者直接接收消息并消费。在这个过程中间,没有我们需要特别注意的地方。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">实现伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 生产者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueDeclare</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">false</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">false</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">false</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">null</span>)</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 消费者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">basicConsume</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">true</span>, <span style="box-sizing: border-box;color: rgb(0, 0, 0);">consumer</span>)</span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们使用 channel 的 queueDeclare 方法来为通过绑定消息队列,并指定消息队列的名称。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 5 行,我们是使用 channel 的 basicConsume 方法来直接从队列接收消息,并自动监听消费。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;">1. 普通队列模式操作简单,适合很简单的业务场景,同时,初学者更易于理解。</span><span style="box-sizing: border-box;">2. 由于普通队列模式所能实现的业务场景太过简单,所以在实际业务场景中,很少会用到。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">工作队列模式,和普通队列模式有点像,都是不使用任何交换机,由生产者、队列、消费者组合完成消息的发送和接收,</span><strong style="box-sizing: border-box;">只不过工作队列支持存在多个消费者,而普通队列模式只支持一个消费者。</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">描述:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_12__wm.png' data-ratio="0." data-type="png" data-w="521" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">工作队列模式下,生产者生产出消息后,直接将消息发送到消息队列中,然后多个消费者按照一个随机的顺序来依次接收消息并消费,存在多个消费者消费消息时,下一个消费者只能等待上一个消费者消费结束后才能接收消息并进行消费。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">这就提示我们,在实际工作中,我们可以把费时的业务操作交给 RabbitMQ 去做,这样可以提升代码的执行效率。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">实现伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 生产者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">basicPublish</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">null</span>, <span style="box-sizing: border-box;color: rgb(0, 0, 0);">message</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">getBytes</span>());</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">Thread</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">sleep</span>(<span style="box-sizing: border-box;color: rgb(17, 102, 68);">1000</span>);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 消费者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">Delivery</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">delivery</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">consumer</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">nextDelivery</span>();</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">Thread</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">sleep</span>(<span style="box-sizing: border-box;color: rgb(17, 102, 68);">1000</span>);</span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们使用 channel 的 basicPublish 方法来生成一条消息。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 3 行,在生成一条消息之后,我们等待 1000 毫秒,即 1 秒后再次生成一条消息。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 5 行,我们使用 consumer 的 nextDelivery 方法来依次获取生产者生产的消息。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 6 行,在消费完一条消息之后,我们让下一个消费者等待 1 秒钟,再去消费下一条消息。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;">1.工作队列模式与发布订阅模式有相同之处,既他们都是经过一个队列来向多个消费者发送消息,不同之处在于,前者不用绑定交换机,而后者则需要使用交换机;</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;white-space: pre-wrap;width: inherit;"><span style="box-sizing: border-box;">2.应用工作队列模式,一定要根据实际业务需求和实际业务场景,设置好多个消费者间等待消费消息的时间,如果这个间隔时间设置太久,则容易造成下一个消费者持续等待,严重占用CPU资源,如果设置时间太短,则业务逻辑还没执行完成就开始了下一个消息的消费,这两种业务场景都是不应该出现的</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">主题模式,也被称为通配符模式,官网一般称为主题模式,即交换机与消息队列所绑定的 key 值可以像匹配通配符的方式,来匹配消息队列,到底什么意思呢,我们往下看。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">描述:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_13__wm.png' data-ratio="0.14821" data-type="png" data-w="587" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">主题模式对 routing key 的匹配规则做了改进,上述其他四种模式中有涉及 key 匹配的地方都是完全匹配,即名称必须相等时才能把 key 匹配上,而对于主题模式,则不需要这样。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">主题模式将 key 值中的每个单词或者关键词,使用英文状态下的 . 符号进行间隔,如上图所示。上图中为我们列举了主题模式中支持的所有通配符语法,我们一个一个来介绍:</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 由于 * 号是 MD 语法关键字,所以这里暂时用 ^ 号代替,同学们注意。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">.orange. : 表示在 orange 的两侧可以匹配一个 key 值,例如 123.orange.456 、abc.orange.456 等,但是,abc.orange.456.123 这个是不可以的。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">..rabbit : 用法和上述 orange 相同,例如: 123.abc.rabbit 、abd.acd.rabbit 等。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">lazy.# : 表示在 lazy 的右侧,可以匹配多个 key 值可以进行通配符匹配,例如:lazy.abc.123 等。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">实现伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 生产者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">exchangeDeclare</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"topic"</span>);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">basicPublish</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"key.123"</span>, ...);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 消费者</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueBind</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">QUEUE_NAME</span>, <span style="box-sizing: border-box;color: rgb(0, 0, 0);">EXCHANGE_NAME</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"key.*"</span>);</span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们使用 channel 的 exchangeDeclare 方法,将交换机声明为 topic 类型,这是使用主题模式的必须项。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 3 行,我们使用 channel 的 basicPublish 方法来将消息绑定到交换机上。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 6 行,我们使用 channel 的 queueBind 方法,将消息队列绑定到交换机上,并且设置 key 的匹配策略为 key.* 。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;">1. 使用主题模式一定要很清楚每个通配符所代表的意思,以防用错通配符,引起不必要的错误;</span><span style="box-sizing: border-box;">2. 主题模式为我们提供了类似于模糊搜索的功能,当我们不知道如何设置 key 时,我们可以采用主题模式,同时,主题模式为我们 key 的分组也提供了很好地实现方案。</span><span style="box-sizing: border-box;">3. 使用主题模式时,注意 key 值的命名不要太长,也不要太短。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_14__wm.png' data-ratio="0.64864" data-type="png" data-w="740" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本小节从什么是消息发送模式开始,详细介绍了 RabbitMQ 中的 5 种消息发送模式,对于每一种消息发送模式,采用文字+伪代码+图片的方式进行了全方位的讲解,旨在帮助同学们,通过对本节内容的学习,可以充分了解 RabbitMQ 中都有哪些消息发送模式,以及每种消息发送模式的特点、消息发送原理等。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本小节是用好 RabbitMQ 的基础,在学习本节内容时,一定要理清楚 5 中消息发送模式间的区别与联系,我们只有在充分了解了 RabbitMQ 中的消息发送模式之后,才能很清楚的知道,什么业务场景哪种消息模式最合适,最后,希望同学们学的开心、码的快乐。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">Hello,大家好。本小节为大家介绍 RabbitMQ 中交换机的相关概念,以及交换机的构成及作用。在 RabbitMQ 消息发送原理概述小节中,我们已经对 RabbitMQ 整体架构有了一个初步的了解,已经知道了交换机在 RabbitMQ 中充当的角色,那么本节会继续深入讲解 RabbitMQ 中的交换机。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本节主要内容:</span></p><ul style="margin-top: 0.8em;margin-bottom: 0.8em;padding-left: 30px;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">什么是交换机;</span></p></li><li style="box-sizing: border-box;white-space: pre-wrap;"><p><span style="box-sizing: border-box;">RabbitMQ 常用交换机详解;</span></p></li></ul><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">在 RabbitMQ 中,交换机主要用来将生产者生产出来的消息,传送到对应的频道中,即</span><strong style="box-sizing: border-box;">交换机是一个消息传送的媒介</strong><span style="box-sizing: border-box;">,其英文被称为 exchange 。交换机在 RabbitMQ 中起着承上启下的作用。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">RabbitMQ 根据不同业务场景,为我们内置了多种交换机,但是这些交换机并不是每一种都会用到,常用的交换机也就 3 种,接下来让我们看一下都有哪三种吧。</span></p><figure style="box-sizing: border-box;overflow-x: auto;margin-top: 1.2em;margin-bottom: 1.2em;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><div width="800" style="width: 768px;"><thead style="box-sizing: border-box;background-color: rgb(248, 248, 248);"><tr style="box-sizing: border-box;break-inside: avoid;break-after: auto;border-top: 1px solid rgb(223, 226, 229);"><th style="box-sizing: border-box;border-top-width: 1px;border-bottom: 0px;border-top-color: rgb(223, 226, 229);border-right-color: rgb(223, 226, 229);border-left-color: rgb(223, 226, 229);padding: 6px 13px;text-align: left;"><span style="box-sizing: border-box;">交换机名称</span></th><th style="box-sizing: border-box;border-top-width: 1px;border-bottom: 0px;border-top-color: rgb(223, 226, 229);border-right-color: rgb(223, 226, 229);border-left-color: rgb(223, 226, 229);padding: 6px 13px;text-align: left;"><span style="box-sizing: border-box;">类型</span></th><th style="box-sizing: border-box;border-top-width: 1px;border-bottom: 0px;border-top-color: rgb(223, 226, 229);border-right-color: rgb(223, 226, 229);border-left-color: rgb(223, 226, 229);padding: 6px 13px;text-align: left;"><span style="box-sizing: border-box;">使用频率</span></th></tr></thead><tbody style="box-sizing: border-box;"><tr style="box-sizing: border-box;break-inside: avoid;break-after: auto;border-top: 1px solid rgb(223, 226, 229);"><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">直通交换机</span></td><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">Direct</span></td><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">高</span></td></tr><tr style="box-sizing: border-box;break-inside: avoid;break-after: auto;border-top: 1px solid rgb(223, 226, 229);background-color: rgb(248, 248, 248);"><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">扇形交换机</span></td><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">Fanout</span></td><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">高</span></td></tr><tr style="box-sizing: border-box;break-inside: avoid;break-after: auto;border-top: 1px solid rgb(223, 226, 229);"><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">主题交换机</span></td><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">Topic</span></td><td style="box-sizing: border-box;border-color: rgb(223, 226, 229);padding: 6px 13px;"><span style="box-sizing: border-box;">高</span></td></tr></tbody></div></figure><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">直通交换机,又被叫做直连交换机,即 Direct Exchange ,是可以直接将消息根据特定匹配规则发送到对应的消息队列的交换机,如果匹配规则相同,则一条消息可以被发送到多个对应的消息队列上,而这个</span><strong style="box-sizing: border-box;">匹配规则是通过 routing_key 来进行匹配。</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 省略与 RabbitMQ 服务端建立连接的过程</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 136, 85);">String</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueName</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"test_direct_x"</span>;</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">exchangeDeclare</span>(<span style="box-sizing: border-box;color: rgb(170, 17, 17);">"direct_exchange"</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"direct"</span>);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueDeclare</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueName</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">true</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">false</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">false</span>, <span style="box-sizing: border-box;color: rgb(34, 17, 153);">null</span>);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">代码块1234</span></span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们声明了一个名为 test_direct_x 队列名称,对于直通交换机而言,这个名称就是我们所说的 routing_key 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 3 行,我们使用了 channel 的 exchangeDeclare 方法来声明了一个交换机,其中,该方法的第一个参数表示交换机的名称,第二个参数则表示交换机的类型,这里我们将类型定义为了直连交换机类型,其类型名称为 direct 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 4 行,我们使用了 channel 的 queueDeclare 方法来声明了一个队列,其中,该方法的第一个参数为我们声明的 test_direct_x 队列。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">消息发送流程:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">结合上述代码,直通交换机的消息发送流程如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_15__wm.png' data-ratio="0." data-type="png" data-w="611" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">消息在经过 direct_exchange 交换机之后,会根据名为 test_direct_x 的 routing_key 与相应的消息队列进行匹配,如果消息队列 1 、消息队列 2 、消息队列 3 都与该 routing_key 相匹配,那么我们的消息会全部流转到这三个消息队列中去。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">扇形交换机,即 Fanout Exchange ,是通过类似广播的形式,将消息传递到消息队列中去,与直通交换机不同的是,</span><strong style="box-sizing: border-box;">扇形交换机不需要绑定 routing_key ,会将消息传递到所有与该交换机绑定的消息队列中去。</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 省略与 RabbitMQ 服务端建立连接的过程</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 136, 85);">String</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueName</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"test_fanout_x"</span>;</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">exchangeDeclare</span>(<span style="box-sizing: border-box;color: rgb(170, 17, 17);">"fanout_exchange"</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"fanout"</span>);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueBind</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueName</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"fanout_exchange"</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">""</span>);</span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们声明了一个名为 test_fanout_x 队列。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 3 行,我们使用了 channel 的 exchangeDeclare 方法来声明了一个交换机,其中,该方法的第一个参数表示交换机的名称,第二个参数则表示交换机的类型,这里我们将类型定义为了扇形交换机类型,其类型名称为 fanout 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 4 行,我们使用了 channel 的 queueBind 方法来将交换机与消息队列进行绑定,其中,该方法的第一个参数为我们声明的 test_fanout_x 队列,第二个参数为要绑定的交换机的名称,这里为 fanout_exchange ,对于扇形交换机来说,队列和交换机的绑定是必须的,否则无法传递消息。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">消息发送流程:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">结合上述代码,扇形交换机的消息发送流程如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_16__wm.png' data-ratio="0." data-type="png" data-w="575" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">消息在经过 fanout_exchange 交换机之后,会首先检测有没有已经与该交换机进行绑定的消息队列,如果没有与该交换机进行绑定的消息队列,则消息会自动失效,且跑抛出异常;如果有与该交换进行绑定的消息队列,则 fanout_exchange 交换机会将消息以广播的形式传递到所有的消息队列中去。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">上图中,消息队列 1 、消息队列 2 、消息队列 3 这三个消息队列的名称均为 test_fanout_x ,且均与名为 fanout_exchange 的交换机进行了绑定,所以,消息在经 fanout_exchange 交换机之后,均会被传递到这三个队列中去。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">定义:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">主题交换机,即 Topic Exchange ,是通过 routing_key 与 bidding_key 的匹配规则进行消息传递的一种交换机。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">与直通交换机不同的是,</span><strong style="box-sizing: border-box;">直通交换机中的 routing_key 和 bidding_key 的名称必须保持一致,但是在主题交换机中,bidding_key 会通过一定的规则去匹配 routing_key ,以此将消息发送到相匹配的消息队列中去。</strong></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 交换机与队列之间进行绑定的 key ,被称为 bidding_key ,消息与交换机之间进行绑定的 key ,被称为 routing_key 。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">伪代码:</strong></p><pre spellcheck="false" lang="java" style="box-sizing: border-box;font-family: var(--monospace);font-size: 0.9em;break-inside: avoid;text-align: left;overflow: visible;white-space: normal;background-image: inherit;background-position: inherit;background-size: inherit;background-repeat: inherit;background-attachment: inherit;background-origin: inherit;background-clip: inherit;background-color: rgb(248, 248, 248);border-width: 1px;border-style: solid;border-color: rgb(231, 234, 237);border-radius: 3px;padding: 8px 4px 6px;margin-bottom: 15px;margin-top: 15px;width: inherit;"><div lang="java" style="box-sizing: border-box;height: auto;overflow: hidden;background: inherit;"><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(170, 85, 0);">// 省略与 RabbitMQ 服务端建立连接的过程</span></span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 136, 85);">String</span> <span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueName</span> <span style="box-sizing: border-box;color: rgb(152, 26, 26);">=</span> <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"test.topic.x"</span>;</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">exchangeDeclare</span>(<span style="box-sizing: border-box;color: rgb(170, 17, 17);">"topic_exchange"</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"topic"</span>);</span></pre><pre role="presentation" style="box-sizing: border-box;font-family: inherit;break-inside: avoid;padding-right: 4px;padding-left: 4px;border-radius: 0px;border-top-width: 0px;border-right: none;border-bottom-width: 0px;border-left-width: 0px;background: 0px 0px;font-size: inherit;white-space: pre-wrap;overflow-wrap: break-word;color: inherit;z-index: 2;overflow: visible;word-break: normal;width: inherit;"><span role="presentation" style="box-sizing: border-box;padding-right: 0.1px;"><span style="box-sizing: border-box;color: rgb(0, 0, 0);">channel</span>.<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueBind</span>(<span style="box-sizing: border-box;color: rgb(0, 0, 0);">queueName</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"fanout_exchange"</span>, <span style="box-sizing: border-box;color: rgb(170, 17, 17);">"test.#"</span>);</span></pre></div></pre><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">代码解释:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 2 行,我们声明了一个名为 test.topic.x 的队列。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 3 行,我们使用了 channel 的 exchangeDeclare 方法来声明了一个交换机,其中,该方法的第一个参数表示交换机的名称,第二个参数则表示交换机的类型,这里我们将类型定义为了扇形交换机类型,其类型名称为 topic 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">第 4 行,我们使用了 channel 的 queueBind 方法来将交换机与消息队列进行绑定,其中,该方法的第一个参数为我们声明的 test_fanout_x 队列,第二个参数为要绑定的交换机的名称,这里为 fanout_exchange ,第三个参数为 bidding_key , 这里是 test.# 。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><strong style="box-sizing: border-box;">消息发送流程:</strong></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">结合上述代码,主题交换机的消息发送流程如下图所示:</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_17__wm.png' data-ratio="0." data-type="png" data-w="646" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">消息在经过 topic_exchange 交换机之后,会根据 routing_key 与 bidding_key 的匹配规则检索相匹配的消息队列,如果没有检测到任何相匹配的消息队列,则消息会自动失效;如果检测到存在相匹配的消息队列,则消息均会会被传送到这些消息队列中去。</span></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">上图中,消息队列 1 、消息队列 2 是我们代码所设置的,bidding_key 为 test.# 的两个消息队列,第三个消息队列的 bidding_key 为 #.topic ,根据主题交换机 # 号匹配规则,routing_key 都会与这些 bidding_key 相匹配,消息均会被传递到这三个消息队列中去。</span></p><blockquote style="box-sizing: border-box;margin-top: 0.8em;margin-bottom: 0.8em;border-left-width: 4px;border-left-color: rgb(223, 226, 229);padding-top: 0px;padding-right: 15px;padding-left: 15px;color: rgb(119, 119, 119);font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><p style="box-sizing: border-box;line-height: inherit;orphans: 4;white-space: pre-wrap;width: inherit;"><strong style="box-sizing: border-box;">Tips:</strong><span style="box-sizing: border-box;"> 在主题交换机中,除了 # 号匹配规则之外,还有 . 号匹配规则,他们两个的匹配规则大同小异,这里只对 # 好匹配规则做了介绍,希望同学们在课下可以自行了解 . 号的匹配规则。</span></p></blockquote><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><img doc360img-src='http://image109.360doc.com/DownloadImg/2022/05/0518/_18__wm.png' data-ratio="0." data-type="png" data-w="688" style="box-sizing: border-box;vertical-align: middle;image-orientation: from-image;display: block;margin: auto;" src="http://pubimage.360doc.com/wz/default.gif"></p><p style="box-sizing: border-box;line-height: inherit;orphans: 4;margin-top: 0.8em;margin-bottom: 0.8em;white-space: pre-wrap;width: inherit;font-family: "Open Sans", "Clear Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;font-size: 16px;text-align: start;background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box;">本小节对常用的 3 种 RabbitMQ 中的交换机进行了详细介绍,从不同种类交换机的概念开始,到交换机的伪代码实现,再到不同种交换机的消息发送流程结束,为各位同学详细介绍了直通交换机、扇形交换机、主题交换机的相关概念,以及消息发送流程,旨在帮助同学们可以对 RabbitMQ 中常用的 3 种交换机都有一个系统性地了解。</span></p> </td> </tr> </tbody>
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/153142.html