﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-我的博客-随笔分类-RabbitMQ</title><link>http://www.blogjava.net/qbna350816/category/55056.html</link><description>201103</description><language>zh-cn</language><lastBuildDate>Sat, 13 Aug 2016 15:01:28 GMT</lastBuildDate><pubDate>Sat, 13 Aug 2016 15:01:28 GMT</pubDate><ttl>60</ttl><item><title>RabbitMQ Management HTTP API</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431575.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 13:50:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431575.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431575.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431575.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431575.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431575.html</trackback:ping><description><![CDATA[<h2><span style="font-size: 14px;">原文：</span><a href="http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html" style="cursor: pointer; font-size: 14px; line-height: 1.5;">http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html</a></h2><h2><span style="font-size: 14px;">介绍</span></h2><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;">除了帮助页面，所有URIs只会服务<code style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #ffffaa;">application/json</code>类型的资源，并且需要HTTP基础认证(使用标准RabbitMQ用户数据库). 默认用户是guest/guest.</p><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;">大多数URIs需要虚拟主机名称作为其路径的一部分, 因为名称是虚拟主机的唯一标识符对象. 默认虚拟主机称为"<code style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #ffffaa;">/</code>", 它需要编码为"<code style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #ffffaa;">%2f</code>".</p><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;">PUT一个资源会对其进行创建. 你上传的JSON对象必须有某个键keys (下面文档有描述)，其它的键会被忽略. 缺失键会引发错误.</p><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;">在AMQP中，由于绑定没有名称或IDs，因此我们基于其所有属性人工合成了一个.&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;">由于一般情况下很难预测这个名字, 你可以通过POST一个工厂URI来创建绑定.查看下面的例子.</p><h2><div>注意事项</div></h2><div style="font-family: 微软雅黑; background-color: #ffffff;">这些注意事项适用于当前管理AP的开发版本。在未来，他们将是固定的。</div><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;"><li style="background-color: inherit;"><code style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #ffffaa;">arguments</code>&nbsp;字段会被忽略.你不创建一个队列,交换器或使用参数进行绑定. 带有参数的队列，交换器或绑定也不会显示这些参数．</li><li style="background-color: inherit;">权限偶尔才需要强制执行.如果一个用户能用HTTP API进行认证，那么它们可以做任何事情.</li><li style="background-color: inherit;">从GET请求中返回的对象中包含许多与监控相关的信息. 它们是无证实的，并且将来可能要发生变化.</li></ul><h2>示例</h2><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;">下面有几个快速例子,它们使用了Unix命令行工具<code style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #ffffaa;">curl</code>:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; font-family: 微软雅黑; color: #444444; background-color: #ffffff;"><li style="background-color: inherit;">获取虚拟主机列表:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #00ff00; background-color: black;">$ curl -i -u guest:guest http://localhost:55672/api/vhosts <br />HTTP/1.1 200 OK <br />Server: MochiWeb/1.1 WebMachine/1.7 (participate in the frantic) <br />Date: Tue, 31 Aug 2010 15:46:59 GMT <br />Content-Type: application/json <br />Content-Length: 5  <br />["/"]</pre></li><li style="background-color: inherit;">创建一个新虚拟主机:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #00ff00; background-color: black;">$ curl -i -u guest:guest -H "content-type:application/json" \   -XPUT http://localhost:55672/api/vhosts/foo <br />HTTP/1.1 204 No Content <br />Server: MochiWeb/1.1 WebMachine/1.7 (participate in the frantic) <br />Date: Fri, 27 Aug 2010 16:56:00 GMT <br />Content-Type: application/json <br />Content-Length: 0</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">注意: 你必须将mime类型指定为<code style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #ffffaa;">application/json</code>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">Note: 在上传的JSON对象中，对象名称是不需要的，因为它已经包含在了URI中. 由于一个虚拟主机除了名称外没有其它属性，这意味着你完全不需要指定一个body.</p></li><li style="background-color: inherit;">在默认虚拟主机中创建一个新的交换器:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #00ff00; background-color: black;">$ curl -i -u guest:guest -H "content-type:application/json" \   -XPUT -d'{"type":"direct","auto_delete":false,"durable":true,"arguments":[]}' \   http://localhost:55672/api/exchanges/%2f/my-new-exchange <br />HTTP/1.1 204 No Content <br />Server: MochiWeb/1.1 WebMachine/1.7 (participate in the frantic) <br />Date: Fri, 27 Aug 2010 17:04:29 GMT <br />Content-Type: application/json <br />Content-Length: 0</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">注意: 在PUT或DELETE的响应中， 除非失败了，否则我们绝不会返回一个body.</p></li><li style="background-color: inherit;">再删除它:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #00ff00; background-color: black;">$ curl -i -u guest:guest -H "content-type:application/json" \   -XDELETE http://localhost:55672/api/exchanges/%2f/my-new-exchange <br />HTTP/1.1 204 No Content <br />Server: MochiWeb/1.1 WebMachine/1.7 (participate in the frantic) <br />Date: Fri, 27 Aug 2010 17:05:30 GMT <br />Content-Type: application/json <br />Content-Length: 0</pre></li></ul><h2><div>参考</div></h2><div style="font-family: 微软雅黑; background-color: #ffffff;"><br style="background-color: inherit;" /><table border="1" cellpadding="2" cellspacing="0" style="font-size: inherit; border-collapse: collapse; margin-top: 10px; margin-bottom: 10px; font-family: Verdana, sans-serif; background-color: inherit;"><tbody style="background-color: inherit;"><tr style="background-color: inherit;"><th style="word-break: break-all; border: 1px solid #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">GET</th><th style="word-break: break-all; border: 1px solid #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">PUT</th><th style="word-break: break-all; border: 1px solid #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">DELETE</th><th style="word-break: break-all; border: 1px solid #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;">POST</th><th style="word-break: break-all; border: 1px solid #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 86px; background-color: inherit;">Path</th><th style="word-break: break-all; border: 1px solid #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">Description</th></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/overview</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;"><div style="min-width: 2px; background-color: inherit;">描述整个系统的各种随机信息。</div></td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/connections</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有打开连接的列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/connections/<span style="background-color: inherit;">name</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">一个单独的连接. DELETE它会导致连接关闭.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/channels</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有打开通道的列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/channels/<span style="background-color: inherit;">channel</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">单个通道的详情.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/exchanges</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有交换器的列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/exchanges/<span style="background-color: inherit;">vhost</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">指定虚拟主机中所有交换器列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/exchanges/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">name</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">一个单独的交换器.要PUT一个交换器,你需要一些像下面这样的body:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: inherit;">{"type":"direct","auto_delete":false,"durable":true,"arguments":[]}</pre></td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/exchanges/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">name</span>/bindings</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">指定交换器中的绑定列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/queues</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有队列的列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/queues/<span style="background-color: inherit;">vhost</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">指定虚拟主机中所有队列列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/queues/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">name</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">一个单独队列.要PUT一个队列, 你需要一些像下面这样的body:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: inherit;">{"auto_delete":false,"durable":true,"arguments":[]}</pre></td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/queues/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">queue</span>/bindings</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">指定队列中的所有绑定列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/bindings</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有绑定列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/bindings/<span style="background-color: inherit;">vhost</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">指定虚拟主机上的所有绑定列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/bindings/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">queue</span>/<span style="background-color: inherit;">exchange</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">队列和交换器之间的所有绑定列表. 记住，队列和交换器可以绑定多次!要创建一个新绑定, POST 这个URI.你需要一些像下面这样的body:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: inherit;">{"routing_key":"my_routing_key","arguments":[]}</pre>响应会包含一个<span style="background-color: inherit;">Location</span>&nbsp;header，它会告诉你新绑定的URI.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/bindings/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">queue</span>/<span style="background-color: inherit;">exchange</span>/<span style="background-color: inherit;">props</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">队列和交换器之间的单个绑定.&nbsp;URI的props部分是一个名称，用于由路由键和属性组成的绑定.你可以通过PUT这个URI来创建一个绑定，它比上面POST URI更方便.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/vhosts</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有虚拟主机列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/vhosts/<span style="background-color: inherit;">name</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">单个虚拟主机.由于虚拟主机只有一个名称，因此在PUT时不需要body.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/users</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有用户列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/users/<span style="background-color: inherit;">name</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">单个用户. 要PUT一个用户, 你需要一些像下面这样的body:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: inherit;">{"password":"secret"}</pre></td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/users/<span style="background-color: inherit;">user</span>/permissions</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">指定用户的所有权限列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;"><span style="background-color: inherit;">/api/permissions</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">所有用户的所有权限列表.</td></tr><tr style="background-color: inherit;"><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 98.5px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 58px; background-color: inherit;">X</td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 74px; background-color: inherit;"><br style="background-color: inherit;" /></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-family: monospace; font-size: 12px; width: 86px; background-color: inherit;">/api/permissions/<span style="background-color: inherit;">vhost</span>/<span style="background-color: inherit;">user</span></td><td style="word-break: break-all; border-style: solid; border-color: #999999; padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; color: #444444; font-size: 12px; width: 788px; background-color: inherit;">一个虚拟主机中某个用户的个人权限. 要PUT一个权限,你需要一些像下面这样的body:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: inherit;">{"scope":"client","configure":".*","write":".*","read":".*"}</pre></td></tr></tbody></table></div><img src ="http://www.blogjava.net/qbna350816/aggbug/431575.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 21:50 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431575.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第七部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431570.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 08:24:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431570.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431570.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431570.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431570.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431570.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 3.1.15&nbsp;消息监听器容器配置有相当多的配置SimpleMessageListenerContainer&nbsp;相关事务和服务质量的选项,它们之间可以互相交互．当使用命名空间来配置&lt;rabbit:listener-container/&gt;时，下表显示了容器属性名称和它们等价的属性名称(在括号中)．未被命名空间暴露的属性，以`N/A`表示.Table&nbsp;3.3. 消...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431570.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431570.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 16:24 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431570.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第六部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431567.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 08:07:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431567.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431567.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431567.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431567.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431567.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 3.1.10&nbsp;配置broker介绍AMQP 规范描述了协议是如何用于broker中队列，交换器以及绑定上的.这些操作是从0.8规范中移植的，更高的存在于org.springframework.amqp.core包中的AmqpAdmin 接口中. 那个接口的RabbitMQ 实现是RabbitAdmin，它位于org.springframework.amqp.rabbit.core 包.A...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431567.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431567.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 16:07 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431567.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第五部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431566.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 07:59:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431566.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431566.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431566.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431566.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431566.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 3.1.9&nbsp;Request/Reply 消息介绍AmqpTemplate&nbsp;也提供了各种各样的sendAndReceive&nbsp;方法，它们接受同样的参数选项(exchange, routingKey, and Message)来执行单向发送操作. 这些方法对于request/reply 场景也是有用的，因为它们在发送前处理了必要的"reply-to"属性配置，并能通过它在专...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431566.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431566.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 15:59 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431566.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第四部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431563.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 04:48:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431563.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431563.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431563.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431563.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431563.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Consumer Tags从1.4.5版本开始，你可以提供一种策略来生成consumer tags.默认情况下，consumer tag是由broker来生成的.public　interface ConsumerTagStrategy {      String createConsumerTag(String queue);  }该队列是可用的，所以它可以（可选）在tag中使用。参考Sectio...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431563.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431563.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 12:48 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431563.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第三部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431562.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 04:38:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431562.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431562.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431562.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431562.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431562.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Queue Affinity 和 LocalizedQueueConnectionFactory当在集群中使用HA队列时,为了获取最佳性能,可以希望连接到主队列所在的物理broker. 虽然CachingConnectionFactory&nbsp;可以配置为使用多个broker 地址; 这会失败的，client会尝试按顺序来连接.&nbsp;LocalizedQueueConnectionFac...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431562.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431562.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 12:38 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431562.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第二部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431561.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 04:21:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431561.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431561.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431561.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431561.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431561.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 3.&nbsp;参考这部分参考文档详细描述了组成Sring AMQP的各种组件.&nbsp;main chapter&nbsp;涵盖了开发AMQP应用程序的核心类. 这部分也包含了有关示例程序的章节．3.1&nbsp;使用 Spring AMQP在本章中,我们将探索接口和类，它们是使用Spring AMQP来开发应用程序的必要组件&nbsp;．3.1.1&nbsp;AMQP 抽象介绍Spring ...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431561.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431561.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 12:21 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431561.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring AMQP 1.6完整参考指南-第一部分</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/13/431560.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 13 Aug 2016 04:03:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/13/431560.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431560.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/13/431560.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431560.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431560.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文：http://docs.spring.io/spring-amqp/docs/1.6.0.RELEASE/reference/html/1. 前言Spring AMQP项目将其核心Spring概念应用于基于AMQP消息解决方案的开发中．我们提供了一个发送和接收消息的高级抽象模板．同时，我们也提供了消息驱动POJO的支持.这些包有助于AMQP资源的管理，从而提升依赖注入和声明式配置的使用. 在...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/13/431560.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431560.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-13 12:03 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/13/431560.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>AMQP-0-9-1中文规范</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/12/431554.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Fri, 12 Aug 2016 10:30:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/12/431554.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431554.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/12/431554.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431554.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431554.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1 概述1.1 本文档的目标此文档定义了一个网络协议－高级消息队列协议(AMQP), 它使一致的客户端程序可以与一致的消息中间件服务器进行通信.我们面对的是这个领域有经验的技术读者，同时还提供了足够的规范和指南．技术工程师可以根据这些文档，在任何硬件平台上使用各种编程语言来构建遵从该协议的解决方案。1.2 摘要1.2.1 为什么使用AMQP?AMQP在一致性客户端和消息中间件(也称为"broker...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/12/431554.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431554.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-12 18:30 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/12/431554.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-官方指南-TLS 支持</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/02/431433.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Tue, 02 Aug 2016 14:25:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/02/431433.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431433.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/02/431433.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431433.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431433.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: RabbitMQ内置支持TLS。自RabbitMQ 3.4.0起, 为防止&nbsp;POODLE attack&nbsp;攻击,已经自动禁用了SSLv3.使用TLS时,推荐安装的Erlang/OTP版本为17.5或以上版本. R16版本在某些证书中可以工作,但存在major limitations.必须安装Erlang加密程序,并且保证它能工作.对于那些从源码进行Erlang编译的Windows...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/02/431433.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431433.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-02 22:25 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/02/431433.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-官方指南－RabbitMQ配置</title><link>http://www.blogjava.net/qbna350816/archive/2016/08/02/431415.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Tue, 02 Aug 2016 01:38:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/08/02/431415.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431415.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/08/02/431415.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431415.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431415.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 原文：http://www.rabbitmq.com/configure.htmlRabbitMQ 提供了三种方式来定制服务器:环境变量定义端口，文件位置和名称(接受shell输入,或者在环境配置文件（rabbitmq-env.conf）中设置)配置文件为服务器组件设置权限,限制和集群，也可以定义插件设置.运行时参数和策略可在运行时进行修改集群设置大部分设置都使用前面的两种方法，但本指南会全部讲解...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/08/02/431415.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431415.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-08-02 09:38 <a href="http://www.blogjava.net/qbna350816/archive/2016/08/02/431415.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-官方指南－rabbitmqctl(1) 指南</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/30/431394.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 30 Jul 2016 08:52:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/30/431394.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431394.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/30/431394.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431394.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431394.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; widows: 1;"><h1><span style="line-height: 24px;"><span style="font-size: 14px;"><span style="font-size: 12px;"><span style="font-size: 14px;">名称</span></span></span></span></h1><div title="rabbitmqctl"><div><p style="margin-right: 0px; margin-left: 0px;">rabbitmqctl &#8212; 用于管理中间件的命令行工具</p></div><div><h2><span style="font-size: 14px;">语法</span></h2><p style="margin-right: 0px; margin-left: 0px;">rabbitmqctl [-n&nbsp;<em>node</em>] [-t&nbsp;<em>timeout</em>] [-q] {<em>command</em>} [<em>command options</em>...]</p></div><div><h2><span style="font-size: 14px;">描述</span></h2><p style="margin-right: 0px; margin-left: 0px;">RabbitMQ是AMQP的实现, 后者是高性能企业消息通信的新兴标准. RabbitMQ server是AMQP 中间件健壮的，可扩展的实现.</p><p style="margin-right: 0px; margin-left: 0px;"><strong>rabbitmqctl</strong>&nbsp;用来管理RabbitMQ中间件的命令行工具.它通过连接中间件节点来执行所有操作。</p><p style="margin-right: 0px; margin-left: 0px;"><span style="line-height: 1.5;">如果中间件没有运行，将会显示诊断信息, 不能到达，或因不匹配Erlang cookie而拒绝连接.</span></p></div><div><h2><span style="font-size: 14px;">选项</span></h2><dl><dt><p style="margin-right: 0px; margin-left: 0px;">[-n&nbsp;<em>node</em>]</p><p style="margin-right: 0px; margin-left: 0px;"><span style="line-height: 1.5;">默认节点是"rabbit@server",此处的server是本地主机. 在一个名为"server.example.com"的主机上, RabbitMQ Erlang node 的节点名称通常是rabbit@server (</span><span style="line-height: 1.5;">除非RABBITMQ_NODENAME在启动时设置了非默认值</span><span style="line-height: 1.5;">).&nbsp;</span><span style="line-height: 1.5;"><strong>hostname -s</strong></span><span style="line-height: 1.5;">&nbsp;的输出通常是"@" 标志后的东西.查看rabbitmq-server(1)来了解配置RabbitMQ broker的细节.</span></p></dt><dt><p style="margin-right: 0px; margin-left: 0px;">[-q]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">使用-q标志来启用宁静(quiet)模式，这会一致消息输出.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">[-t&nbsp;<em>timeout</em>]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">操作超时时间（秒为单位）. 只适用于"list" 命令. 默认是无穷大.</p></dd></dl></div><div><h2><span style="font-size: 14px;">命令</span></h2><div><h3><span style="font-size: 14px;">应用程序和集群管理</span></h3><h3><span style="line-height: 1.5;">stop</span><span style="line-height: 1.5;">&nbsp;[</span><em style="line-height: 1.5;">pid_file</em><span style="line-height: 1.5;">]</span></h3><dl><dd><p style="margin-right: 0px; margin-left: 0px;">用于停止运行RabbitMQ的Erlang node.如果指定了pid_file，还将等待指定的过程结束。例如：</p><p style="margin-right: 0px; margin-left: 0px;"><span style="line-height: 1.5;">rabbitmqctl stop</span></p><p style="margin-right: 0px; margin-left: 0px;">此命令会终止RabbitMQ node的运行.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">stop_app</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">停止RabbitMQ application,但Erlang node会继续运行.此命令主要用于优先执行其它管理操作（这些管理操作需要先停止RabbitMQ application），如<span style="line-height: 1.5;">.&nbsp;</span><a href="http://www.rabbitmq.com/man/rabbitmqctl.1.man.html#reset" style="cursor: pointer; line-height: 1.5;"><strong>reset</strong></a><span style="line-height: 1.5;">.例如：</span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl stop_app</pre></dd><dt><p style="margin-right: 0px; margin-left: 0px;">start_app</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">启动RabbitMQ application.</p><p style="margin-right: 0px; margin-left: 0px;">此命令典型用于在执行了其它管理操作之后，重新启动停止的RabbitMQ application。如<a href="http://www.rabbitmq.com/man/rabbitmqctl.1.man.html#reset" style="cursor: pointer;"><strong>reset</strong></a>.例如：</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl start_app</pre><p style="margin-right: 0px; margin-left: 0px;">此命令来指导RabbitMQ node来启动RabbitMQ application.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">wait {<em>pid_file</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">等待RabbitMQ application启动.此命令用来等待RabbitMQ application来启动node。它会等待创建pid文件，然后等待pid文件中的特定pid过程启动，最后等待RabbitMQ&nbsp;<span style="line-height: 1.5;">&nbsp;application 来启动node.&nbsp;</span></p><p style="margin-right: 0px; margin-left: 0px;">pid file是通过<strong>rabbitmq-server</strong>&nbsp;脚本来创建的.默认情况下，它存放于Mnesia目录中. 修改<strong>RABBITMQ_PID_FILE</strong>&nbsp;环境变量可以改变此位置。如：</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl wait /var/run/rabbitmq/pid</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会在RabbitMQ node启动后返回.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">reset</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">将RabbitMQ node还原到最初状态.包括<span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">从所在群集中删除此node,从管理数据库中删除所有配置数据，如已配置的用户和虚拟主机，以及删除所有持久化消息</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">.</span></p><p style="margin-right: 0px; margin-left: 0px;">执行<strong>reset和</strong><strong>force_reset之前，必须停止</strong>RabbitMQ application ,如使用<a href="http://www.rabbitmq.com/man/rabbitmqctl.1.man.html#stop_app" style="cursor: pointer;"><strong>stop_app</strong></a>.</p><p style="margin-right: 0px; margin-left: 0px;">示例:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl reset</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会重设RabbitMQ　node.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">force_reset</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">强制RabbitMQ node还原到最初状态.</p><p style="margin-right: 0px; margin-left: 0px;">不同于<strong>reset</strong>&nbsp;，&nbsp;<strong>force_reset</strong>&nbsp;命令会无条件地重设node,不论当前管理数据库的状态和集群配置是什么. 它只能在数据库或集群配置已损坏的情况下才可使用。</p><p style="margin-right: 0px; margin-left: 0px;"></p><p style="margin-right: 0px; margin-left: 0px;">执行<strong>reset和</strong><strong>force_reset之前，必须停止</strong>RabbitMQ application ,如使用<a href="http://www.rabbitmq.com/man/rabbitmqctl.1.man.html#stop_app" style="cursor: pointer;"><strong>stop_app</strong></a>.</p><p style="margin-right: 0px; margin-left: 0px;">示例:</p><p style="margin-right: 0px; margin-left: 0px;"></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl force_reset</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会重设RabbitMQnode.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">rotate_logs {<em>suffix</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">指示RabbitMQ node循环日志文件.</p><p style="margin-right: 0px; margin-left: 0px;">RabbitMQ 中间件会将原来日志文件中的内容追加到原始名称和后辍的日志文件中，然后再将原始日志文件内容复制到新创建的日志上。实际上，当前日志内容会移到以此后辍结尾的文件上。当目标文件不存在时，将会进行创建。如果不指定后辍，则不会发生循环，日志文件只是重新打开。示例：</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl rotate_logs .1</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ node将日志文件的内容追加到新日志文件（文件名由原日志文件名和.1后辍构成）中。如. rabbit@mymachine.log.1 和 rabbit@mymachine-sasl.log.1. 最后, 日志会在原始位置恢复到新文件中.</p></dd></dl></div><div><h3><span style="font-size: 14px;">集群管理</span></h3><dl><dt><p style="margin-right: 0px; margin-left: 0px;">join_cluster {<em>clusternode</em>} [--ram]</p></dt><dd><dl><dt>clusternode</dt><dd><p style="margin-right: 0px; margin-left: 0px;">加入集群的节点.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">[--ram]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">如果进行了设置，节点将以RAM节点身份加入集群.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">指导节点成为集群中的一员. 在加入集群之前，节点会重置,因此在使用此命令时，必须小心. 这个命令要成功,RabbitMQ应用程序必须先停止,如<a href="http://www.rabbitmq.com/man/rabbitmqctl.1.man.html#stop_app" style="cursor: pointer;"><strong>stop_app</strong></a>.</p><p style="margin-right: 0px; margin-left: 0px;">集群节点可以是两种类型: 磁盘节点(Disc Node) 或 内存节点(RAM Node).磁盘节点会在RAM和磁盘中复制数据, 通过冗余可以防止节点失效事件，并可从断电这种全局事件中进行恢复. RAM节点只在RAM中复制数据(除了队列的内容外，还依赖于队列是否是持久化的或者内容对于内存来说是否过大) ，并主要用于可伸缩性. RAM节点只有当管理资源(如，增加/删除队列,交换机,或绑定)的时候才具有更高的性能.一个集群必须至少有一个磁盘节点，通常来说还不止一个.</p><p style="margin-right: 0px; margin-left: 0px;">默认情况下，节点是磁盘节点.如果你想要创建内存节点,需要提供<strong>--ram</strong>&nbsp;标志.</p><p style="margin-right: 0px; margin-left: 0px;">在执行<strong>cluster</strong>命令之后, 无论何时，当前节点上启动的RabbitMQ 应用程序在节点宕机的情况下，<span style="line-height: 1.5;">会尝试连接集群中的其它节点。</span></p><p style="margin-right: 0px; margin-left: 0px;">要脱离集群, 必须重设(reset)节点. 你也可以通过<strong>forget_cluster_node</strong>&nbsp;命令来远程删除节点.</p><p style="margin-right: 0px; margin-left: 0px;">更多详情，参考<a href="http://www.rabbitmq.com/clustering.html" target="_top" style="cursor: pointer;">集群指南</a>.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl join_cluster hare@elena --ram</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于指示RabbitMQ node以ram节点的形式将&nbsp;<strong>hare@elena</strong>&nbsp;加入集群.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">cluster_status</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">按节点类型来分组展示集群中的所有节点，包括当前运行的节点.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl cluster_status</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会显示集群中的所有节点.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">change_cluster_node_type {disc | ram}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">修改集群节点的类型. 要成功执行此操作，必须首先停止节点，要将节点转换为RAM节点，则此节点不能是集群中的唯一disc节点。</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl change_cluster_node_type disc</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会将一个RAM节点转换为disc节点.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">forget_cluster_node [--offline]</p></dt><dd><dl><dt><p style="margin-right: 0px; margin-left: 0px;">[--offline]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">允许节点从脱机节点中删除. 这只在所有节点都脱机且最后一个掉线节点不能再上线的情况下有用，<span style="line-height: 1.5;">从而防止整个集群从启动。它不能使用在其它情况下，因为这会导致不一致</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">．</span></p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">远程删除一个集群节点.要删除的节点必须是脱机的, 而在删除节点期间节点必须是在线的，除非使用了<strong>--offline</strong>&nbsp;标志.</p><p style="margin-right: 0px; margin-left: 0px;">当使用<strong>--offline</strong>&nbsp;标志时，rabbitmqctl不会尝试正常连接节点;相反，它会临时改变节点以作修改.如果节点不能正常启动的话，这是非常有用的.在这种情况下，节点将变成集群元数据的规范源<span style="line-height: 1.5;">（例如，队列的存在），即使它不是以前的。因此，如果有可能，你应该在最新的节点上使用这个命令来关闭。</span></p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl -n hare@mcnulty forget_cluster_node rabbit@stringer</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会从节点<strong>hare@mcnulty中删除</strong><strong>rabbit@stringer节点</strong>.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">rename_cluster_node {oldnode1} {newnode1} [oldnode2] [newnode2 ...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">支持在本地数据库中重命名集群节点.</p><p style="margin-right: 0px; margin-left: 0px;">此子命令会促使rabbitmqctl临时改变节点以作出修改. 因此本地集群必须是停止的，其它节点可以是在线或离线的．</p><p style="margin-right: 0px; margin-left: 0px;">这个子命令接偶数个参数，成对表示节点的旧名称和新名称.你必须指定节点的旧名称和新名称，因为其它停止的节点也可能在同一时间重命名.</p><p style="margin-right: 0px; margin-left: 0px;">同时停止所有节点来重命名也是可以的(在这种情况下，每个节点都必须给出旧名称和新名称)或一次停止一个节点来重命名(在这种情况下，每个节点只需要被告知其名句是如何变化的).</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl rename_cluster_node rabbit@misshelpful rabbit@cordelia</pre><p style="margin-right: 0px; margin-left: 0px;">此命令来将节点名称<strong>rabbit@misshelpful</strong>&nbsp;重命名为<strong>rabbit@cordelia</strong>.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">update_cluster_nodes {clusternode}</p></dt><dd><dl><dt>clusternode</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用于咨询具有最新消息的节点.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">指示已集群的节点醒来时联系<strong>clusternode</strong>.这不同于<strong>join_cluster</strong>&nbsp;，因为它不会加入任何集群 - 它会检查节点已经以<strong>clusternode</strong>的形式存在于集群中了．</p><p style="margin-right: 0px; margin-left: 0px;">需要这个命令的动机是当节点离线时，集群可以变化.考虑这样的情况，节点Ａ和节点Ｂ都在集群里边，这里节点Ａ掉线了，Ｃ又和Ｂ集群了，然后Ｂ又离开了集群．当Ａ醒来的时候，它会尝试联系Ｂ，但这会失败，因为Ｂ已经不在集群中了.<strong>update_cluster_nodes -n A C</strong>&nbsp;可解决这种场景．</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">force_boot</p></dt><dd><div>确保节点将在下一次启动，即使它不是最后一个关闭的。通常情况下，当你关闭整个<span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">RabbitMQ 集群时，你重启的第一个节点应该是最后一个下线的节点，因为它可以看到其它节点所看不到的事情. 但有时这是不可能的:例如，如果整个集群是失去了电力而所有节点都在想它不是最后一个关闭的．</span></div><p style="margin-right: 0px; margin-left: 0px;">在这种节点掉线情况下，你可以调用<strong>rabbitmqctl force_boot</strong>&nbsp;．这就告诉节点下一次无条件的启动节点.在此节点关闭后，集群的任何变化，它都会丢失．</p><p style="margin-right: 0px; margin-left: 0px;">如果最后一个掉线的节点永久丢失了，那么你需要优先使用<strong>rabbitmqctl forget_cluster_node --offline</strong>,&nbsp;<span style="line-height: 1.5;">因为它可以确保在丢失的节点上掌握的镜像队列得到提升。</span></p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl force_boot</pre><p style="margin-right: 0px; margin-left: 0px;">这可以强制节点下次启动时不用等待其它节点．</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">sync_queue [-p&nbsp;<em>vhost</em>] {queue}</p></dt><dd><dl><dt>queue</dt><dd><div>同步队列的名称</div></dd></dl><p style="margin-right: 0px; margin-left: 0px;">指示未同步slaves上的镜像队列自行同步.同步发生时，队列会阻塞(所有出入队列的发布者和消费者都会阻塞).此命令成功执行后，队列必须是镜像的．</p><p style="margin-right: 0px; margin-left: 0px;">注意，未同步队列中的消息被耗尽后，最终也会变成同步. 此命令主要用于未<span style="line-height: 1.5;">耗尽的队列。</span></p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">cancel_sync_queue [-p&nbsp;<em>vhost</em>] {queue}</p></dt><dd><dl><dt>queue</dt><dd><p style="margin-right: 0px; margin-left: 0px;">取消同步的队列名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">指示同步镜像队列停止同步.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">purge_queue [-p&nbsp;<em>vhost</em>] {queue}</p></dt><dd><dl><dt>queue</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要清除队列的名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">清除队列(删除其中的所有消息).</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_cluster_name {name}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">设置集群名称. 集群名称在client连接时，会通报给client,也可用于federation和shovel插件记录消息的来源地.&nbsp;<span style="line-height: 1.5;">群集名称默认是来自在群集中的第一个节点的主机名，但可以改变。</span></p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl set_cluster_name london</pre><p style="margin-right: 0px; margin-left: 0px;">设置集群名称为"london".</p></dd></dl></div><div><h3><span style="font-size: 14px;">用户管理</span></h3><p style="margin-right: 0px; margin-left: 0px;">注意<strong>rabbitmqctl</strong>&nbsp;管理RabbitMQ 内部用户数据库. 任何来自其它认证后端的用户对于<strong>rabbitmqctl</strong>来说是不可见的.</p><dl><dt><p style="margin-right: 0px; margin-left: 0px;">add_user {<em>username</em>} {<em>password</em>}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要创建的用户名称.</p></dd><dt>password</dt><dd><p style="margin-right: 0px; margin-left: 0px;">设置创建用户登录broker的密码.<span style="line-height: 1.5;">&nbsp; &nbsp; &nbsp; &nbsp;</span></p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">rabbitmqctl add_user tonyg changeit<br /></p><p style="margin-right: 0px; margin-left: 0px;">此命令用于指示RabbitMQ broker 创建一个拥有非管理权限的用户，其名称为<strong>tonyg，</strong>&nbsp;初始密码为<strong>changeit</strong>.</p><p style="margin-right: 0px; margin-left: 0px;"><br /></p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">delete_user {<em>username</em>}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要删除的用户名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如<span style="line-height: 1.5;">:</span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl delete_user tonyg</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于指示RabbitMQ broker删除名为<strong>tonyg的用户</strong></p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">change_password {<em>username</em>} {<em>newpassword</em>}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要修改密码的用户名称.</p></dd><dt>newpassword</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用户的新密码.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl change_password tonyg newpass</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于指定RabbitMQ broker将<strong>tonyg</strong>&nbsp;用户的密码修改为<strong>newpass</strong>.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">clear_password {<em>username</em>}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要清除密码的用户名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl clear_password tonyg</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会指示RabbitMQ broker清除名为tonyg的用户密码.现在，此用户不能使用密码登录(但可以通过SASL EXTERNAL登录，如果配置了的话).</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">authenticate_user {<em>username</em>} {<em>password</em>}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用户的名称.</p></dd><dt>password</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用户的密码.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl authenticate_user tonyg verifyit</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会指示RabbitMQ broker以名称为tonyg，&nbsp;密码为verifyit来进行验证.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_user_tags {<em>username</em>} {<em>tag</em>&nbsp;...}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要设置tag的用户名称.</p></dd><dt>tag</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用于设置0个，1个或多个tags.任何现有的tags都将被删除.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl set_user_tags tonyg administrator</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker用于确保<strong>tonyg</strong>&nbsp;是administrator.当通过AMQP来登录时，这没有什么效果,但用户通过其它的途经来登录时，它可用来管理用户,虚拟主机和权限(如使用管理插件).</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl set_user_tags tonyg</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会指示RabbitMQ broker删除tonyg上的任何现有的tag.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_users</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">列出用户. 每个结果行都包含用户名，其后紧跟用户的tags.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_users</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker列出所有用户.</p></dd></dl></div><div><h3><span style="font-size: 14px;">访问控制</span></h3><p style="margin-right: 0px; margin-left: 0px;">注意<strong>rabbitmqctl</strong>&nbsp;会管理RabbitMQ的内部用户数据库. 无权限的用户将不能使用<strong>rabbitmqctl</strong>.</p><dl><dt><p style="margin-right: 0px; margin-left: 0px;">add_vhost {<em>vhost</em>}</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要创建虚拟主机名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">创建一个虚拟主机.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl add_vhost test</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker来创建一个新的名为test的虚拟主机.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">delete_vhost {<em>vhost</em>}</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要删除的虚拟主机的名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">删除一个虚拟主机.</p><p style="margin-right: 0px; margin-left: 0px;">删除一个虚拟主机，同时也会删除所有交换机，队列，绑定，用户权限，参数和策略.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl delete_vhost test</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker删除名为test的虚拟主机.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_vhosts [<em>vhostinfoitem</em>&nbsp;...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">列出所有虚拟主机.</p><p style="margin-right: 0px; margin-left: 0px;"><strong>vhostinfoitem</strong>&nbsp;参数用于标识哪些虚拟主机应该包含在结果集中.结果集中的列顺序会匹配参数的顺序.<strong>vhostinfoitem</strong>&nbsp;可接受下面的值：</p><dl><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">虚拟主机的名称.</p></dd><dt>tracing</dt><dd><p style="margin-right: 0px; margin-left: 0px;">是否对虚拟主机启用追踪.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">如果没有指定<strong>vhostinfoitem</strong>&nbsp;参数，那么会显示虚拟主机名称.</p><p style="margin-right: 0px; margin-left: 0px;">例如：</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_vhosts name tracing</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于指示RabbitMQ broker显示所有虚拟主机.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_permissions [-p&nbsp;<em>vhost</em>] {<em>user</em>} {<em>conf</em>} {<em>write</em>} {<em>read</em>}</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">授予用户可访问的虚拟机名称，默认是<strong>/</strong>.</p></dd><dt>user</dt><dd><p style="margin-right: 0px; margin-left: 0px;">可访问指定虚拟主机的用户名称.</p></dd><dt>conf</dt><dd><p style="margin-right: 0px; margin-left: 0px;">一个用于匹配用户在哪些资源名称上拥有配置权限的正则表达式</p></dd><dt>write</dt><dd><p style="margin-right: 0px; margin-left: 0px;">一个用于匹配用户在哪些资源名称上拥有写权限的正则表达式.</p></dd><dt>read</dt><dd><p style="margin-right: 0px; margin-left: 0px;">一个用于匹配用户在哪些资源名称上拥有读权限的正则表达式.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">设置用户权限.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl set_permissions -p /myvhost tonyg "^tonyg-.*" ".*" ".*"</pre><p style="margin-right: 0px; margin-left: 0px;">此命令表示RabbitMQ broker授予<strong>tonyg</strong>&nbsp;用户可访问&nbsp;<strong>/myvhost虚拟主机</strong>,并在资源名称以"tonyg-"开头的所有资源上都具有配置权限，并在所有资源上都拥有读写权限。</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">clear_permissions [-p&nbsp;<em>vhost</em>] {<em>username</em>}</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用于设置禁止用户访问的虚拟主机名称,默认为<strong>/</strong>.</p></dd><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">禁止访问特定虚拟主机的用户名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">设置用户权限.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl clear_permissions -p /myvhost tonyg</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于指示RabbitMQ broker禁止tonyg&nbsp;用户访问/myvhost虚拟主机.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_permissions [-p&nbsp;<em>vhost</em>]</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用于指定虚拟主机名称，将会列出所有可访问此虚拟主机的所有用户名称和权限.默认为<strong>/</strong>.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">显示虚拟机上权限.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_permissions -p /myvhost</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker列出所有已授权访问<strong>/myvhost&nbsp;</strong>虚拟主机的用户，同时也会列出这些用户能在虚拟主机资源可操作的权限.注意，空字符串表示没有任何授予的权限。</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_user_permissions {<em>username</em>}</p></dt><dd><dl><dt>username</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要显示权限的用户名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">列出用户权限.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_user_permissions tonyg</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker列出tonyg可授权访问的所有虚拟主机名称，以及在这些虚拟主机上的操作.</p></dd></dl></div><div><h3><span style="font-size: 14px;">参数管理</span></h3><p style="margin-right: 0px; margin-left: 0px;"><span style="line-height: 1.5;">RabbitMQ的某些特性(如联合插件)是动态控制的</span>. 每个参数都是与特定虚拟主机相关的组件名称, name和value构成的. 组件名称和name都是字符串,值是Erlang term. 参数可被设置，清除和显示.通常你可以参考文档来了解如何设置参数.</p><dl><dt><p style="margin-right: 0px; margin-left: 0px;">set_parameter [-p&nbsp;<em>vhost</em>] {<em>component_name</em>} {<em>name</em>} {<em>value</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">设置一个参数.</p><dl><dt>component_name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要设置的组件名称.</p></dd><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要设置的参数名称.</p></dd><dt>value</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要设置的参数值，作不JSON项。在多数shells中，你更喜欢将其引起来.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl set_parameter federation local_username '"guest"'</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于在默认虚拟主机上设置<strong>federation</strong>&nbsp;组件的<strong>local_username 参数值</strong><strong>"guest"</strong>.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">clear_parameter [-p&nbsp;<em>vhost</em>] {<em>component_name</em>} {<em>key</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">清除参数.</p><dl><dt>component_name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要清除参数的组件名称.</p></dd><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要清除的参数名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl clear_parameter federation local_username</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于清除默认虚拟主机上的<strong>federation</strong>&nbsp;组件的<strong>local_username</strong>&nbsp;参数值.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_parameters [-p&nbsp;<em>vhost</em>]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">列出虚拟主机上的所有参数.</p><p style="margin-right: 0px; margin-left: 0px;">示例:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_parameters</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于列出默认虚拟主机上的所有参数.</p></dd></dl></div><div><h3><span style="font-size: 14px;">策略管理</span></h3><p style="margin-right: 0px; margin-left: 0px;">策略用于在<span style="line-height: 1.5;">集群范围的基础上用于控制和修改队列和交换机的行为.</span><span style="line-height: 1.5;">&nbsp;策略应用于虚拟主机,由name, pattern, definition或可选的priority组成. 策略可被设置，清除和列举.</span></p><dl><dt><p style="margin-right: 0px; margin-left: 0px;">set_policy [-p&nbsp;<em>vhost</em>] [--priority&nbsp;<em>priority</em>] [--apply-to&nbsp;<em>apply-to</em>] {<em>name</em>} {<em>pattern</em>} {<em>definition</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">设置策略.</p><dl><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">策略名称.</p></dd><dt>pattern</dt><dd><p style="margin-right: 0px; margin-left: 0px;">正则表达式, 匹配要应用的资源</p></dd><dt>definition</dt><dd><p style="margin-right: 0px; margin-left: 0px;">策略的定义,JSON形式．在大多数shells中，<span style="line-height: 1.5;">你很可能需要引用这个</span></p></dd><dt>priority</dt><dd><p style="margin-right: 0px; margin-left: 0px;">策略的整数优先级. 数字越高则优先级越高.默认是０.</p></dd><dt>apply-to</dt><dd><p style="margin-right: 0px; margin-left: 0px;">策略适用的对象类型，其值可为 "queues", "exchanges" 或 "all".默认是"all".</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl set_policy federate-me "^amq." '{"federation-upstream-set":"all"}'</pre><p style="margin-right: 0px; margin-left: 0px;">此命令在默认虚拟主机上设置策略为<strong>federate-me，</strong>这样内建的交换器将进行联合.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">clear_policy [-p&nbsp;<em>vhost</em>] {<em>name</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">清除策略.</p><dl><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要清除的策略名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl clear_policy federate-me</pre><p style="margin-right: 0px; margin-left: 0px;">此命令来清除默认虚拟主机上的<strong>federate-me</strong>&nbsp;策略.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_policies [-p&nbsp;<em>vhost</em>]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">显示虚拟主机上的所有策略.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_policies</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会显示默认虚拟主机上的所有策略.</p></dd></dl></div><div><h3><span style="font-size: 14px;">服务器状态</span></h3><p style="margin-right: 0px; margin-left: 0px;"><span style="line-height: 1.5;">服务器状态查询查询服务器返回一个结果以制表符分隔的列表</span>. 某些查询(<strong>list_queues</strong>,&nbsp;<strong>list_exchanges</strong>,&nbsp;<strong>list_bindings</strong>, 和&nbsp;<strong>list_consumers</strong>) 接受一个可选的<strong>vhost</strong>&nbsp;参数. 如果这个参数出现了，那么它必须指定在查询的后面.</p><p style="margin-right: 0px; margin-left: 0px;">list_queues, list_exchanges and list_bindings 命令接受一个可选的虚拟主机参数以显示其结果．默认值为"/".</p><dl><dt><p style="margin-right: 0px; margin-left: 0px;">list_queues [-p&nbsp;<em>vhost</em>] [<em>queueinfoitem</em>&nbsp;...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">返回队列的详细信息. 如果无-p标志，将显示／虚拟主机上的队列详情．"-p" 标志可用来覆盖此默认值．</p><p style="margin-right: 0px; margin-left: 0px;"><strong>queueinfoitem</strong>&nbsp;参数用于指示哪些队列信息项会包含在结果集中.结果集的列顺序将匹配参数的顺序.<strong>queueinfoitem</strong>&nbsp;可以是下面列表中的任何值:</p><dl><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">非ASCII字符的队列名称.</p></dd><dt>durable</dt><dd><p style="margin-right: 0px; margin-left: 0px;">服务器重启后，队列是否能幸存.</p></dd><dt>auto_delete</dt><dd><p style="margin-right: 0px; margin-left: 0px;">不再使用时，是否需要自动删除队列.</p></dd><dt>arguments</dt><dd><p style="margin-right: 0px; margin-left: 0px;">队列参数.</p></dd><dt>policy</dt><dd><p style="margin-right: 0px; margin-left: 0px;">应用到队列上的策略名称.</p></dd><dt>pid</dt><dd><p style="margin-right: 0px; margin-left: 0px;">关联队列的Erlang进程ID.</p></dd><dt>owner_pid</dt><dd><p style="margin-right: 0px; margin-left: 0px;">表示队列专用所有者的代表连接的Erlang进程ID.如果队列是非专用的，此值将为空．</p></dd><dt>exclusive</dt><dd><p style="margin-right: 0px; margin-left: 0px;">True:如果队列是专用的(即有owner_pid), 反之false</p></dd><dt>exclusive_consumer_pid</dt><dd><p style="margin-right: 0px; margin-left: 0px;">表示此channel的专用消费者订阅到此队列的Erlang进程Id. 如果没有专用消费者，则为空．</p></dd><dt>exclusive_consumer_tag</dt><dd><p style="margin-right: 0px; margin-left: 0px;">专用消费者订阅到此队列的Consumer tag.如果没有专用消费者，则为空.</p></dd><dt>messages_ready</dt><dd><p style="margin-right: 0px; margin-left: 0px;">准备分发给客户端的消息数目.</p></dd><dt>messages_unacknowledged</dt><dd><p style="margin-right: 0px; margin-left: 0px;">分发到客户端但尚未应答的消息数目.</p></dd><dt>messages</dt><dd><p style="margin-right: 0px; margin-left: 0px;">准备分发和未应答消息的总和(队列深度).</p></dd><dt>messages_ready_ram</dt><dd><p style="margin-right: 0px; margin-left: 0px;">驻留在ram中messages_ready的消息数目.</p></dd><dt>messages_unacknowledged_ram</dt><dd><p style="margin-right: 0px; margin-left: 0px;">驻留在ram中messages_unacknowledged的消息数目.</p></dd><dt>messages_ram</dt><dd><p style="margin-right: 0px; margin-left: 0px;">驻留在ram中的消息总数.</p></dd><dt>messages_persistent</dt><dd><p style="margin-right: 0px; margin-left: 0px;">队列中持久化消息的数目(对于瞬时队列总是0).</p></dd><dt>message_bytes</dt><dd><p style="margin-right: 0px; margin-left: 0px;">队列中所有消息体的大小总和.这不包括消息属性(包括headers)&nbsp;<span style="line-height: 1.5;">或任何开销(overhead)。</span></p></dd><dt>message_bytes_ready</dt><dd><p style="margin-right: 0px; margin-left: 0px;">类似于<strong>message_bytes</strong>&nbsp;，但只统计准备投递给clients的那些消息．</p></dd><dt>message_bytes_unacknowledged</dt><dd><p style="margin-right: 0px; margin-left: 0px;">类似于<strong>message_bytes</strong>&nbsp;，但只统计那些已经投递给clients但还未应答的消息</p></dd><dt>message_bytes_ram</dt><dd><p style="margin-right: 0px; margin-left: 0px;">类似于<strong>message_bytes</strong>&nbsp;，但只统计那些在RAM中的消息</p></dd><dt>message_bytes_persistent</dt><dd><p style="margin-right: 0px; margin-left: 0px;">类似于<strong>message_bytes</strong>&nbsp;，但只统计那些持久化的消息</p></dd><dt>head_message_timestamp</dt><dd><p style="margin-right: 0px; margin-left: 0px;">如果存在，只显示队列中第１个消息的timestamp属性. 消息的时间戳只出现在分页情况下．</p></dd><dt>disk_reads</dt><dd><p style="margin-right: 0px; margin-left: 0px;">从队列启动开如，已从磁盘上读取该队列的消息总次数.</p></dd><dt>disk_writes</dt><dd><p style="margin-right: 0px; margin-left: 0px;">从队列启动开始，已向磁盘队列写消息总次数.</p></dd><dt>consumers</dt><dd><p style="margin-right: 0px; margin-left: 0px;">消费者数目.</p></dd><dt>consumer_utilisation</dt><dd><p style="margin-right: 0px; margin-left: 0px;">时间分数(0.0与1.0之间)，队列可立即向消费者投递消息. 它可以小于1.0，如果消费者受限于网络堵塞或预提取数量.</p></dd><dt>memory</dt><dd><p style="margin-right: 0px; margin-left: 0px;">与队列相关的Erlang进程消耗的内存字节数,包括栈,堆以及内部结构.</p></dd><dt>slave_pids</dt><dd><p style="margin-right: 0px; margin-left: 0px;">如果队列是镜像的，这里给出的是当前slaves的IDs.</p></dd><dt>synchronised_slave_pids</dt><dd><p style="margin-right: 0px; margin-left: 0px;">如果队列是镜像的，当前slaves的IDs是master同步的- 即它们可在无消息丢失的情况下，接管master.</p></dd><dt>state</dt><dd><p style="margin-right: 0px; margin-left: 0px;">队列状态.正常情况下是'running', 但如果队列正在同步也可能是"{syncing, MsgCount}". 处于集群下的节点如果掉线了，队列状态交显示'down' (大多数<strong>queueinfoitem</strong>s 将不可用).</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">如果没有指定<strong>queueinfoitem</strong>s，那么将显示队列名称和队列深度．</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_queues -p /myvhost messages consumers</pre><p style="margin-right: 0px; margin-left: 0px;">此命令显示了<strong>/myvhost</strong>虚拟主机中每个队列的深度和消费者数目.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_exchanges [-p&nbsp;<em>vhost</em>] [<em>exchangeinfoitem</em>&nbsp;...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">返回交换器细节.如果没有指定"-p"选项，将返回&nbsp;<strong>/</strong>&nbsp;虚拟主机的细节. &nbsp;"-p" 选项可用来覆盖默认虚拟主机.</p><p style="margin-right: 0px; margin-left: 0px;"><strong>exchangeinfoitem</strong>&nbsp;参数用来表示哪些交换器信息要包含在结果中. 结果集中列的顺序将与参数顺序保持一致.&nbsp;<strong>exchangeinfoitem</strong>&nbsp;可接受下面的列表中任何值：</p><dl><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">交换器名称.</p></dd><dt>type</dt><dd><p style="margin-right: 0px; margin-left: 0px;">交换器类型(如[<strong>direct</strong>,&nbsp;<strong>topic</strong>,&nbsp;<strong>headers</strong>,&nbsp;<strong>fanout</strong>]).</p></dd><dt>durable</dt><dd><p style="margin-right: 0px; margin-left: 0px;">当服务器重启时，交换器是否能复活.</p></dd><dt>auto_delete</dt><dd><p style="margin-right: 0px; margin-left: 0px;">当不再使用时，交换器是否需要自动删除.</p></dd><dt>internal</dt><dd><p style="margin-right: 0px; margin-left: 0px;">交换器是否是内部的，即不能由client直接发布.</p></dd><dt>arguments</dt><dd><p style="margin-right: 0px; margin-left: 0px;">交换器参数</p></dd><dd><p style="margin-right: 0px; margin-left: 0px;"><br /></p></dd><dd></dd><dt><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">policy<br /></span></dt></dl></dd><dd><p style="margin-right: 0px; margin-left: 0px;"></p></dd><dt><span style="line-height: 1.5;">应用到交换器上的策略名称.</span></dt><p style="margin-right: 0px; margin-left: 0px;"></p></dl><p style="margin-right: 0px; margin-left: 0px;">如果没有指定<strong>exchangeinfoitem</strong>s，那么将会显示交换器类型和类型</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_exchanges -p /myvhost name type</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会显示<strong>/myvhost</strong>中每个交换器的名称和类型.</p><dt><p style="margin-right: 0px; margin-left: 0px;">list_bindings [-p&nbsp;<em>vhost</em>] [<em>bindinginfoitem</em>&nbsp;...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">返回绑定细节.默认情况下返回的是&nbsp;<strong>/</strong>&nbsp;虚拟主机上的绑定详情.可使用"-p" 标记来覆盖默认虚拟主机.</p><p style="margin-right: 0px; margin-left: 0px;"><strong>bindinginfoitem</strong>&nbsp;参数用来表示结果中包含哪些绑定信息. 结果集中列的顺序将匹配参数的顺序.<strong>bindinginfoitem</strong>可接受下面列表的任意值:</p><dl><dt>source_name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">绑定中消息来源的名称.&nbsp;C中非ASCII转义字符.</p></dd><dt>source_kind</dt><dd><p style="margin-right: 0px; margin-left: 0px;">绑定中消息来源的类别.当前总是exchange.&nbsp;C中非ASCII转义字符.</p></dd><dt>destination_name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">绑定中消息目的地名称.C中非ASCII转义字符.</p></dd><dt>destination_kind</dt><dd><p style="margin-right: 0px; margin-left: 0px;">绑定中消息目的地的种类.&nbsp;C中非ASCII转义字符.</p></dd><dt>routing_key</dt><dd><p style="margin-right: 0px; margin-left: 0px;">绑定的路由键,C中非ASCII转义字符.</p></dd><dt>arguments</dt><dd><p style="margin-right: 0px; margin-left: 0px;">绑定参数.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">如果没有指定<strong>bindinginfoitem</strong>s，将会显示所有上述条目．</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_bindings -p /myvhost exchange_name queue_name</pre><p style="margin-right: 0px; margin-left: 0px;">此命令来显示<strong>/myvhost</strong>虚拟主机上绑定的交换器名称和队列名称.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_connections [<em>connectioninfoitem</em>&nbsp;...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">返回TCP/IP连接统计.</p><p style="margin-right: 0px; margin-left: 0px;"><strong>connectioninfoitem</strong>&nbsp;参数用来表示在结果中包含哪些连接信息.&nbsp;结果集中列的顺序将匹配参数的顺序.&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong>connectioninfoitem</strong>可接受下面列表的任意值:</p><dl><dt>pid</dt><dd><p style="margin-right: 0px; margin-left: 0px;">与连接相关的Erlang进程ID.</p></dd><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">连接的可读名称.</p></dd><dt>port</dt><dd><p style="margin-right: 0px; margin-left: 0px;">服务器端口.</p></dd><dt>host</dt><dd><p style="margin-right: 0px; margin-left: 0px;">返回反向DNS获取的服务器主机名称，或 IP地址(反向DNS解析失败) 或者未启用．</p></dd><dt>peer_port</dt><dd><p style="margin-right: 0px; margin-left: 0px;">Peer 端口.</p></dd><dt>peer_host</dt><dt>　　　返回反向DNS获取的Peer主机名称，或 IP地址(反向DNS解析失败) 或者未启用．</dt><dt>ssl</dt><dd><p style="margin-right: 0px; margin-left: 0px;">用Boolean来表示连接是否是SSL的.</p></dd><dt>ssl_protocol</dt><dd><p style="margin-right: 0px; margin-left: 0px;">SSL 协议(如. tlsv1)</p></dd><dt>ssl_key_exchange</dt><dd><p style="margin-right: 0px; margin-left: 0px;">SSL key exchange 算法 (如 rsa)</p></dd><dt>ssl_cipher</dt><dd><p style="margin-right: 0px; margin-left: 0px;">SSL cipher 算法 (如aes_256_cbc)</p></dd><dt>ssl_hash</dt><dd><p style="margin-right: 0px; margin-left: 0px;">SSL hash 函数 (如 sha)</p></dd><dt>peer_cert_subject</dt><dd><p style="margin-right: 0px; margin-left: 0px;">peer的 SSL 安全证书的主体, RFC4514形式．</p></dd><dt>peer_cert_issuer</dt><dd><p style="margin-right: 0px; margin-left: 0px;">peer的 SSL安全证书的发行者, RFC4514 形式.</p></dd><dt>peer_cert_validity</dt><dd><p style="margin-right: 0px; margin-left: 0px;">peer的SSL安全证书的有效期.</p></dd><dt>state</dt><dd><p style="margin-right: 0px; margin-left: 0px;">连接状态(可为[<strong>starting</strong>,&nbsp;<strong>tuning</strong>,&nbsp;<strong>opening</strong>,&nbsp;<strong>running</strong>,&nbsp;<strong>flow</strong>,&nbsp;<strong>blocking</strong>,&nbsp;<strong>blocked</strong>,&nbsp;<strong>closing</strong>,&nbsp;<strong>closed</strong>]其中一个).</p></dd><dt>channels</dt><dd><div>使用连接的<span style="font-family: 'Microsoft Yahei';">channel</span>数。</div></dd><dt>protocol</dt><dd><p style="margin-right: 0px; margin-left: 0px;">使用的AMQP协议版本(当前是<strong>{0,9,1}</strong>&nbsp;或<strong>{0,8,0}</strong>). 注意，如果client请求的是AMQP 0-9 连接, 我们会视为AMQP 0-9-1.</p></dd><dt>auth_mechanism</dt><dd><p style="margin-right: 0px; margin-left: 0px;">使用的SASL认证机制,如<strong>PLAIN</strong>.</p></dd><dt>user</dt><dd><p style="margin-right: 0px; margin-left: 0px;">与连接相关的用户名</p></dd><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">虚拟主机名称，Ｃ中非ASCII转义字符.</p></dd><dt>timeout</dt><dd><p style="margin-right: 0px; margin-left: 0px;">连接超时／协商的心跳间隔,秒为单位.</p></dd><dt>frame_max</dt><dd><p style="margin-right: 0px; margin-left: 0px;">最大 frame 大小(字节).</p></dd><dt>channel_max</dt><dt><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">&nbsp; &nbsp; &nbsp; &nbsp; 此连接上channel的最大数目.</span></dt><dt>client_properties</dt><dd><p style="margin-right: 0px; margin-left: 0px;">连接建立期间由client发送的信息属性.</p></dd><dt>recv_oct</dt><dd><p style="margin-right: 0px; margin-left: 0px;">Octets已收到.</p></dd><dt>recv_cnt</dt><dd><p style="margin-right: 0px; margin-left: 0px;">Packets&nbsp;已收到.</p></dd><dt>send_oct</dt><dd><p style="margin-right: 0px; margin-left: 0px;">Octets 发送.</p></dd><dt>send_cnt</dt><dd><p style="margin-right: 0px; margin-left: 0px;">Packets 发送.</p></dd><dt>send_pend</dt><dd><p style="margin-right: 0px; margin-left: 0px;">发送队列大小.</p></dd><dt>connected_at</dt><dd><p style="margin-right: 0px; margin-left: 0px;">连接建立的日期和时间,当作timestamp.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">如果没有<strong>connectioninfoitem</strong>s， 那么会显示user, peer host, peer port,<span style="line-height: 1.5;">流量控制和内存块状态的时间</span></p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_connections send_pend port</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会显示发送队列的大小以及第个连接的服务器端口．</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_channels [<em>channelinfoitem</em>&nbsp;...]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">返回所有当前channel上的信息,逻辑容器执行大部分 AMQP命令.这将包含最初AMQP连接的部分，以及不同插件和其它扩展创建的channels.</p><p style="margin-right: 0px; margin-left: 0px;"><strong>channelinfoitem</strong>&nbsp;参数用来表示在结果集中包含哪些channel信息．结果集中列的顺序将匹配参数的顺序.&nbsp;<strong>channelinfoitem</strong>&nbsp;可接受下面列表中的任何一个参数：</p><dl><dt>pid</dt><dd><p style="margin-right: 0px; margin-left: 0px;">与连接相关的Erlang进程ID.</p></dd><dt>connection</dt><dd><p style="margin-right: 0px; margin-left: 0px;">channel所属的连接Erlang进程ID.</p></dd><dt>name</dt><dd><p style="margin-right: 0px; margin-left: 0px;">channel的可读名称.</p></dd><dt>number</dt><dd><p style="margin-right: 0px; margin-left: 0px;">channel的数目，在一个连接中，它有唯一的标识符．</p></dd><dt>user</dt><dd><p style="margin-right: 0px; margin-left: 0px;">与channel相关的用户名称.</p></dd><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">channel操作的虚拟主机.</p></dd><dt>transactional</dt><dd><p style="margin-right: 0px; margin-left: 0px;">True：如果channel处于事务模式,其它情况为false.</p></dd><dt>confirm</dt><dd><p style="margin-right: 0px; margin-left: 0px;">True：如果channel是确认模式，其它情况为false.</p></dd><dt>consumer_count</dt><dd><p style="margin-right: 0px; margin-left: 0px;">在channel中接收消息的逻辑AMQP消费者数目．</p></dd><dt>messages_unacknowledged</dt><dd><p style="margin-right: 0px; margin-left: 0px;">在channel中消息已投递但还未应答的消息数目．</p></dd><dt>messages_uncommitted</dt><dd><p style="margin-right: 0px; margin-left: 0px;">在channel中已收到消息但还没有提交事务的消息个数．</p></dd><dt>acks_uncommitted</dt><dd><div>确认收到一个还未提交的事务数。</div></dd><dt>messages_unconfirmed</dt><dd><div>尚未确认已发布消息的数目。在通道不在确认模式下时，这将是0。</div></dd><dt>prefetch_count</dt><dd><p style="margin-right: 0px; margin-left: 0px;">新消费者QoS预提取限制, 0表示无上限.</p></dd><dt>global_prefetch_count</dt><dd><p style="margin-right: 0px; margin-left: 0px;">整个channel　QoS预提取限制, 0表示无上限.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">如果没有指定<strong>channelinfoitem</strong>s，那么将显示pid, user, consumer_count,messages_unacknowledged．</p><p style="margin-right: 0px; margin-left: 0px;"><br /></p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl list_channels connection messages_unacknowledged</pre><p style="margin-right: 0px; margin-left: 0px;">此命令会显示每个channel中连接进程和未应答消息的数目.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">list_consumers [-p&nbsp;<em>vhost</em>]</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">列举消费者, 即订阅队列的消息流. 每行将打印出由制表符分隔的已订阅队列的名称，<span style="line-height: 1.5;">创建并管理订阅的channel进程的标识,channel中订阅的</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">consumer tag唯一标识符, boolean值表示投递到此消费者的消息是否需要应答,整数值表示表示预提取限制(为０表示无限制), 以及关于此消费者的任何其它参数．</span></p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">status</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">显示 broker 状态信息，如当前Erlang节点上运行的应用程序, RabbitMQ 和 Erlang 的版本信息, OS 名称, 内存和文件描述符统计信息. (查看<strong>cluster_status</strong>&nbsp;命令来找出那些节点是集群化的以及正在运行的.)</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl status</pre><p style="margin-right: 0px; margin-left: 0px;">此命令显示了RabbitMQ broker的相关信息.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">environment</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">显示每个运行程序环境中每个变量的名称和值.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">report</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">为所有服务器状态生成一个服务器状态报告，输出应该重定向到一个文件.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl report &gt; server_report.txt</pre><p style="margin-right: 0px; margin-left: 0px;">此命令创建了一个服务器报告，可将它附着在支持请求的电子邮件中．</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">eval {<em>expr</em>}</p></dt><dd><p style="margin-right: 0px; margin-left: 0px;">执行任意Erlang表达式.</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl eval 'node().'</pre><p style="margin-right: 0px; margin-left: 0px;">此命令用于返回rabbitmqctl连接的节点名称</p></dd></div><div><h3><span style="font-size: 14px;">杂项</span></h3><dl><dt><p style="margin-right: 0px; margin-left: 0px;">close_connection {<em>connectionpid</em>} {<em>explanation</em>}</p></dt><dd><dl><dt>connectionpid</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要关闭的与连接相关的Erlang进程ID.</p></dd><dt>explanation</dt><dd><p style="margin-right: 0px; margin-left: 0px;">解释字符串.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">指示broker关闭与Erlang进程id相关的连接(可通过<a href="http://www.rabbitmq.com/man/rabbitmqctl.1.man.html#list_connections" style="cursor: pointer;"><strong>list_connections</strong></a>&nbsp;命令查看), 通过为连接客户端传递解释字符串(作为AMQP连接关闭协议的一部分).</p><p style="margin-right: 0px; margin-left: 0px;">例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">rabbitmqctl close_connection "&lt;rabbit@tanto.4262.0&gt;" "go away"</pre><p style="margin-right: 0px; margin-left: 0px;">此命令指示RabbitMQ broker关闭与Erlang 进程id&lt;rabbit@tanto.4262.0&gt;相关联的连接, 同时向客户端传递go away字符串.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">trace_on [-p&nbsp;<em>vhost</em>]</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要开启追踪的虚拟主机的名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">开启追踪.注意，追踪状态不是持久化的; 如果服务器重启，追踪状态将会丢失.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">trace_off [-p&nbsp;<em>vhost</em>]</p></dt><dd><dl><dt>vhost</dt><dd><p style="margin-right: 0px; margin-left: 0px;">要停止追踪的虚拟主机名称.</p></dd></dl><p style="margin-right: 0px; margin-left: 0px;">停止追踪.</p></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_vm_memory_high_watermark {<em>fraction</em>}</p></dt><dd><dl><dt>fraction</dt><dd><div>当一个浮点数大于或等于0时，会触发流量控制新内存阈值部分。</div></dd></dl></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_vm_memory_high_watermark absolute {<em>memory_limit</em>}</p></dt><dd><dl><dt>memory_limit</dt><dd><p style="margin-right: 0px; margin-left: 0px;">流程控制触发的新内存限制, 以字节来表示大于或等于０的整数或以字符串和内存单位来表示(如 512M或1G). 可用的单位是: k, kiB: kibibytes (2^10 bytes) M, MiB: mebibytes (2^20) G, GiB: gibibytes (2^30) kB: kilobytes (10^3) MB: megabytes (10^6) GB: gigabytes (10^9)</p></dd></dl></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_disk_free_limit {<em>disk_limit</em>}</p></dt><dd><dl><dt>disk_limit</dt><dd><p style="margin-right: 0px; margin-left: 0px;">以整数或字符串单位的可用磁盘下限限制(查看vm_memory_high_watermark), 如 512M or 1G. 一旦可用磁盘空间达到这个限制，就会设置磁盘报警.</p></dd></dl></dd><dt><p style="margin-right: 0px; margin-left: 0px;">set_disk_free_limit mem_relative {<em>fraction</em>}</p></dt><dd><dl><dt>fraction</dt><dd><p style="margin-right: 0px; margin-left: 0px;">相对于整个可用内存的限制，其值为非负浮点数. 当值小于１.０时是很危险的，应该谨慎使用．</p></dd><dd><div></div></dd></dl></dd></dl></div></div></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/431394.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-30 16:52 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/30/431394.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-官方指南－产品清单</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/30/431393.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 30 Jul 2016 08:47:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/30/431393.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431393.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/30/431393.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431393.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431393.html</trackback:ping><description><![CDATA[<div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.875;">原文：<a href="http://www.rabbitmq.com/production-checklist.html"><span style="color: #0000ff;">http://www.rabbitmq.com/production-checklist.html</span></a></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.875;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">介绍</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">像RabbitMQ这样的数据服务经常有许多的可调参数．某些配置对于开发环境来说是意义的，但却不适合产品环境. 单个配置不能满足每种使用情况. 因此，在进入产品环境时，评估配置是很重要的. 这就是本指南提供帮助的目的．</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">虚拟主机，用户，权限</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">Virtual Hosts</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在单租户环境中，例如，当RabbitMQ在产品环境中只致力于为某单个系统服务时，使用默认虚拟主机 (</span><span style="color:#333333;background-color:#ffffff">/</span><span style="color:#555555;background-color:#ffffff">)是非常好的.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在多租户环境中，为每个租户／环境使用单独的虚拟主机，如：</span><span style="color:#333333;background-color:#ffffff">project1_development</span><span style="color:#555555;background-color:#ffffff">,&nbsp;</span><span style="color:#333333;background-color:#ffffff">project1_production</span><span style="color:#555555;background-color:#ffffff">,&nbsp;</span><span style="color:#333333;background-color:#ffffff">project2_development</span><span style="color:#555555;background-color:#ffffff">,&nbsp;</span><span style="color:#333333;background-color:#ffffff">project2_production</span><span style="color:#555555;background-color:#ffffff">, 等等.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">用户</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在产品环境中，删除默认用户(</span><span style="color:#333333;background-color:#ffffff">guest</span><span style="color:#555555;background-color:#ffffff">). 默认情况下，默认用户只能通过本地来连接, 因为它有众所周的凭证.为了不启用远程连接,可考虑使用带有administrative权限和生成密码的独立用户来代替</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">强烈建议在每个程序中使用单独的用户,例如，如果你有一个mobile app, 一个Web app, 和一个数据聚合系统, 你最好有３个独立的用户. 这会使许多事情变得更简单:</span></div><ul yne-block-type="list"><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">使 client 连接与程序相关联</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">使用细粒度的权限</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">凭据翻滚(如. 周期性地或遭到破坏的情况下)</span></li></ul><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;">如果有许多相同应用程序的实例，有一个更好安全性权衡（每一个实例的凭据）和方便的配置（共享一些或所有实例之间的一组凭据）。物联网的应用涉及很多客户执行相同或相似的功能，有固定的IP地址，它可以使用X509证书或源IP地址范围验证。</div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">资源限制</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当消费者跟不上的时候，RabbitMQ 使用</span><a href="http://www.rabbitmq.com/alarms.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Resource-driven alarms</span></a><span style="color:#555555;background-color:#ffffff">&nbsp;(资源驱动报警)来压制(throttle）发布者. 在进入生产之前评估资源限制配置是重要的。</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">内存</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">默认情况下， RabbitMQ会使用可用RAM的40%． 这专门针对于那些运行RabbitMQ的节点，通常情况下，提高此限制是合理的. 然而，应注意的是，操作系统和文件系统的缓存也需要内存来运行。如果不这样做，会由于操作系统交换导致严重的吞吐量下降，甚至导致操作系统会终止RabbitMQ过程的运行。</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">下面是一些基本的指导方针，用于确定推荐的</span><a href="http://www.rabbitmq.com/memory.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">RAM limit</span></a><span style="color:#555555;background-color:#ffffff">:</span></div><ul yne-block-type="list"><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">至少有128 MB</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当RAM达到4GB时，可配置为75%的RAM限制</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当RAM达到4GB－8GB时，可配置为80%的RAM限制</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当RAM达到8GB－16GB时，可配置为85%的RAM限制</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当RAM大于16GB时，可配置为90%的RAM限制</span></li></ul><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">高于0.9的值是很危险的，不推荐配置</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">可用磁盘空间</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">必要的可用磁盘空间可防止</span><a href="http://www.rabbitmq.com/disk-alarms.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">disk space alarms</span></a><span style="color:#555555;background-color:#ffffff">.(磁盘空间报警) ．默认情况下，RabbitMQ始终需要 50 MiB的可用磁盘空间.在大多数Linux发行者，根据开发者的经验，可将放置到小分区的</span><span style="color:#333333;background-color:#ffffff">/var</span><span style="color:#555555;background-color:#ffffff">&nbsp;目录下. 然而，对于产品环境来说，这不是一个推荐值, 因为它们可能明显的更高的RAM 限制. 下面是一些基本的指导方针，如何确定有多少空闲磁盘空间是推荐的:</span></div><ul yne-block-type="list"><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">至少有2 GB</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当限制为1到8GB的RAM时，可配置为RAM限制的50％</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当限制为8到32GB的RAM时，可配置为RAM限制的40%</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当限制超过32GB的RAM时，可配置为RAM限制的30%</span></li></ul><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.5;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#ffffff">rabbit.disk_free_limit</span><span style="color:#555555;background-color:#ffffff">&nbsp;配置可通过&nbsp;</span><span style="color:#333333;background-color:#ffffff">{mem_relative, N}来完成，使其相对于</span><span style="color:#555555;background-color:#ffffff">RAM限制的百分比来计算. 例如, 使用</span><span style="color:#333333;background-color:#ffffff">{mem_relative, 0.5}</span><span style="color:#555555;background-color:#ffffff">&nbsp;设为50%,&nbsp;</span><span style="color:#333333;background-color:#ffffff">{mem_relative, 0.25}</span><span style="color:#555555;background-color:#ffffff">设为25%等等.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">打开文件句柄限制</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;">操作系统限制了并发打开的文件句柄的最大数量，其中包括网络套接字。确保您的限制设置得足够高，以允许预期数量的并发连接和队列。</div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;">对于有效RabbitMQ用户，确保你的环境允许至少50K的打开文件描述符，包括开发环境。</div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">作为经验法则,并发连接数的95%乘以２再加上队列的总数可以计算出打开文件句柄限制( multiple the 95th percentile number of concurrent connections by 2 and add total number of queues to calculate recommended open file handle limit). 值高于500K也是恰当地，它不会消耗太多的硬件资源，因此建议在生产环境中设置. 查看</span><a href="http://www.rabbitmq.com/networking.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Networking guide</span></a><span style="color:#555555;background-color:#ffffff">&nbsp;来了解更多信息.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">安全注意事项</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">用户和权限</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">查看vhosts, users, 和 证书章节.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">Erlang Cookie</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在Linux 和BSD 系统中, 有必要限制只有运行RabbitMQ和rabbitmqctl工具的用户才能访问</span><a href="http://www.rabbitmq.com/clustering.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Erlang cookie</span></a><span style="color:#555555;background-color:#ffffff">.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">TLS</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">如果有可能，我们建议使用</span><span style="background-color:#ffffff;font-weight:bold">Ｔ</span><a href="http://www.rabbitmq.com/ssl.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">LS connections</span></a><span style="color:#555555;background-color:#ffffff">， 至少要加密通信. Peer验证（身份验证）也被推荐 . 开发和QA 环境可使用</span><a href="https://github.com/michaelklishin/tls-gen/"><span style="color:#444444;background-color:#ffffff;font-weight:bold">self-signed TLS certificates</span></a><span style="color:#555555;background-color:#ffffff">. 当RabbitMQ和所有程序运行在可信网络或隔离(使用像VMware NSX技术)环境中时，自签名证书可以应用于产品环境．</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">虽然RabbitMQ试图提供一个默认的安全TLS 配置 (如．SSLv3是禁用的), 我们推荐评估TLS 版本和密码套件. 请参考</span><a href="http://www.rabbitmq.com/ssl.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">TLS guide</span></a><span style="color:#555555;background-color:#ffffff">&nbsp;了解更多信息.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">网络配置</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">产品环境需要调整网络配置．请参考&nbsp;</span><a href="http://www.rabbitmq.com/networking.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Networking Guide</span></a><span style="color:#555555;background-color:#ffffff">&nbsp;来了解细节.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">自动连接恢复</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">某些client libraries, 例如&nbsp;</span><a href="http://www.rabbitmq.com/api-guide.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Java</span></a><span style="color:#555555;background-color:#ffffff">,&nbsp;</span><a href="http://www.rabbitmq.com/dotnet-api-guide.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">.NET</span></a><span style="color:#555555;background-color:#ffffff">, 和&nbsp;</span><a href="http://rubybunny.info/"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Ruby</span></a><span style="color:#555555;background-color:#ffffff">, 在网络失败后，支持自动连接恢复．如果client提供了这种功能，建议使用它来代替你自己的恢复机制.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">集群化考虑</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">集群大小</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当确定集群大小时，需要重点考虑下面的几个因素：</span></div><ul yne-block-type="list"><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">希望的吞吐量</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">希望的复制( mirrors的数目)</span></li><li style="list-style-type: disc; list-style-position: inside; white-space: pre-wrap; text-align: left; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">数据局部性</span></li></ul><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.5;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">因为客户端可以连接到任何节点，RabbitMQ可能需要进行集群间消息路由和内部操作。尝试使消费者和生产者连接到同一个节点，如果可能的话：这将减少节点间的流量。 使消费者连接到持有队列的master上(可使用HTTP API进行推断)，也是有帮助的.</span><span style="background-color:#ffffff">当考虑到数据局部性时，总的集群吞吐量可以达到不平凡的量</span><a href="interm"><span style="color:interm;background-color:#ffffff">。</span></a></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">对于大多数环境中，镜像超过一半的群集节点是足够的。建议使用一个奇数的节点（3，5，等等）的集群。</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">分区处理策略</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在用于产品环境之前，挑选</span><a href="http://www.rabbitmq.com/partitions.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">partition handling strategy</span></a><span style="color:#555555;background-color:#ffffff">&nbsp;是很重要的. </span><span style="color:interm;background-color:#ffffff">有疑问时，使用theautoheal策略。</span></div><img src ="http://www.blogjava.net/qbna350816/aggbug/431393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-30 16:47 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/30/431393.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-官方指南－内存报警</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/30/431392.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 30 Jul 2016 07:05:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/30/431392.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431392.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/30/431392.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431392.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431392.html</trackback:ping><description><![CDATA[原文：<a href="http://www.rabbitmq.com/memory.html">http://www.rabbitmq.com/memory.html<br /><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.875;"><span style="color:#555555;background-color:#ffffff">RabbitMQ服务器在启动时以及</span><span style="color:#333333;background-color:#ffffff">abbitmqctl set_vm_memory_high_watermark&nbsp;</span><span style="color:#333333;background-color:#ffffff;font-style:italic">fraction</span><span style="color:#555555;background-color:#ffffff">&nbsp;执行时，会检查计算机的RAM总大小. 默认情况下下, 当 RabbitMQ server 的使用量超过RAM的40% ，它就会发出内存警报，并阻塞所有连接. 一旦内存警报清除 (如，服务器将消息转存于磁盘，或者将消息投递给clients),服务又地恢复.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.875;"><span style="color:#555555;background-color:#ffffff">默认内存阀值设置为已安装RAM的40%. 注意这并不会阻止RabbitMQ server使用内存量超过40%, 它只是为了压制发布者． Erlang的垃圾回收器最坏情况下，可使用配置内存的２倍(默认情况下t, RAMr的80%）. 因此强制建议开启OS swap或page files .</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">32位架构倾向于每一个进程有2GB的内存限制. 64位架构的一般实现(i.e. AMD64 和 Intel EM64T) 只允许每个进程为256TB. 64-位 Windows 限制为8TB. 但是，请注意，即使是64位操作系统下，一个32位的过程往往只有一个2GB的最大地址空间。</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">配置内存阀值</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">内存阀值可通过编辑</span><a href="http://www.rabbitmq.com/configure.html#configuration-file"><span style="color:#444444;background-color:#ffffff;font-weight:bold">configuration file</span></a><span style="background-color:#ffffff;font-weight:bold">来配置</span><span style="color:#555555;background-color:#ffffff">.下面的例子将阀值设为默认值0.4:</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">[{rabbit, [{vm_memory_high_watermark, 0.4}]}].</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">默认值0.4 代表的是已安装RAM的 40% , 有时候还更小.如：在 32位平台中，如果你安装有４GB RAM , 4GB 的40% 是 1.6GB, 但是 32-位 Windows 正常情况下限制进程为2GB,因此实际阀值是2GB的40%  (即820MB).</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">另外, 内存阀值也可以设置为绝对值. 下面的例子将阀值设为了1073741824 字节 (1024 MB):</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">[{rabbit, [{vm_memory_high_watermark, {absolute, 1073741824}}]}].</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">同例, 也可使用内存单位:</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">[{rabbit, [{vm_memory_high_watermark, {absolute, "1024MiB"}}]}].</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">如果绝对上限大于了安装的RAM可用的虚拟地址空间, 阀值上限会略小.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当RabbitMQ服务器启动时，内存限制将追加到</span><span style="background-color:#ffffff">RABBITMQ_NODENAME</span><span style="color:#555555;background-color:#ffffff">.log 文件中：</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">=INFO REPORT==== 29-Oct-2009::15:43:27 === Memory limit set to 2048MB.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">内存限制也可以使用</span><span style="color:#333333;background-color:#ffffff">rabbitmqctl　status命令查询</span><span style="color:#555555;background-color:#ffffff">．</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">其阀值也可以在broker运行时，通过</span><span style="color:#333333;background-color:#ffffff">rabbitmqctl set_vm_memory_high_watermark&nbsp;</span><span style="color:#333333;background-color:#ffffff;font-style:italic">fraction</span><span style="color:#555555;background-color:#ffffff">&nbsp;命令或&nbsp;</span><span style="color:#333333;background-color:#ffffff">rabbitmqctl set_vm_memory_high_watermark absolute&nbsp;</span><span style="color:#333333;background-color:#ffffff;font-style:italic">memory_limit</span><span style="color:#555555;background-color:#ffffff">&nbsp;命令修改. 内存单位也可以在命令中使用. 此命令会在broker重启后生效. 当执行此命令时，内存限制可能会改变热插拔RAM，而不会发生报警，这是因为需要全部数量的系统RAM.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">禁止所有发布</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">其值为０时，会立即触发报警并禁用所有发布 (当需要禁用全局发布时，这可能是有用的); use&nbsp;</span><span style="color:#333333;background-color:#ffffff">rabbitmqctl set_vm_memory_high_watermark 0</span><span style="color:#555555;background-color:#ffffff">.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">限制的地址空间</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">当在６４位操作系统中运行３２位 Erlang VM时，(or a 32 bit OS with PAE), 可用地址内存是受限制的. 服务器探测到后会记录像下边的日志消息:</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">=WARNING REPORT==== 19-Dec-2013::11:27:13 === Only 2048MB of 12037MB memory usable due to limited address space. Crashes due to memory exhaustion are possible - see http://www.rabbitmq.com/memory.html#address-space</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">内存报警系统是不完美的.虽然停止发布通常会防止任何进一步的内存使用，但可能有其他东西继续增加内存使用。通常情况下，当这种情况发生时，物理内存耗尽，操作系统将开始交换。但是当运行一个有限的地址空间，超过限制的运行会导致虚拟机崩溃。</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">因此强制建议在在６４位操作系统上运行６４位的Erlang VM.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">配置分页阈值</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在broker达到最高水位阻塞发布者之前,它会尝试将队列内容分页输出到磁盘上来释放内存. 持久化和瞬时消息都会分页输出 (已经在磁盘上的持久化消息会被赶出内存).</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">默认情况下，在达最高水位的５０％时，就会发生这种情况． (即，默认最高水位为0.4, 这会在内存使用达到20%时就会发生). 要修改此值，可修改</span><span style="color:#333333;background-color:#ffffff">vm_memory_high_watermark_paging_ratio</span><span style="color:#555555;background-color:#ffffff">&nbsp;配置的0.5默认值. 例如:</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">[{rabbit, [{vm_memory_high_watermark_paging_ratio, 0.75},          {vm_memory_high_watermark, 0.4}]}].</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">上面的配置表示在内存使用达到３０％时，就会启动,40%的时候会阻塞发布者.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">也可以将</span><span style="color:#333333;background-color:#ffffff">vm_memory_high_watermark_paging_ratio</span><span style="color:#555555;background-color:#ffffff">&nbsp;值设为大于</span><span style="color:#333333;background-color:#ffffff">1.0的值</span><span style="color:#555555;background-color:#ffffff">.在这种情况下，队列不会把它的内容分页到磁盘上.如果这引起了内存报警关闭，那么生产者会如上面预期的一样被阻塞.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#ff6600;background-color:#ffffff;font-weight:bold">未确认的平台</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">如果RabbitMQ服务器不能识别你的系统，它将在</span><span style="background-color:#ffffff">RABBITMQ_NODENAME</span><span style="color:#555555;background-color:#ffffff">.log 文件中追加警告. </span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">然后它会假设安装了超过了1GB的RAM:</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#333333;background-color:#eeeeee">=WARNING REPORT==== 29-Oct-2009::17:23:44 === Unknown total memory size for your OS {unix,magic_homebrew_os}. Assuming memory size is 1024MB.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">在这种情况下，</span><span style="color:#333333;background-color:#ffffff">vm_memory_high_watermark</span><span style="color:#555555;background-color:#ffffff">&nbsp;配置值假设为1GB RAM. 在&nbsp;</span><span style="color:#333333;background-color:#ffffff">vm_memory_high_watermark</span><span style="color:#555555;background-color:#ffffff">&nbsp;默认设为 0.4的情况下, RabbitMQ的内存阀值设为了410MB, 因此当RabbitMQ使用了多于410M内存时，它会阻塞生产者.因此当RabbitMQ不能识别你的平台时，如果你实际有8GB RAM，并且你想让RabbitMQ内存使用量超过3GB阻塞生产者,你可以设置</span><span style="color:#333333;background-color:#ffffff">vm_memory_high_watermark为</span><span style="color:#555555;background-color:#ffffff">3.</span></div><div yne-bulb-block="paragraph" style="white-space: pre-wrap; line-height: 1.38462;"><span style="color:#555555;background-color:#ffffff">推荐RAM 水位设置，可参考</span><a href="http://www.rabbitmq.com/production-checklist.html"><span style="color:#444444;background-color:#ffffff;font-weight:bold">Production Checklist</span></a><span style="color:#555555;background-color:#ffffff">.</span></div><br /></a><img src ="http://www.blogjava.net/qbna350816/aggbug/431392.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-30 15:05 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/30/431392.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第12章-管理RabbitMQ错误条件</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/20/431254.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Wed, 20 Jul 2016 03:39:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/20/431254.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431254.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/20/431254.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431254.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431254.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;">在本章中，我们将涵盖下面的主题:</span><br style="background-color: inherit;" /><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">监控</span><span style="line-height: 1.5; background-color: inherit;">RabbitMQ的行为</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">使用</span><span style="line-height: 1.5; background-color: inherit;">RabbitMQ进行故障诊断</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">跟踪</span><span style="line-height: 1.5; background-color: inherit;">RabbitMQ当前活动</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">调试</span><span style="line-height: 1.5; background-color: inherit;">RabbitMQ的消息</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">当RabbitMQ重启失败时该做什么</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">使用Wireshark来调试</span></li></ol></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;">介绍</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;">每当我们开发一个应用程序的时候，一种常见的做法是开发一个诊断基础设施</span><span style="background-color: inherit;"><span style="background-color: inherit;">. 这可以基于日志文件，SNMP 转移以及其它手段.<br style="background-color: inherit;" /><span style="background-color: inherit;">RabbitMQ提供了标准日志文件和内建消息故障诊断解决方案<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">在前面三个食谱中，我们将看到如何来使用这三种特性.<br style="background-color: inherit;" /><span style="background-color: inherit;">某些时候，会存在一些阻止RabbitMQ启动的问题.在这种情况下，需要强制解决服务器上的问题并重启服务器。这一点，我们将在RabbitMQ重启失败时该做什么食谱中讲解。</span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;">然而,调试消息也是应用程序开发的一部分.在这种情况下,</span><span style="line-height: 1.5; background-color: inherit;">我们需要知道RabbitMQ和客户之间交换的准确信息</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.可以使用一个内建代理工具(Java client API的一部分)</span><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">&nbsp;(查看调试<span style="background-color: inherit;"><em style="background-color: inherit;">RabbitMQ的消息食谱</em><span style="background-color: inherit;">)或者使用高级网络监视工具来检查网络状况，正如我们将在使用<em>Wireshark来调试食谱中看到的一样。</em></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;">监控RabbitMQ行为</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;">为了检查RabbitMQ的正常行为，有一个监控工具是很有用的，特别是在处理集群的时候<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">有许多不同的工具，商业的或免费的,&nbsp;</span></span></span><span style="line-height: 1.5; background-color: inherit;">这有助于让它们受控于分布式系统如Nagios、Zabbix之下</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.</span><br style="background-color: inherit;" /><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">在本食谱中，我们将展示如何配置Ganglia&nbsp;&nbsp;RabbitMQ 插件<span style="background-color: inherit;"><span style="background-color: inherit;">(<span style="background-color: inherit;">http://<span style="background-color: inherit;">sourceforge.net/apps/trac/ganglia/wiki/ganglia_quick_start<span style="background-color: inherit;">).</span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;">准备</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;">为了运行此食谱,你需要启用管理插件来配置RabbitMQ。同时，你也需要安装和配置<span style="background-color: inherit;"><span style="background-color: inherit;">Ganglia. 在本食谱中，我们使用的版本是3.6.0.</span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;">如何做</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;">为了使用Ganglia监控图形来查看RabbitMQ统计数据，你需要执行下面的步骤：<span style="background-color: inherit;"><br style="background-color: inherit;" /><span style="background-color: inherit;">1. 在你的Linux发行版上，使用yum或apt-get安装和配置Ganglia<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">.你需要下面的包:<br style="background-color: inherit;" /><span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">ganglia-gmetad<br style="background-color: inherit;" /><span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">ganglia-gmond<br style="background-color: inherit;" /><span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">ganglia-gmond-python<br style="background-color: inherit;" /><span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">ganglia-web<br style="background-color: inherit;" /><span style="background-color: inherit;">&nbsp;<span style="background-color: inherit;">ganglia<br style="background-color: inherit;" /><span style="background-color: inherit;">2. 从https://github.com/ganglia/gmond_python_modules/blob/master/rabbit/python_modules/rabbitmq.py拷贝Python Ganglia监控插件到<span style="background-color: inherit;">/usr/lib64/ganglia/python_<span style="background-color: inherit;">modules<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">3.&nbsp;<span style="background-color: inherit;"><span style="background-color: inherit;">从h<span style="background-color: inherit;">ttps://github.com/ganglia/gmond_python_modules/blob/master/<span style="background-color: inherit;">rabbit/conf.d/rabbitmq.pyconf拷贝<span style="background-color: inherit;">Python Ganglia 配置文件到/etc/ganglia/conf.d&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="background-color: inherit;">4. 检查配置文件中的参数正确性.实际上,&nbsp;</span><span style="line-height: 1.5; background-color: inherit;">你可能需要通过只留下默认的虚拟主机来解决以下条目</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">:</span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">paramvhost {<br style="background-color: inherit;" /><span style="background-color: inherit;">value = "/"<br style="background-color: inherit;" /><span style="background-color: inherit;">}<br style="background-color: inherit;" /><span style="background-color: inherit;">5.如果它已经运行了，使用下面的命令来重启<span style="background-color: inherit;">gmond<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;">service gmond restart</span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;">如何工作</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;">通过这个食谱</span><span style="background-color: inherit;">, 你可以从Ganglia环境中来监控RabbitMQ<span style="background-color: inherit;">.</span><br style="text-align: -webkit-auto; background-color: inherit;" /></span>TIP</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;">对于基本的故障诊断，你可以通过日志文件来进行，默认情况下，日志文件存储于<span style="background-color: inherit;"><span style="background-color: inherit;">/var/log/rabbitmq<span style="background-color: inherit;">.</span></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><br style="background-color: inherit;" /></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">一旦它运行起来，你就可以从同一个web界面中，看到系统信息和RabbitMQ节点、队列的相关信息，如下面的截图所示：<br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qbna350816/121.png" width="1060" height="372" alt="" /><br /></span></span></span></span><div><font face="Microsoft Yahei" style="background-color: inherit;">更多</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">Ganglia</span></font><span style="line-height: 1.5; background-color: inherit;">是集群监测一种广泛的解决方案，但不是唯一的一个。<font face="Microsoft Yahei" style="background-color: inherit;">其它的解决方案还包括</font></span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">Nagios (</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">www.nagios.org), Zabbix (www.zabbix.com), 以及Puppet (puppetlabs.com).</span></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">通过RabbitMQ排除故障</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">正如前面食谱提到的, 我们可以通过一种便利的方式，即以日志文件的方式来监控RabbitMQ行为<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">也可以使用RabbitMQ自身来访问同种信息, 通过向<span style="background-color: inherit;">AMQP client通知broker的活动.</span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">准备</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">要运行本食谱，我们需要运行RabbitMQ以及Java client library.<br style="text-align: -webkit-auto; background-color: inherit;" /></span>如何做</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">为了消费日志消息，你可在<span style="background-color: inherit;">Consumer.java中执行主方法<span style="background-color: inherit;">.你可在<span style="background-color: inherit;"><span style="background-color: inherit;">Chapter12/Recipe02/Java/src/<span style="background-color: inherit;">rmqexample中找到源友<span style="background-color: inherit;">. 下面，我们将高亮主要步骤:<br style="background-color: inherit;" /><span style="background-color: inherit;">1. 创建一个临时匿名队列，并将其绑定到AMQP log交换器:<br style="background-color: inherit;" /><span style="background-color: inherit;">String tmpQueue = channel.queueDeclare().getQueue();<br style="background-color: inherit;" /><span style="background-color: inherit;">channel.queueBind(tmpQueue,"amq.rabbitmq.log","#");<br style="background-color: inherit;" /><span style="background-color: inherit;">2. 在消费者回调(<span style="background-color: inherit;">ActualConsumer.java<span style="background-color: inherit;">)中,可以检索消息和每个消息的路由键，并将它们打印出来<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;">String routingKey = envelope.getRoutingKey();<br style="background-color: inherit;" /><span style="background-color: inherit;">String message = new String(body);<br style="background-color: inherit;" /><span style="background-color: inherit;">System.out.println(routingKey + ": " + message);<br style="background-color: inherit;" /><span style="background-color: inherit;">3. 此时，你可以在broker上执行任何RabbitMQ操作，并且你会看到日志输出到标准输出上。</span></span></span></span></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">如何工作</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">RabbitMQ log交换器<span style="background-color: inherit;">amq.rabbitmq.log是一个<span style="background-color: inherit;">topic交换器，RabbitMQ自身用来发布其日志消息<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">在我们的示例代码中，我们使用#通配符来消费所有topics的消息<span style="background-color: inherit;"><span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">例如，通过运行另一份代码，我们可运行同一个broker的两个连接，然后中断它，我们将下面的输出<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;">info: accepting AMQP connection &lt;0.2737.0&gt; (127.0.0.1:54698 -&gt;<span style="background-color: inherit;">127.0.0.1:5672)</span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span><span style="background-color: inherit;">info: accepting AMQP connection &lt;0.2753.0&gt; (127.0.0.1:54699 -&gt;<span style="background-color: inherit;">127.0.0.1:5672)<br style="background-color: inherit;" /><span style="background-color: inherit;">warning: closing AMQP connection &lt;0.2737.0&gt; (127.0.0.1:54698 -&gt;<span style="background-color: inherit;">127.0.0.1:5672):<br style="background-color: inherit;" /><span style="background-color: inherit;">connection_closed_abruptly<br style="background-color: inherit;" /><span style="background-color: inherit;">warning: closing AMQP connection &lt;0.2753.0&gt; (127.0.0.1:54699 -&gt;<span style="background-color: inherit;">127.0.0.1:5672):<br style="background-color: inherit;" /><span style="background-color: inherit;">connection_closed_abruptly<br style="background-color: inherit;" /></span></span></span></span></span></span></span></span></font><div style="background-color: inherit;">值得注意的是，在这里报告的信息，信息和警告不是自己的一部分，但是我们在每个开始打印的路由键<span style="line-height: 1.5; background-color: inherit;">消息（前一步骤的步骤2）。</span></div></div><div><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div><font face="Microsoft Yahei" style="background-color: inherit;">TIP</font></div><div><span style="line-height: 1.5; background-color: inherit;">如果我们只想收到警告和错误消息，我们可以订阅相应的主题</span><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">.</span><br style="text-align: -webkit-auto; background-color: inherit;" /></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">更多</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">默认情况下，日志交换器－<span style="background-color: inherit;">amq.rabbitmq.log被创建在虚拟主机<span style="background-color: inherit;"><span style="background-color: inherit;">/中。</span></span></span></span></font><span style="line-height: 1.5; background-color: inherit;">通过在RabbitMQ配置文件中定义default_vhost从而设置其位置是可能的</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.</span><br style="background-color: inherit;" /><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">追踪RabbitMQ当前活动</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">有时，为了分析和调试未知的应用程序行为，我们需要追踪RabbitMQ接收和分发的所有消息<span style="background-color: inherit;">.<br style="background-color: inherit;" /></span></span></font><span style="line-height: 1.5; background-color: inherit;">RabbitMQ提供追踪这些消息的所谓的流水追踪工具。</span><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><br style="background-color: inherit;" /><span style="background-color: inherit;">追踪活动可以在运行时启用和禁用,并且它应该只用于调试，因为它规定了broker活动的开销<span style="background-color: inherit;">.</span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span>准备</font></div><div><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">要运行此食谱，我们需要运行此食谱，我们需要运行RabbitMQ和Java client library.<br style="text-align: -webkit-auto; background-color: inherit;" /></span><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"></span></span></span></span>如何做</span></span></font></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">RabbitMQ使用与日志消息中同样的机制来发送追踪消息;因此，示例代码与前一个食谱中的非常相似<span style="background-color: inherit;">.</span></font></span></span></span></span></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><br style="text-align: -webkit-auto; background-color: inherit;" /></span><span style="background-color: inherit;">为了消费追踪消息，你可以执行<span style="background-color: inherit;">Consumer.java中的主方法，你可在<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">Chapter12/Recipe02/Java/src/<span style="background-color: inherit;">rmqexample目录中找到源码<span style="background-color: inherit;">.这里，我们高亮了主要步骤:<br style="background-color: inherit;" /><span style="background-color: inherit;">1. 创建一个临时队列，并将其绑定到AMQP log交换器上:<br style="background-color: inherit;" /><span style="background-color: inherit;">String tmpQueue = channel.queueDeclare().getQueue();<br style="background-color: inherit;" /><span style="background-color: inherit;">channel.queueBind(tmpQueue,"amq.rabbitmq.trace","#");<br style="background-color: inherit;" /><span style="background-color: inherit;">2.在消费者回调(<span style="background-color: inherit;">ActualConsumer.java<span style="background-color: inherit;">)中, 可以获取每个消息，并使用下面的代码打印出来<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;">String routingKey = envelope.getRoutingKey();<br style="background-color: inherit;" /><span style="background-color: inherit;">String message = new String(body);<br style="background-color: inherit;" /><span style="background-color: inherit;">Map&lt;String,Object&gt; headers = properties.getHeaders();<br style="background-color: inherit;" /><span style="background-color: inherit;">LongStringexchange_name = (LongString)<br style="background-color: inherit;" /><span style="background-color: inherit;">headers.get("exchange_name");<br style="background-color: inherit;" /><span style="background-color: inherit;">LongString node = (LongString) headers.get("node");<br style="background-color: inherit;" /><span style="background-color: inherit;">...<br style="background-color: inherit;" /><span style="background-color: inherit;">3. 可从root用户(Linux)或在RabbitMQ命令控制台<span style="background-color: inherit;">(Windows)来激活firehose，其激活命令如下:<br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">rabbimqctl trace_on</strong><br style="background-color: inherit;" /><span style="background-color: inherit;">4. 此时,你可以向broker启动生产和发送消息,然后你们会在标准输出中看到追踪信息<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">5. 可调用下面的命令来禁用firehose:<br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">rabbimqctl trace_off</strong></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span>如何工作&nbsp;</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">默认情况下，<span style="background-color: inherit;">amq.rabbit.trace&nbsp;<span style="background-color: inherit;">topic交换器不会接收任何消息,但一旦激活<span style="background-color: inherit;">firehose后(前面步骤的步骤3),所有流经<span style="background-color: inherit;">broker的消息将被按下面的规则拷贝:<br style="background-color: inherit;" /><span style="background-color: inherit;">1.<span style="background-color: inherit;">进入broker的消息,它们是通过路由键<span style="background-color: inherit;">publish.<span style="background-color: inherit;">exchange-name发布的<span style="background-color: inherit;">, 这里的<span style="background-color: inherit;">exchange-name是消息最初发布的交换器名称<span style="background-color: inherit;"><span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">2.离开broker的消息,它们是通过路由键<span style="background-color: inherit;"><span style="background-color: inherit;">deliver.queuename发布的<span style="background-color: inherit;">,这里的<span style="background-color: inherit;">queue-name是消息最初被消费的队列名称<span style="background-color: inherit;"><span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">3.消息的body是从原始消息中拷贝过来的<span style="background-color: inherit;">.</span></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="background-color: inherit;">4.原始消息的元数据会插入到拷贝消息的header属性中.<span style="background-color: inherit;"><span style="background-color: inherit;">&nbsp;在步骤2中,我们已经看到了,如何获取最初分发消息的交换器名称,但获取所有原始信息也是可以的,即,找到所有可有字段,并将它们插到消息属性中.firehose的官方文档链接位于:<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">h<span style="background-color: inherit;">ttp://<span style="background-color: inherit;">www.rabbitmq.com/firehose.html<span style="background-color: inherit;">.</span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">调试RabbitMQ消息</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">有时,通过在标准输出中记录通过broker的消息是有用的.通过RabbitMQ Java客户端提供的简单应用程序来追踪消息,也是可行的.<br style="text-align: -webkit-auto; background-color: inherit;" /></span>准备</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">要运行此食谱,你需要运行的RabbitMQ(运行标准端口&nbsp;<span style="background-color: inherit;">5672),以及<span style="background-color: inherit;"><span style="background-color: inherit;">RabbitMQ Java client library</span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span>如何做</font></div><div><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">RabbitMQ的Java client library中包含了一个追踪工具，你可以按下面的步骤来进行实际使用</font><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">.</font><br style="background-color: inherit;" /><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">1. 从</font><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">http://www.</font><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">rabbitmq.com/java-client.html页面下载最新版本的</font><span style="font-family: 'Microsoft Yahei';">RabbitMQ Java client library</span><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">.</font><br style="background-color: inherit;" /><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">2. 将其解</font>压，并进入其目录</span></span></span></span></span></span></span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.</span></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">3. 通过下面的命令来运行Java tracer:<br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">./runjava.sh com.rabbitmq.tools.Tracer</strong><br style="background-color: inherit;" /><span style="background-color: inherit;">4. 运行用于调试Java client,并将其连接到<span style="background-color: inherit;">5673端口<span style="background-color: inherit;">.对于本食谱,我们可以使用包含在Java client包中的另一个Java工具,其调用如下<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">./runjava.sh com.rabbitmq.examples.PerfTest -h amqp://</strong><span style="background-color: inherit;"><strong style="background-color: inherit;">localhost:5673 -C 1 -D 1</strong></span></span></span></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span>如何工作</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">追踪工具是一个简单的AMQP代理;默认情况下，它监听<span style="background-color: inherit;">5673端口，并会把所有的请求转发到默认监听5672端口的<span style="background-color: inherit;"><span style="background-color: inherit;">RabbitMQ broker<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">.</span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span><span style="background-color: inherit;">所有生产或消费的消息，如同AMQP操作一样，都会记录到标准输出中<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">运行前面步骤的步骤4,我们使用了包含在Java client包中另一个用于作RabbitMQ压力测试的工具<span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">在这里,我们只是限制了生产一个消息(<span style="background-color: inherit;">-C 1<span style="background-color: inherit;">) 并消费它(<span style="background-color: inherit;">-D 1<span style="background-color: inherit;">).</span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span>TIP</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">追踪工具只在Java client API中可用.<br style="text-align: -webkit-auto; background-color: inherit;" /></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">更多</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">可以使用下面的代码来为Java追踪程序传递更多的参数<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;">./runjava.sh com.rabbitmq.tools.Tracer listenPort connectHost&nbsp;<span style="background-color: inherit;">connectPort<br style="background-color: inherit;" /><span style="background-color: inherit;"><span style="background-color: inherit;">listenPort指的是追踪器监听的端口<span style="background-color: inherit;">(默认为<span style="background-color: inherit;">5673<span style="background-color: inherit;">),&nbsp;<span style="background-color: inherit;">connectHost<span style="background-color: inherit;">/<span style="background-color: inherit;">connectPort&nbsp;<span style="background-color: inherit;">(默认为<span style="background-color: inherit;">localhost/5672<span style="background-color: inherit;">) 是用于连接并转发收到请求的主机和端口。</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">使用下面的命令，你可以找到所有<span style="background-color: inherit;">PerfTest可用选项<span style="background-color: inherit;">:<br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">./runjava.sh com.rabbitmq.examples.PerfTest --help</strong></span></span></span></span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span></span></span></span></span></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">也可参考</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">在http://www.rabbitmq.com/java-tools.html中，你可以找到Java追踪工具以及PerfTest的文档.<span style="background-color: inherit;"><span style="background-color: inherit;"><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">当RabbitMQ重启失败时，需要做什么</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">偶尔情况下， RabbitMQ 可能会重启失败。如果broker包含持久化数据时，这是一个严重的问题，否则，有足够的能力重设其持久化状态。<br style="text-align: -webkit-auto; background-color: inherit;" /></span>准备</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">要运行此食谱，你只需要一个测试RabbitMQ broker.<br style="text-align: -webkit-auto; background-color: inherit;" /></span>TIP</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">我们将销毁所有之前定义的数据&#8212;以避免使用生产实例<span style="background-color: inherit;">.</span><br style="text-align: -webkit-auto; background-color: inherit;" /></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">如何做</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">要清空RabbitMQ, 可执行下面的简单步骤:<br style="background-color: inherit;" /><span style="background-color: inherit;">1. 如果RabbitMQ运行的话，停止它.<br style="background-color: inherit;" /><span style="background-color: inherit;">2. 定位到<span style="background-color: inherit;">Mnesia 数据库目录<span style="background-color: inherit;">.默认是<span style="background-color: inherit;">/var/lib/rabbitmq/<span style="background-color: inherit;">mnesia&nbsp;<span style="background-color: inherit;">(Linux) or&nbsp;<span style="background-color: inherit;">%APPDATA%\RabbitMQ\db&nbsp;<span style="background-color: inherit;">(Windows).<br style="background-color: inherit;" /><span style="background-color: inherit;">3. 递归删除其目录和文件.<br style="background-color: inherit;" /><span style="background-color: inherit;">4. 重启RabbitMQ.</span></span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></span>如何工作</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><font color="#ff0000" style="background-color: inherit;">Mnesia 数据库包含了所有运行时的RabbitMQ定义信息: 队列,交换器,用户等等.<span style="background-color: inherit;"><br style="background-color: inherit;" /><span style="background-color: inherit;">通过删除Mnesia数据库&nbsp;(或者通过重命名,这样可以在需要的时候恢复某些数据<span style="background-color: inherit;">), RabbitMQ会重置到出厂默认状态,当RabbitMQ启动时,它会创建一个新的<span style="background-color: inherit;">Mnesia数据库,并使用默认值进行初始化.</span></span></span></span></font><br style="text-align: -webkit-auto; background-color: inherit;" /></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">更多</font></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">如果broker无法在第一时间启动,有可能是某个系统目录存在权限问题<span style="background-color: inherit;">:</span></span></font><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">即要么是Mnesia数据库目录,要么是日志目录,要么是某些在配置文件中指定的临时的或自定义的目录</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.</span></div><div><span style="line-height: 1.5; background-color: inherit;">你可以在RabbitMQ故障排除页页找到详尽的列表</span><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">(<span style="background-color: inherit;">http://<span style="background-color: inherit;">www.rabbitmq.com/troubleshooting.html<span style="background-color: inherit;">).</span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span><br style="background-color: inherit;" /></font></div><div><font face="Microsoft Yahei" style="background-color: inherit;">也可参考</font></div><div><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">在Mnesia API&nbsp;<span style="background-color: inherit;">文档页面(<span style="background-color: inherit;">http://www.erlang.org/doc/man/mnesia.html<span style="background-color: inherit;">),,你可以找到更多关于如何破解Mnesia数据库的信息.</span></span></span></font></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" /></font></span></span></span></span></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="line-height: 19px; background-color: inherit;">使用</span><span style="line-height: 1.5; background-color: inherit;">Wireshark调试</span></font></div><div><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">在调试<span style="background-color: inherit;">RabbitMQ消息食谱中,我们已经了解过了如何来追踪RabbitMQ的消息.</span></font></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" /></font></span></span></span></div><div><div style="background-color: inherit;">然而，以下情况并不总是可能的或可取的，即停止正在运行的客户端（或RabbitMQ服务器），修改它的连接端口，指向一个不同的broker；我们只想监控<span style="line-height: 1.5; background-color: inherit;">正在实时传递的消息，影响系统的活动应该尽可能的少。</span></div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" />TIP</font></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">但是,正如在前面食谱(追踪RabbitMQ当前活动)中看到的一样,激活firehose是可行的 .</font></span></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" /></font></span></span></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span><span style="background-color: inherit;">Wireshark是一个免费的有能力解码AMQP消息的网络分析工具.<br style="background-color: inherit;" /><span style="background-color: inherit;">此工具既可用在客户段,也可以用在服务端,从而</span></span></font></span></span></span><span style="line-height: 1.5; background-color: inherit;">无缝</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">监控AMQP交通状况</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.</span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" />准备</font></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">要练习这个食谱,你需要运行的RabbitMQ以及RabbitMQ Java&nbsp;<span style="background-color: inherit;">client library.</span></font></span></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><br style="text-align: -webkit-auto; background-color: inherit;" /></span>如何做</font></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">在下面的步骤中,我们将看到如何使用Wireshark来追踪AMQP消息:<br style="background-color: inherit;" /><span style="background-color: inherit;">1. 如果Wireshark在你的系统中尚不可用,那么需要从http://www.wireshark.org/下载和安装Wireshark&nbsp;<span style="background-color: inherit;"><span style="background-color: inherit;">. 如果可能的话,你也可以从你的发行版中进行安装,如:<span style="background-color: inherit;"><br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">yum install wireshark-gnome</strong><br style="background-color: inherit;" /><span style="background-color: inherit;">2.在Linux系统中,以root用户来启动Wireshark<span style="background-color: inherit;"><span style="background-color: inherit;">.<br style="background-color: inherit;" /><span style="background-color: inherit;">3.启动从环回接口中捕获消息.<br style="background-color: inherit;" /><span style="background-color: inherit;">4.切换到Java client library路径下,在终端中运行下面的命令:<br style="background-color: inherit;" /><span style="background-color: inherit;"><strong style="background-color: inherit;">./runjava.sh com.rabbitmq.examples.PerfTest -C 1 -D 1</strong><br style="background-color: inherit;" /><span style="background-color: inherit;">5.</span></span></span></span></span></span></span></span></span></span></span></span></span></font></span></span></span><span style="line-height: 1.5; background-color: inherit;">停止Wireshark&nbsp;GUI的采集,并分析抓到的AMQP交通状况</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">.</span><br style="background-color: inherit;" /><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">如何工作</font></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">使用Wireshark,可用于检测AMQP交通的退出或进行一个持有RabbitMQ服务器或客户端的服务器.<span style="background-color: inherit;"><br style="background-color: inherit;" /><span style="background-color: inherit;">在我们的例子中,我们捕获了运行在同一台机器上服务端和客户端网络交通状况,因此连接是localhost中发生的.这也是为什么我们从环回接口中捕获交通状况的原因<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">(前面步骤的步骤3).</span></span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span><span style="background-color: inherit;">反之,我们应该从网络接口中进行捕获,这种网络接口通常是eth0或其它相似的网络接口.<br style="text-align: -webkit-auto; background-color: inherit;" /></span><br style="background-color: inherit;" />TIP</font></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">在Linux上,可以直接捕获localhost<span style="background-color: inherit;"><span style="background-color: inherit;">;但同样的操作不能应用到<span style="background-color: inherit;">Windows上.在这种情况下,客户端和服务端必须位于不同的两台机器上<span style="background-color: inherit;">, 并且在网络接口上(要么是物理的,要么是虚拟的)必须激活捕获<span style="background-color: inherit;">, 这样它们之间才可连接.</span></span></span></span></span></font></span></span></span></span></div><div><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><br style="background-color: inherit;" /></font></span></span></span></span></span></span></div><div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span></span></font><div style="background-color: inherit;">所以，为了运行Wireshark的图形用户界面，如果RabbitMQ客户端和服务器运行在同一个节点，你需要选择环回接口，如图下面的截图所示<span style="font-family: 'Microsoft Yahei'; line-height: 1.5; background-color: inherit;">:<br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qbna350816/122.png" width="1013" height="452" alt="" /><br /><br /></span></div></div><div style="background-color: inherit;"><div><font face="Microsoft Yahei" style="background-color: inherit;">TIP</font></div><div><span style="line-height: 1.5; background-color: inherit;">在Linux上，当你安装Wireshark软件包，你通常只会有命令行界面，tshark。要安装Wireshark的GUI，你必须安装相应的软件包</span><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">. 例如,在<span style="background-color: inherit;">Fedora中,你需要安装<span style="background-color: inherit;">wireshark-gnome包<span style="background-color: inherit;">.</span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span></span></span><br style="background-color: inherit;" /></font></div><div><span style="line-height: 1.5; background-color: inherit;">一旦AMQP交通已穿过环回接口，它已经被Wireshark捕获。</span><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><br style="text-align: -webkit-auto; background-color: inherit;" /></span></font><div style="background-color: inherit;">运行在步骤4的实验实际上在两个独立的连接中开启了一个生产者和一个消费者.</div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">为了高亮显示,找到一个描述为<span style="background-color: inherit;">Basic.PublishContent-Header的包<span style="background-color: inherit;">,点击它<span style="background-color: inherit;">,并选择<span style="background-color: inherit;">Follow TCP stream<span style="background-color: inherit;">.</span></span></span></span></span></span></span></span></font><span style="line-height: 1.5; background-color: inherit;">然后，您可以关闭显示客户端和服务器之间有效负载对话的窗口。在主窗口中，您现在可以看到在客户端和服务器之间交换的网络数据包，如下面的截图所示：<br /><br /><img src="http://www.blogjava.net/images/blogjava_net/qbna350816/123.png" width="1127" height="782" alt="" /><br /><br /></span><span style="font-family: 'Microsoft Yahei';">用同样的方式,你可以选择RabbitMQ server,如下面的截图所示</span><span style="font-family: 'Microsoft Yahei';">:<br /><img src="http://www.blogjava.net/images/blogjava_net/qbna350816/124.png" width="1086" height="799" alt="" /><br /></span><div><div style="background-color: inherit;">在前面的两个截图中，我们已经强调了消息AMQP的有效载荷，但由于Wireshark中包括了一个非常完整的AMQP解剖器,你会发现在AMQP交通的很多细节。</div><font face="Microsoft Yahei" style="background-color: inherit;">更多</font></div><div><div style="background-color: inherit;">如果RabbitMQ配置为使用SSL,并且你想要分析加密流量,在一定条件下,通过在Wireshark配置中合理配置SSL公共/私有密钥也是可以的<span style="line-height: 1.5; background-color: inherit;">。</span></div><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">可在<span style="background-color: inherit;">http://wiki.wireshark.org/SSL找到更多信息<span style="background-color: inherit;">.</span></span></span><br style="text-align: -webkit-auto; background-color: inherit;" /></span></span></span>也可参考</font></div><div><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">在</font><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;">http://wiki.</font><span style="background-color: inherit;"><font face="Microsoft Yahei" style="background-color: inherit;"><span style="background-color: inherit;">wireshark.org/AMQP,你可以找到一些关于</span>Wireshark AMQP 解剖器的一些指南<span style="background-color: inherit;">.</span></font></span></span></span></div><span style="font-family: 'Microsoft Yahei';"><br /><br /><br /><br /></span></div></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/431254.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-20 11:39 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/20/431254.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第9章-扩展RabbitMQ功能</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/20/431253.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Wed, 20 Jul 2016 03:30:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/20/431253.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431253.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/20/431253.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431253.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431253.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在本章节中，我们将展现一些RabbitMQ中的可用插件.然后，我们将展示如何使用现实世界中的例子来开发新插件.启用和配置STOMP插件管理RabbitMQ集群监控Shovel状态开发新插件&#8211;&nbsp;使用ODBC连接关系数据库介绍多亏了插件设施，使得RabbitMQ成为了一个可扩展平台.它提供了许多通用插件,其中一些已经在前面的章节中解释过了.例如,&nbsp;Federation和...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/07/20/431253.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431253.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-20 11:30 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/20/431253.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第8章-RabbitMQ性能调优</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/15/431213.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Fri, 15 Jul 2016 06:53:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/15/431213.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431213.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/15/431213.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431213.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431213.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在这一章中，我们将涵盖:多线程和队列系统调整改善带宽使用不同分发工具介绍这里没有标准的RabbitMQ调优指南，因为不同应用程序会采用不同方式优化.通常情况下，应用程序需要在客户端进行优化:处理器密集型应用程序可以通过为每个处理器内核运行一个线程来进行优化I/O密集型应用程序可以通过在单核上运行多个线程来隐藏隐式延迟在两种情况下，消息传递是完美的结合.为了优化网络传输速率，AMQP标准规定消息按束...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/07/15/431213.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431213.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-15 14:53 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/15/431213.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第7章-开发高可用应用程序</title><link>http://www.blogjava.net/qbna350816/archive/2016/07/02/431082.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sat, 02 Jul 2016 11:11:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/07/02/431082.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431082.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/07/02/431082.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431082.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431082.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在本章中我们将覆盖涉及:镜像队列同步队列优化镜像策略在几个broker之间分发消息创建一个地理位置集群复制过滤和转发消息将高可用技术结合在一起客户端高可用性介绍RabbitMQ通过数据复制来达到高可用，当数据完整性、服务连续性是最重要的时候，&nbsp;这一点与存储(如：RAID解决方案),数据库,以及所有IT基础设施解决方案是相同的。事实上，这些解决方案不仅可以避免数据丢失，也可以避免计划维护和...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/07/02/431082.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/431082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-07-02 19:11 <a href="http://www.blogjava.net/qbna350816/archive/2016/07/02/431082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>官网指南-rabbitmq-service 指南</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/24/431017.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Fri, 24 Jun 2016 15:58:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/24/431017.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/431017.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/24/431017.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/431017.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/431017.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; background-color: #ffffff;"><h1 style="background-color: inherit;"><span style="font-size: 16px; line-height: 1.5; background-color: inherit;"><span style="font-size: 14px; background-color: inherit;">名称</span></span></h1><div lang="en" title="rabbitmq-service.bat" style="background-color: inherit;"><div style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">rabbitmq-service.bat &#8212; 管理RabbitMQ AMQP service</p></div><div style="background-color: inherit;"><h2 style="background-color: inherit;"><span style="font-size: 14px; background-color: inherit;">语法</span></h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">rabbitmq-service.bat&nbsp;[command]</p></div><div style="background-color: inherit;"><h2 style="background-color: inherit;"><span style="font-size: 14px; background-color: inherit;">描述</span></h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ是AMQP的实现, 后者是高性能企业消息通信的新兴标准. RabbitMQ server是AMQP 中间件的健壮，可扩展实现.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">运行<strong style="background-color: inherit;">rabbitmq-service，可允许</strong>RabbitMQ broker在NT/2000/2003/XP/Vista&#174;环境上以服务来运行，这样就可以通过<span style="line-height: 1.5; background-color: inherit;">Windows&#174; services applet来启动和停止服务.</span></p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认情况下，服务会以本地系统帐户中认证上下文来运行。因此，有必要将Erlang cookies 和本地系统帐户进行同步(典型地，C:\WINDOWS\.erlang.cookie和帐户将用来运行&nbsp;rabbitmqctl).</p></div><div style="background-color: inherit;"><h2 style="background-color: inherit;"><span style="font-size: 14px; background-color: inherit;">命令</span></h2><dl style="background-color: inherit;"><dt style="background-color: inherit;">help</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">显示使用信息.</p></dd><dt style="background-color: inherit;">install</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">安装service，安装后，它不会启动。如果环境变量修改了的话，随后的调用将更新服务参数.</p></dd><dt style="background-color: inherit;">remove</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">删除service.如果删除时，service正在运行，则将会自动停止。<span style="line-height: 1.5; background-color: inherit;">&nbsp;它不会删除任何文件，后续可通过</span><span style="line-height: 1.5; background-color: inherit;"><strong style="background-color: inherit;">rabbitmq-server</strong></span><span style="line-height: 1.5; background-color: inherit;">&nbsp;继续操作。</span></p></dd><dt style="background-color: inherit;">start</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">启动service. 在此之前，service必须被正确安装</p></dd><dt style="background-color: inherit;">stop</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">停止service.&nbsp;</p></dd><dt style="background-color: inherit;">disable</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">禁用service. 这等价于在服务控制面板中，将启动类型设置为禁用.</p></dd><dt style="background-color: inherit;">enable</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">启用service.&nbsp;这等价于在服务控制面板中，将启动类型设置为自动.</p></dd></dl></div><div style="background-color: inherit;"><h2 style="background-color: inherit;"><span style="font-size: 14px; background-color: inherit;">环境变量</span></h2><dl style="background-color: inherit;"><dt style="background-color: inherit;">RABBITMQ_SERVICENAME</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认为RabbitMQ.</p></dd><dt style="background-color: inherit;">RABBITMQ_BASE</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认是当前用户的应用程序数据目录. 这是日志和数据目录的位置（<span style="line-height: 1.5; background-color: inherit;">C:\Users\Administrator\AppData\Roaming\RabbitMQ</span><span style="line-height: 1.5; background-color: inherit;">）.</span></p></dd><dt style="background-color: inherit;"></dt><dt><span style="background-color: inherit;">RABBITMQ_NODENAME</span></dt><dd><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认是rabbit. 当你想在一台机器上运行多个节点时，此配置是相当有用的，&nbsp;<span style="background-color: inherit;">RABBITMQ_NODENAME在每个</span>erlang-node和机器的组合中应该唯一。</p></dd><dd><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">参考<a href="http://www.rabbitmq.com/clustering.html#single-machine" target="_top" style="cursor: pointer; background-color: inherit;">clustering on a single machine guide</a>&nbsp;来更多细节.</p></dd><dt><span style="background-color: inherit;">RABBITMQ_NODE_IP_ADDRESS</span></dt><dd><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认情况下，RabbitMQ会绑定到所有网络接口上,如果只想绑定某个网络接口，可修改此设置。</p></dd><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"></p></dd><dt style="background-color: inherit;">RABBITMQ_NODE_PORT</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认为5672.</p></dd><dt style="background-color: inherit;">ERLANG_SERVICE_MANAGER_PATH</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认为C:\Program Files\erl5.5.5\erts-5.5.5\bin&nbsp;(或64位环境 中为C:\Program Files (x86)\erl5.5.5\erts-5.5.5\bin). 这是Erlang service manager的安装位置.</p></dd><dt style="background-color: inherit;">RABBITMQ_CONSOLE_LOG</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">将此变量设置为new或reuse,以将服务器控制台的输出重定向到名为SERVICENAME.debug文件中(位于安装服务的用户应用程序数据目录）.在Vista下，其位置在C:\Users\AppData\username\SERVICENAME. 在Windows的前期版本中，位置在C:\Documents and Settings\username\Application Data\SERVICENAME.&nbsp;</p></dd><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">如果RABBITMQ_CONSOLE_LOG设置为new,那么每次服务启动时都会创建一个新文件。</p></dd><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">如果RABBITMQ_CONSOLE_LOG设置为reuse，那么每次服务启动时，文件都会被覆盖.</p></dd><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当RABBITMQ_CONSOLE_LOG<span style="background-color: inherit;">&nbsp;没有设置或设置的值不是new或reuse时，默认的行为是丢弃服务器输出。</span></p></dd><dd style="background-color: inherit;"><div><span style="background-color: inherit;"><br /></span></div></dd></dl></div></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/431017.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-24 23:58 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/24/431017.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第6章节-开发可伸缩应用程序</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/15/430914.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Wed, 15 Jun 2016 12:54:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/15/430914.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430914.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/15/430914.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430914.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430914.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在本章节中我们将覆盖:创建一个本地服务器集群创建一个简单集群自动添加一个RabbitMQ&nbsp;集群引入消息负载均衡器创建集群客户端介绍RabbitMQ提供了各种各样的特性以及集群功能.通过使用集群，一组适当配置的主机的行为与单个broker实例一样，但集群带有下面的目的:高可用性: 如果一个节点宕机了，分布式broker仍然能接受和处理消息.这方面内容会在Chapter 7,Developi...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/06/15/430914.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/430914.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-15 20:54 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/15/430914.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第5章-在Web应用程序中使用RabbitMQ</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/14/430901.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Tue, 14 Jun 2016 14:07:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/14/430901.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430901.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/14/430901.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430901.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430901.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在本章中我们将覆盖:使用Spring来开发web监控程序使用Spring来开发异步web搜索使用STOMP来开发web监控程序介绍RabbitMQ可以像客户端一样使用在服务端。当前，RabbitMQ覆盖了大部分使用的语言和技术来构建web程序，如PHP,Node.js, Python, Ruby, 以及其它.你可以在http://www.rabbitmq.com/devtools.html找到全部...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/06/14/430901.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/430901.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-14 22:07 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/14/430901.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第4章-混合使用不同技术</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/13/430873.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Mon, 13 Jun 2016 12:25:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/13/430873.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430873.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/13/430873.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430873.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430873.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在本章中我们将覆盖:使用.NET client通过MQTT绑定iPhone应用与RabbitMQ在Andriod上使用消息来更新Google Maps通过Andriod后端来发布消息使用Qpid来交换RabbitMQ消息使用Mosquitto来交换RabbitMQ消息使用.NET clients来绑定WCF程序介绍在前面的章节中，我们已经介绍了基本概念。现在，我们要使用这些概念来创建真实的应用程序...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/06/13/430873.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/430873.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-13 20:25 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/13/430873.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>官网指南-RabbitMQ支持平台</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/06/430789.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sun, 05 Jun 2016 16:09:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/06/430789.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430789.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/06/430789.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430789.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430789.html</trackback:ping><description><![CDATA[<p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; font-size: 13px; background-color: #ffffff;"><span style="font-size: 14px; background-color: inherit;">RabbitMQ的目标是尽可能广泛地支持大部分平台.RabbitMQ 可运行在任何支持Erlang的平台上, 包括内嵌系统，多核集群，云服务器.</span></p><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;">下面的平台支持Erlang，因此也可以运行RabbitMQ:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><li style="background-color: inherit;">Linux</li><li style="background-color: inherit;">Windows, NT through 10</li><li style="background-color: inherit;">Windows Server 2003/2008/2012</li><li style="background-color: inherit;">Mac OS X</li><li style="background-color: inherit;">Solaris</li><li style="background-color: inherit;">FreeBSD</li><li style="background-color: inherit;">TRU64</li><li style="background-color: inherit;">VxWorks</li></ul><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;">RabbitMQ的开源版本大部分都部署在下面的平台上：</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><li style="background-color: inherit;">Ubuntu and Debian-based Linux distributions</li><li style="background-color: inherit;">Fedora, CentOS and RPM-based Linux distributions</li><li style="background-color: inherit;">openSUSE and derived distributions (including SLES and SLERT)</li><li style="background-color: inherit;">Mac OS X</li><li style="background-color: inherit;">Windows XP and later</li></ul><h3>Windows</h3><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;">RabbitMQ可运行Windows XP及其后续版本中(Server 2003, Vista, Windows 7, Windows 8, Windows 10, Server 2008 and Server 2012). 尽管没有测试，但应该可以运行在Windows NT ，Windows 2000 上.</p><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;">64位的Windows Erlang VM从R15版本开始可用.建议使用最新的64位Erlang版本来运行。参考<a href="http://www.rabbitmq.com/which-erlang.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Erlang version compatibility page</a>.</p><h3>通用UNIX</h3><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;">虽没有官方支持，Erlang 和 RabbitMQ 能运行在含有POSIX layer including Solaris, FreeBSD, NetBSD, OpenBSD的操作系统上.</p><h3>虚拟平台</h3><p style="margin-right: 0px; margin-left: 0px; font-family: 微软雅黑; color: #555555; background-color: #ffffff;">RabbitMQ 可运行物理或虚拟硬件上. 这可以允许不支持的平台通过仿真来运行RabbitMQ.<br /><span style="background-color: inherit;">参考</span><a href="http://www.rabbitmq.com/ec2.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">EC2 guide</a><span style="background-color: inherit;">&nbsp;来了解RabbitMQ如何运行在Amazon EC2上的更多信息.</span></p><img src ="http://www.blogjava.net/qbna350816/aggbug/430789.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-06 00:09 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/06/430789.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>官网指南-rabbitmq-server(1) 指南</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/06/430788.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sun, 05 Jun 2016 16:06:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/06/430788.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430788.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/06/430788.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430788.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430788.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; background-color: #ffffff;"><h1><span style="font-size: 16px; line-height: 1.5; background-color: inherit;"><span style="font-size: 14px; background-color: inherit;">名称</span></span></h1><div title="rabbitmq-server" style="background-color: inherit;"><div style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">rabbitmq-server &#8212; 启动RabbitMQ AMQP server</p></div><div style="background-color: inherit;"><h2><span style="font-size: 14px; background-color: inherit;">语法</span></h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">rabbitmq-server&nbsp;[-detached]</p></div><div style="background-color: inherit;"><h2><span style="font-size: 14px; background-color: inherit;">描述</span></h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ是AMQP的实现, 后者是高性能企业消息通信的新兴标准. RabbitMQ server是AMQP 中间件的健壮，可扩展实现.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">前端运行rabbitmq-server，它会显示横幅消息，会报告启动时的过程信息，最后会显示"broker running",以表明RabbitMQ中间件已经成功启动。</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要关闭server,只需要终止过程或使用rabbitmqctl(1)（即：rabbitmqctl stop）.</p></div><div style="background-color: inherit;"><h2><span style="font-size: 14px; background-color: inherit;">环境变量</span></h2><dl style="background-color: inherit;"><dt style="background-color: inherit;">RABBITMQ_MNESIA_BASE</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认是&nbsp;/var/lib/rabbitmq/mnesia. 用于设置Mnesia 数据库文件存放的目录.</p></dd><dt style="background-color: inherit;">RABBITMQ_LOG_BASE</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">日志目录 ，server生成的/var/log/rabbitmq. Log&nbsp;日志文志会放置在文件会放置在此目录.（如：window10下默认安装时，日志目录为：<span style="line-height: 1.5; background-color: inherit;">C:\Users\Administrator\AppData\Roaming\RabbitMQ\log</span><span style="line-height: 1.5; background-color: inherit;">）</span></p></dd><dt style="background-color: inherit;">RABBITMQ_NODENAME</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认是rabbit. 当你想在一台机器上运行多个节点时，此配置是相当有用的，&nbsp;RABBITMQ_NODENAME在每个erlang-node和机器的组合中应该唯一。</p></dd><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">参考<a href="http://www.rabbitmq.com/clustering.html#single-machine" target="_top" style="cursor: pointer; background-color: inherit;">clustering on a single machine guide</a>&nbsp;来更多细节.</p></dd><dt style="background-color: inherit;">RABBITMQ_NODE_IP_ADDRESS</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认情况下，RabbitMQ会绑定到所有网络接口上,如果只想绑定某个网络接口，可修改此设置。</p></dd><dt style="background-color: inherit;">RABBITMQ_NODE_PORT</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">默认是5672.</p></dd></dl></div><div style="background-color: inherit;"><h2><span style="font-size: 14px; background-color: inherit;">选项</span></h2><dl style="background-color: inherit;"><dt style="background-color: inherit;">-detached</dt><dd style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">以后端的方式来启动进程 ，注意，这会导致pid无法写入到pid文件中.例如<span style="line-height: 1.5; background-color: inherit;">:</span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: inherit;">rabbitmq-server -detached</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">以后端方式来启动RabbitMQ AMQP server.</p></dd></dl></div><div style="background-color: inherit;"><h2><span style="font-size: 14px; background-color: inherit;">也可参考</span></h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">rabbitmq-env.conf(5)&nbsp;rabbitmqctl(1)</p><div></div></div></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/430788.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-06 00:06 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/06/430788.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第3章-管理RabbitMQ</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/05/430786.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sun, 05 Jun 2016 12:10:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/05/430786.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430786.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/05/430786.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430786.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430786.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 本章我们将覆盖:使用虚拟主机配置用户使用SSL实现客户端证书从浏览器中管理RabbitMQ配置RabbitMQ参数开Python程序来监控RabbitMQ自己开发web程序来监控RabbitMQ介绍一旦安装后，RabbitMQ不需要任何配置就可以工作. 然而，RabbitMQ有许多的配置选项,这些配置选项使得它更为灵活，能工作于多种不同环境中.在本章中，我们将看到如何改变配置来满足应用程序的需求。...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/06/05/430786.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/430786.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-05 20:10 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/05/430786.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>阿里云ECS Centos 7下安装RabbitMQ3.6.1</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/05/430785.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sun, 05 Jun 2016 12:08:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/05/430785.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430785.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/05/430785.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430785.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430785.html</trackback:ping><description><![CDATA[<div><h1><span style="font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;"><span style="font-size: 14px;">一.安装Erlang</span></span></h1><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif; text-align: justify; background-color: #ffffff;"><span style="color: #000000; background-color: inherit;">1、下载推荐的安装包</span></p><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"># wget&nbsp;<a href="https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_18.3-1" style="cursor: pointer; background-color: inherit;">https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_18.3-1</a>~centos~7_amd64.rpm</div></div><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif; text-align: justify; background-color: #ffffff;"><span style="color: #000000; background-color: inherit;">2、安装<br /><br /></span><span style="color: #000000; line-height: 1.5;">安装依赖包</span></p><div style="font-family: 微软雅黑; background-color: #ffffff;"><code style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; color: red;"><span style="color: #000000; background-color: inherit;"><code style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; color: red;"><span style="color: #000000; background-color: inherit;">yum&nbsp;</span></code><code style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; color: red;"><span style="color: #000000; background-color: inherit;">install</span></code>&nbsp;<code style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; color: red;"><span style="color: #000000; background-color: inherit;">unixODBC&nbsp;unixODBC-devel&nbsp;wxBase&nbsp;wxGTK&nbsp;SDL&nbsp;wxGTK-gl<br /></span></code></span></code></div><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif; text-align: justify; background-color: #ffffff;">#rpm -ivh&nbsp;<a href="https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_18.3-1" style="cursor: pointer; font-family: 微软雅黑;">esl-erlang_18.3-1</a><span style="font-family: 微软雅黑;">~centos~7_amd64.rpm</span></p></div><div></div><div>二.安装RabbitMQ</div><div>下载RabbitMQ</div><div># wget&nbsp;<a href="http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm" style="cursor: pointer;">http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm</a></div><div><div style="font-family: 微软雅黑; text-align: justify; background-color: #ffffff;"># rpm -ivh&nbsp;<span style="text-align: left; background-color: inherit;">rabbitmq-server-3.6.1-1.noarch.rpm</span></div><div style="font-family: 微软雅黑; text-align: justify; background-color: #ffffff;"><span style="text-align: left; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; text-align: justify; background-color: #ffffff;"><span style="font-family: Verdana, Arial, Helvetica, sans-serif;">安装rabbitmq-server的过程中遇到了一个问题：</span></div><div style="font-family: 微软雅黑; text-align: justify; background-color: #ffffff;"><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">Error: Package: rabbitmq-server-3.6.1-1.noarch (/rabbitmq-server-3.6.1-1.noarch)&nbsp;<br style="background-color: inherit;" />Requires: erlang &gt;= R16B-3&nbsp;<br style="background-color: inherit;" />You could try using --skip-broken to work around the problem&nbsp;<br style="background-color: inherit;" />You could try running: rpm -Va --nofiles --nodigest</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">这是由于erlang的版本问题，其实是没有影响的，你可以使用下面的命令进行安装：</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">#rpm -ivh --nodeps rabbitmq-server-3.6.1-1.noarch.rpm</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"><br style="background-color: inherit;" /></p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"></p><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;"><span style="color: #000000; background-color: inherit;"><strong style="background-color: inherit;">启动</strong></span></p><p style="margin-right: 0px; margin-left: 0px;">#service&nbsp;rabbitmq-server&nbsp;start --后台方式运行</p><p style="margin-right: 0px; margin-left: 0px;">#service rabbitmq-server stop &nbsp;--停止运行</p><p style="margin-right: 0px; margin-left: 0px;">#service rabbitmq-server status --查看状态</p><p style="margin-right: 0px; margin-left: 0px; color: #555555;"><span style="color: #000000; background-color: inherit;">#rabbitmq-server start&nbsp;<br style="background-color: inherit;" /></span></p><p style="margin-right: 0px; margin-left: 0px; color: #555555;"><span style="color: #000000; background-color: inherit;">可以看到使用的日志文件</span></p><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;"><span style="color: #000000; background-color: inherit;"><span style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, 'monospace !important'; font-size: 13px;"><span style="font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif; font-size: 14px;"><strong style="background-color: inherit;">日志目录</strong></span><br style="background-color: inherit;" /></span></span></p><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;"><span style="color: #000000;">/var/log/rabbitmq</span></p><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;"><span style="color: #000000;">#</span><span style="font-family: 微软雅黑; font-size: 16px; text-align: left; background-color: inherit;">cat&nbsp;/var/log/rabbitmq/</span><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#97;&#98;&#98;&#105;&#116;&#64;&#105;&#90;&#57;&#52;&#110;&#120;&#115;&#108;&#122;&#54;&#54;&#90;&#46;&#108;&#111;&#103;" style="cursor: pointer; font-family: 微软雅黑; font-size: 16px; text-align: left; background-color: inherit;">rabbit@iZ94nxslz66Z.log</a>&nbsp;可以看到下面的日志记录</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;">...................................................................................................................................................................................................................................................</p><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:10&nbsp;===</div><div>node&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#97;&#98;&#98;&#105;&#116;&#64;&#105;&#90;&#57;&#52;&#110;&#120;&#115;&#108;&#122;&#54;&#54;&#90;" style="cursor: pointer; background-color: inherit;">rabbit@iZ94nxslz66Z</a></div><div>home&nbsp;dir&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;/var/lib/rabbitmq</div><div>config&nbsp;file(s)&nbsp;:&nbsp;/etc/rabbitmq/rabbitmq.config&nbsp;(not&nbsp;found)</div><div>cookie&nbsp;hash&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;fisYwC976M1LblhTfYslpg==</div><div>log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;/var/log/rabbitmq/<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#97;&#98;&#98;&#105;&#116;&#64;&#105;&#90;&#57;&#52;&#110;&#120;&#115;&#108;&#122;&#54;&#54;&#90;&#46;&#108;&#111;&#103;" style="cursor: pointer; background-color: inherit;">rabbit@iZ94nxslz66Z.log</a></div><div>sasl&nbsp;log&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;/var/log/rabbitmq/<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#97;&#98;&#98;&#105;&#116;&#64;&#105;&#90;&#57;&#52;&#110;&#120;&#115;&#108;&#122;&#54;&#54;&#90;&#45;&#115;&#97;&#115;&#108;&#46;&#108;&#111;&#103;" style="cursor: pointer; background-color: inherit;">rabbit@iZ94nxslz66Z-sasl.log</a></div><div>database&nbsp;dir&nbsp;&nbsp;&nbsp;:&nbsp;/var/lib/rabbitmq/mnesia/<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#97;&#98;&#98;&#105;&#116;&#64;&#105;&#90;&#57;&#52;&#110;&#120;&#115;&#108;&#122;&#54;&#54;&#90;" style="cursor: pointer; background-color: inherit;">rabbit@iZ94nxslz66Z</a></div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Memory&nbsp;limit&nbsp;set&nbsp;to&nbsp;397MB&nbsp;of&nbsp;992MB&nbsp;total.</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Disk&nbsp;free&nbsp;limit&nbsp;set&nbsp;to&nbsp;50MB</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Limiting&nbsp;to&nbsp;approx&nbsp;65435&nbsp;file&nbsp;handles&nbsp;(58889&nbsp;sockets)</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>FHC&nbsp;read&nbsp;buffering:&nbsp;&nbsp;OFF</div><div>FHC&nbsp;write&nbsp;buffering:&nbsp;ON</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Database&nbsp;directory&nbsp;at&nbsp;/var/lib/rabbitmq/mnesia/<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#114;&#97;&#98;&#98;&#105;&#116;&#64;&#105;&#90;&#57;&#52;&#110;&#120;&#115;&#108;&#122;&#54;&#54;&#90;" style="cursor: pointer; background-color: inherit;">rabbit@iZ94nxslz66Z</a>&nbsp;is&nbsp;empty.&nbsp;Initialising&nbsp;from&nbsp;scratch...</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Priority&nbsp;queues&nbsp;enabled,&nbsp;real&nbsp;BQ&nbsp;is&nbsp;rabbit_variable_queue</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Adding&nbsp;vhost&nbsp;'/'</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Creating&nbsp;user&nbsp;'guest'</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Setting&nbsp;user&nbsp;tags&nbsp;for&nbsp;user&nbsp;'guest'&nbsp;to&nbsp;[administrator]</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Setting&nbsp;permissions&nbsp;for&nbsp;'guest'&nbsp;in&nbsp;'/'&nbsp;to&nbsp;'.*',&nbsp;'.*',&nbsp;'.*'</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>msg_store_transient:&nbsp;using&nbsp;rabbit_msg_store_ets_index&nbsp;to&nbsp;provide&nbsp;index</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>msg_store_persistent:&nbsp;using&nbsp;rabbit_msg_store_ets_index&nbsp;to&nbsp;provide&nbsp;index</div><div></div><div>=WARNING&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>msg_store_persistent:&nbsp;rebuilding&nbsp;indices&nbsp;from&nbsp;scratch</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>started&nbsp;TCP&nbsp;Listener&nbsp;on&nbsp;[::]:5672</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:20:11&nbsp;===</div><div>Server&nbsp;startup&nbsp;complete;&nbsp;0&nbsp;plugins&nbsp;started.</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:21:52&nbsp;===</div><div>Management&nbsp;plugin:&nbsp;using&nbsp;rates&nbsp;mode&nbsp;'basic'</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:21:52&nbsp;===</div><div>Management&nbsp;plugin&nbsp;started.&nbsp;Port:&nbsp;15672</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:21:52&nbsp;===</div><div>Statistics&nbsp;database&nbsp;started.</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:21:52&nbsp;===</div><div>Plugins&nbsp;changed;&nbsp;enabled&nbsp;[mochiweb,webmachine,rabbitmq_web_dispatch,</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amqp_client,rabbitmq_management_agent,</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rabbitmq_management],&nbsp;disabled&nbsp;[]</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:23:01&nbsp;===</div><div>Stopping&nbsp;RabbitMQ</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:23:01&nbsp;===</div><div>stopped&nbsp;TCP&nbsp;Listener&nbsp;on&nbsp;[::]:5672</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:23:01&nbsp;===</div><div>Stopped&nbsp;RabbitMQ&nbsp;application</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:23:01&nbsp;===</div><div>Halting&nbsp;Erlang&nbsp;VM</div><div></div><div>=INFO&nbsp;REPORT====&nbsp;28-Apr-2016::04:23:29&nbsp;===</div><div>Starting&nbsp;RabbitMQ&nbsp;3.6.1&nbsp;on&nbsp;Erlang&nbsp;18.3</div><div>Copyright&nbsp;(C)&nbsp;2007-2016&nbsp;Pivotal&nbsp;Software,&nbsp;Inc.</div><div>Licensed&nbsp;under&nbsp;the&nbsp;MPL.&nbsp;&nbsp;See&nbsp;<a href="http://www.rabbitmq.com/" style="cursor: pointer; background-color: inherit;">http://www.rabbitmq.com/</a></div><div><div style="background-color: inherit;"><span style="color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;">...................................................................................................................................................................................................................................................</span></div></div><p style="margin-right: 0px; margin-left: 0px; color: #555555; font-family: 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, 'Lucida Grande', Tahoma, sans-serif;"><span style="color: #000000; background-color: inherit;"><br style="background-color: inherit;" /></span></p><p style="margin-right: 0px; margin-left: 0px; color: #333333;"><strong style="background-color: inherit;">卸载</strong></p><div style="font-size: 16px;">#rpm&nbsp;-qa|grep rabbitmq</div><div>rabbitmq-server-3.6.1-1.noarch</div><div style="font-size: 16px;">#rpm&nbsp;-e&nbsp;--nodeps&nbsp;rabbitmq-server-3.6.1-1.noarch</div><div style="font-size: 16px;"></div><div style="font-size: 16px;">#rpm&nbsp;-qa|grep&nbsp;erlang</div><div>esl-erlang-18.3-1.x86_64</div><div style="font-size: 16px;"><div>#rpm&nbsp;-e&nbsp;--nodeps&nbsp;esl-erlang-18.3-1.x86_64</div></div><p style="margin-right: 0px; margin-left: 0px;"><strong style="background-color: inherit;">管理</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">Rabbitmq服务器的主要通过rabbitmqctl和rabbimq-plugins两个工具来管理，以下是一些常用功能。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">1）. 服务器启动与关闭</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 启动: rabbitmq-server &#8211;detached</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关闭:rabbitmqctl stop</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 若单机有多个实例，则在rabbitmqctlh后加&#8211;n 指定名称</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">2）. 插件管理</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 开启某个插件：rabbitmq-pluginsenable xxx</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 关闭某个插件：rabbitmq-pluginsdisablexxx</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注意：重启服务器后生效。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">3）.virtual_host管理</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 新建virtual_host: rabbitmqctladd_vhost&nbsp; xxx</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 撤销virtual_host:rabbitmqctl&nbsp; delete_vhost xxx</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">4）. 用户管理</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 新建用户：rabbitmqctl add_user xxxpwd</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 删除用户:&nbsp;&nbsp; rabbitmqctl delete_user xxx</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 改密码: rabbimqctlchange_password {username} {newpassword}</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 设置用户角色：rabbitmqctlset_user_tags {username} {tag ...}</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag可以为 administrator,monitoring, management</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">5）. 权限管理</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 权限设置：set_permissions [-pvhostpath] {user} {conf} {write} {read}</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vhostpath</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vhost路径</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用户名</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Conf</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个正则表达式match哪些配置资源能够被该用户访问。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Write</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个正则表达式match哪些配置资源能够被该用户读。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Read</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一个正则表达式match哪些配置资源能够被该用户访问。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">6）. 获取服务器状态信息</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 服务器状态：rabbitmqctl status</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 队列信息：rabbitmqctl list_queues[-p vhostpath] [queueinfoitem ...]</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queueinfoitem可以为：name，durable，auto_delete，arguments，messages_ready，</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; messages_unacknowledged，messages，consumers，memory</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exchange信息：rabbitmqctllist_exchanges[-p vhostpath] [exchangeinfoitem ...]</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exchangeinfoitem有：name，type，durable，auto_delete，internal，arguments.</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Binding信息：rabbitmqctllist_bindings[-p vhostpath] [bindinginfoitem ...]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bindinginfoitem有：source_name，source_kind，destination_name，destination_kind，routing_key，arguments</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Connection信息：rabbitmqctllist_connections [connectioninfoitem ...]</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Connectioninfoitem有：recv_oct，recv_cnt，send_oct，send_cnt，send_pend等。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Channel信息：rabbitmqctl&nbsp; list_channels[channelinfoitem ...]</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Channelinfoitem有consumer_count，messages_unacknowledged，messages_uncommitted，acks_uncommitted，messages_unconfirmed，prefetch_count，client_flow_blocked</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"><strong style="background-color: inherit;">常用命令：</strong></p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">查看所有队列信息</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"># rabbitmqctl list_queues</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">关闭应用</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"># rabbitmqctl stop_app</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">启动应用，和上述关闭命令配合使用，达到清空队列的目的</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"># rabbitmqctl start_app</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">清除所有队列</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"># rabbitmqctl reset</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">更多用法及参数，可以执行如下命令查看</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;"># rabbitmqctl</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">&nbsp;</p><h2>rabbitmq常用命令</h2><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmq-server start &nbsp;或者 &nbsp;&nbsp;service rabbitmq-server start &nbsp; &nbsp; #启动rabbitmq</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmqctl list_exchanges&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmqctl list_bindings</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmqctl list_queues #分别查看当前系统种存在的Exchange和Exchange上绑定的Queue信息。</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmqctl status &nbsp;#查看运行信息</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmqctl stop &nbsp; &nbsp; #停止运行rabbitmq</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">rabbitmq-plugins enable rabbitmq_management &nbsp;</p><p style="margin-right: 0px; margin-left: 0px; font-family: Verdana, Arial, Helvetica, sans-serif;">#启动rabbitmq的图形管理界面，这个操作必须重启rabbitmq，&nbsp;然后在web中 http://127.0.0.1:15672 用户名和密码都是guest guest。如果局域网无法访问设置防火墙过滤规则或关闭防火墙。</p><div></div><br /></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/430785.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-05 20:08 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/05/430785.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>官网指南-RabbitMQ集群指南</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/05/430784.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sun, 05 Jun 2016 11:53:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/05/430784.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430784.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/05/430784.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430784.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430784.html</trackback:ping><description><![CDATA[<h1><span style="font-size: 14px;">概述</span></h1><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ broker是一个或多个Erlang节点的逻辑分组，多个运行的RabbitMQ应用程序可共享用户，虚拟主机，队列，交换机，绑定以及运行时参数。有时我们将多个节点的集合称为集群。</p><div style="background-color: inherit;"><h3>什么是复制?</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ broker操作所需的所有数据/状态都可以在多个节点间复制. 例外是消息队列,默认情况下它驻留在一个节点， 尽管它们对所有节点来说，是可见的，可达的<span style="line-height: 1.5;">.要在集群中跨节点复制队列，可参考</span><a href="http://www.rabbitmq.com/ha.html" style="cursor: pointer; line-height: 1.5; color: #444444; font-weight: bold;">high availability</a><span style="line-height: 1.5;">&nbsp;文档(注意，你仍然先需要一个工作集群).</span></p></div><div style="background-color: inherit;"><h3>主机名解析需求</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ节点彼此之间使用域名，要么是简短的，要么是全限定的(FQDNs). 因此，集群中所有成员的主机名都必须是可解析的，也可用于机器上的命令行工具，如<span style="color: #333333; background-color: inherit;">rabbitmqctl</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">主机名解析可使用任何一种标准的操作系统提供方法:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;">DNS 记录</li><li style="background-color: inherit;">本地主机文件(e.g.&nbsp;<span style="color: #333333; background-color: inherit;">/etc/hosts</span>)</li></ul>在更加严格的环境中，DNS记录或主机文件修改是受限的,不可能的或不受欢迎的,&nbsp;<a href="http://erlang.org/doc/apps/erts/inet_cfg.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Erlang VM可通过使用替代主机名解析方法来配置</a>, 如一个替代的DNS服务器,一个本地文件，一个非标准的主机文件位置或一个混合方法. 这些方法可以与标准操作主机名解析方法一起协同工作。<p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要使用FQDNs, 参考<span style="color: #333333; background-color: inherit;">RABBITMQ_USE_LONGNAME</span>&nbsp;in the&nbsp;<a href="http://www.rabbitmq.com/configure.html#define-environment-variables" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Configuration guide</a>.</p></div><div style="background-color: inherit;"><h3>集群构成</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">集群可以通过多种方式来构建:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;">手动使用<span style="color: #333333; background-color: inherit;">rabbitmqctl</span></li><li style="background-color: inherit;">通过在<a href="http://www.rabbitmq.com/configure.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">配置文件</a>列举集群节点来声明</li><li style="background-color: inherit;">通过使用<a href="https://github.com/aweber/rabbitmq-autocluster/" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">rabbitmq-autocluster</a>&nbsp;(插件)来声明</li><li style="background-color: inherit;">使用<a href="http://github.com/rabbitmq/rabbitmq-clusterer" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">rabbitmq-clusterer</a>（插件）来声明</li></ul><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">一个集群的构成可以动态修改. 所有RabbitMQ brokers开始都是以单个节点来运行的. 这些节点可以加入到集群中, 随后也可以脱离集群再次成为单一节点。</p></div><div style="background-color: inherit;"><h3>故障处理</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ brokers 可以容忍个别节点故障. 节点可以随意地启动和关闭，只要在已知关闭的时间内能够联系到集群节点.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ 集群有多种模式来处理<a href="http://www.rabbitmq.com/partitions.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">网络分化</a>, 主要是一致性方向. 集群是在LAN中使用的，不推荐在WAN中运行集群.&nbsp;<a href="http://www.rabbitmq.com/shovel.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Shovel</a>&nbsp;或&nbsp;<a href="http://www.rabbitmq.com/federation.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Federation</a>&nbsp;插件对于跨WAN连接brokers&nbsp;，有更好的解决方案. 注意&nbsp;<a href="http://www.rabbitmq.com/distributed.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Shovel 和 Federation 不等同于集群</a>.</p></div><div style="background-color: inherit;"><h3>磁盘和内存节点</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">节点可以是磁盘节点，也可以是内存节点。多数情况下，你希望所有的节点都是磁盘节点，但RAM节点是一种特殊情况，它可以提高集群中队列和，交换机，绑定的性能. 当有疑问时，最好只使用磁盘节点。</p></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><h2>集群文字记录(Transcript)</h2><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">下面是通过三台机器－<span style="color: #333333;">rabbit1</span>,&nbsp;<span style="color: #333333;">rabbit2</span>,&nbsp;<span style="color: #333333;">rabbit3来设置和操作Rabb</span>itMQ集群的文字记录.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">我们假设用户已经登录到这三台机器上，并且都已经在机器上安装了RabbitMQ,以及rabbitmq-server 和rabbitmqctl 脚本都已经在用户的PATH环境变量中.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">This transcript can be modified to run on a single host, as explained more details below.</p><div style="color: #555555; background-color: inherit;"><h3>节点(以及CLI工具)之间如何来认证: Erlang Cookie</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ 节点和CLI 工具(如<span style="color: #333333; background-color: inherit;">rabbitmqctl</span>) 使用cookie来确定每个节点之间是否可以通信. 两个节点之间要能通信，它们必须要有相同的共享密钥Erlang cookie. cookie只是具有字母数字特征的字符串。只要你喜欢，它可长可短. 每个集群节点必须有相同的cookie.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当RabbitMQ&nbsp;服务器启动时，Erlang VM 会自动地创建一个随机的cookie文件. 最简单的处理方式是允许一个节点来创建文件，然后再将这个文件拷贝到集群的其它节点中。</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">在 Unix 系统中, cookie的通常位于<span style="color: #333333; background-color: inherit;">/var/lib/rabbitmq/.erlang.cookie</span>&nbsp;或<span style="color: #333333; background-color: inherit;">$HOME/.erlang.cookie</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">在Windows中, 其位置在<span style="color: #333333; background-color: inherit;">C:\Users\Current User\.erlang.cookie</span>(<span style="color: #333333; background-color: inherit;">%HOMEDRIVE% + %HOMEPATH%\.erlang.cookie</span>) 或<span style="color: #333333; background-color: inherit;">C:\Documents and Settings\Current User\.erlang.cookie</span>, 对于RabbitMQ Windows service其位置在<span style="color: #333333; background-color: inherit;">C:\Windows\.erlang.cookie。如果使用了</span>Windows service , &nbsp;cookie可被放于这两个位置中.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">作为替代方案，你可以在&nbsp;<span style="color: #333333;">rabbitmq-server&nbsp;</span>和&nbsp;<span style="color: #333333;">rabbitmqctl</span>&nbsp;脚本中调用erl时,插入"<span style="color: #333333; background-color: inherit;">-setcookie&nbsp;cookie</span>"选项.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当cookie未配置时 (例如，不相同), RabbitMQ 会记录这样的错误"Connection attempt from disallowed node" and "Could not auto-cluster".</p></div><div style="background-color: inherit;"><h3>启动独立节点</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">集群可通过重新配置，而将现有RabbitMQ 节点加入到集群配置中. 因此第一步是以正常的方式在所有节点上启动RabbitMQ:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmq-server -detached</span> <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmq-server -detached</span> <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmq-server -detached</span></pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">这会创建三个独立的RabbitMQ brokers, 每个节点一个，可通过cluster_status命令来验证:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1]}]},{running_nodes,[rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit2]}]},{running_nodes,[rabbit@rabbit2]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit3 ... [{nodes,[{disc,[rabbit@rabbit3]}]},{running_nodes,[rabbit@rabbit3]}] ...done.</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">以<span style="color: #333333; background-color: inherit;">rabbitmq-server</span>&nbsp;shell脚本来启动<span style="color: #555555;">RabbitMQ broker的节点名称是</span><span style="color: #333333; background-color: inherit;">rabbit@shorthostname</span>,在这里，短节点名称是小写的(如上面的<span style="color: #333333; background-color: inherit;">rabbit@rabbit1</span>). 如果在windows上，你使用<span style="color: #333333; background-color: inherit;">rabbitmq-server.bat批处理文件来启动，短节点名称是大写的</span>（如：<span style="color: #333333; background-color: inherit;">rabbit@RABBIT1</span>). 当你输入节点名称时，不论是大写还是小写的，这些字符串都必须精确匹配。</p></div><div style="background-color: inherit;"><h3>创建集群</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">为了把这三个节点构建到一个集群中，我们可以告诉其中的两个节点, 假设为<span style="color: #333333; background-color: inherit;">rabbit@rabbit2</span>&nbsp;和&nbsp;<span style="color: #333333; background-color: inherit;">rabbit@rabbit3</span>, 将加入到第三个节点的集群中，这第三个节点假设为<span style="color: #333333; background-color: inherit;">rabbit@rabbit1</span>.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">首先我们将<span style="color: #333333; background-color: inherit;">rabbit@rabbit2加入到</span><span style="color: #333333; background-color: inherit;">rabbit@rabbit1的集群中</span>. 要做到这一点，我们必须在<span style="color: #333333; background-color: inherit;">rabbit@rabbit2</span>&nbsp;上停止RabbitMQ应用程序，并将其加入到<span style="color: #333333; background-color: inherit;">rabbit@rabbit1</span>&nbsp;集群中, 然后再重启RabbitMQ 应用程序.&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">注意：加入集群会隐式地重置节点, 因此这会删除此节点上先前存在的所有资源和数据.（如何备份数据）</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span> <br />Stopping node rabbit@rabbit2 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl join_cluster rabbit@rabbit1</span> <br />Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> <br />Starting node rabbit@rabbit2 ...done.</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">在每个节点上通过运行cluster_status&nbsp;命令，我们可以看到两个节点已经加入了集群:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]},  {running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}] ...done. </pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">现在我们将<span style="color: #333333; background-color: inherit;">rabbit@rabbit3节点加入到同一个集群中</span>. 操作步骤同上面的一致,除了这次我们选择<span style="color: #333333; background-color: inherit;">rabbit2来加入集群，但这并不重要：</span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span> <br />Stopping node rabbit@rabbit3 ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl join_cluster rabbit@rabbit2</span> <br />Clustering node rabbit@rabbit3 with rabbit@rabbit2 ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> <br />Starting node rabbit@rabbit3 ...done.</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">在任何一个节点上通过运行cluster_status命令，我们可以看到三个节点已经加入了集群:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit3,rabbit@rabbit2,rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit3,rabbit@rabbit1,rabbit@rabbit2]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit3 ... [{nodes,[{disc,[rabbit@rabbit3,rabbit@rabbit2,rabbit@rabbit1]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1,rabbit@rabbit3]}] ...done.</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">通过上面的步骤，当集群运行的时候，我们可以在任何时候将新的节点加入到集群中.</p></div><div style="background-color: inherit;"><h3>重启集群节点</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">注意，加入到集群中的节点可在任何时候停止， 对于崩溃来说也没有问题. 在这两种情况下，集群剩余的节点将不受影响地继续操作，当它们重启的时候，这些崩溃的节点会再次自动追赶上其它的集群节点。</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">我们关闭了节点<span style="color: #333333; background-color: inherit;">rabbit@rabbit1和</span><span style="color: #333333; background-color: inherit;">rabbit@rabbit3</span>，并在每步观察集群的状态:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop</span> <br />Stopping and halting node rabbit@rabbit1 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit3,rabbit@rabbit2]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit3 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit3]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop</span> <br />Stopping and halting node rabbit@rabbit3 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit2]}] ...done.</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">译者注：关闭了<span style="color: #333333; line-height: 1.5; background-color: inherit;">rabbit1节点后，运行的节点已经没有rabbit1节点了</span></p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">现在我们再次启动节点,并检查集群状态:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmq-server -detached</span> <br />rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmq-server -detached</span> <br />rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1,rabbit@rabbit3]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit3 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1,rabbit@rabbit3]}] ...done.</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">这里有一些重要的警告:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="color: #555555; background-color: inherit;">当整个集群崩溃的时候， 最后一个崩溃的节点必须第一个上线.如果不是这样，节点将会等待最后一个磁盘节点30秒以确认其重新上线，否则就会失败. 如果最后一个下线的节点，不能再重新上线，那么它可能会使用<span style="color: #333333; background-color: inherit;">forget_cluster_node命令来从集群中删除</span>&nbsp;- 查阅&nbsp;<span style="color: #333333; background-color: inherit;">rabbitmqctl页面来了解更多信息</span>.</li><li style="background-color: inherit;">如果所有集群节点都在同一个时间内停止且不受控制（如断电）。在这种情况下，你可以在某个节点上使用<span style="color: #333333; background-color: inherit;">force_boot命令使其再次成为可启动的－<span style="color: #555555;">查阅&nbsp;</span>rabbitmqctl页面来了解更多信息<span style="color: #555555;">.</span></span></li></ul></div><div style="color: #555555; background-color: inherit;"><h3>脱离集群</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当节点不再是集群的一部分时，可以明确地将其从集群中删除. 首先我们将节点<span style="color: #333333; background-color: inherit;">rabbit@rabbit3从集群中删除</span>, 以使其回归独立操作.要做到这一点，需要在<span style="color: #333333; background-color: inherit;">rabbit@rabbit3节点上停止</span>RabbitMQ 应用程序,重设节点，并重启RabbitMQ应用程序.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span> <br />Stopping node rabbit@rabbit3 ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl reset</span> <br />Resetting node rabbit@rabbit3 ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> <br />Starting node rabbit@rabbit3 ...done.</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="line-height: 1.5;">在节点上运行</span><span style="line-height: 1.5;">cluster_status</span><span style="line-height: 1.5;">&nbsp;命令来确认</span><span style="line-height: 1.5; color: #333333;">rabbit@rabbit3节点现在已不再是集群的一部分，并且会独自操作</span><span style="line-height: 1.5;">:</span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]},  {running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit3 ... [{nodes,[{disc,[rabbit@rabbit3]}]},{running_nodes,[rabbit@rabbit3]}] ...done. </pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">我们也可以远程地删除节点，这是相当有用的，举例来说，当处理无反应的节点时.举例来说，我们可以从&nbsp;<span style="color: #333333;">rabbit@rabbit2中删除</span><span style="color: #333333; background-color: inherit;">rabbit@rabbi1</span>.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span> <br />Stopping node rabbit@rabbit1 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl forget_cluster_node rabbit@rabbit1</span> <br />Removing node rabbit@rabbit1 from cluster ... ...done.</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">注意，<span style="color: #333333; background-color: inherit;">rabbit1仍然认为它与</span><span style="color: #333333; background-color: inherit;">rabbit2处在一个集群中，但尝试启动时会出现一个错误</span>.这时，我们需要对其进行重置以使其能再次启动.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> <br />Starting node rabbit@rabbit1 ... Error: inconsistent_cluster: Node rabbit@rabbit1 thinks it's clustered with node rabbit@rabbit2, but rabbit@rabbit2 disagrees <br />rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl reset</span> <br />Resetting node rabbit@rabbit1 ...done. <br />rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> Starting node rabbit@mcnulty ... ...done.</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">现在，&nbsp;cluster_status&nbsp;命令会显示三个节点都是独立节点，并且操作是独立的:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1]}]},{running_nodes,[rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit2]}]},{running_nodes,[rabbit@rabbit2]}] ...done. <br />rabbit3$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit3 ... [{nodes,[{disc,[rabbit@rabbit3]}]},{running_nodes,[rabbit@rabbit3]}] ...done.</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">注意：<span style="color: #333333; background-color: inherit;">rabbit@rabbit2节点仍然残留有集群的状态（译者注：怎么看出来的呢？）</span>, 但是&nbsp;<span style="color: #333333; background-color: inherit;">rabbit@rabbit1</span>&nbsp;和<span style="color: #333333; background-color: inherit;">rabbit@rabbit3</span>&nbsp;节点是新鲜的RabbitMQ brokers.如果我们想重新初始化<span style="color: #333333; background-color: inherit;">rabbit@rabbit2节点，我们可以按其它节点的步骤来操作</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span> <br />Stopping node rabbit@rabbit2 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl reset</span> <br />Resetting node rabbit@rabbit2 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> <br />Starting node rabbit@rabbit2 ...done.</pre></div></div><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><h2>升级集群</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当从主版本或小版本进行升级时 (如：从3.0.x 到3.1.x,或从2.x.x 到3.x.x),或者是升级Erlang时, 整个集群在升级时必须记下来（taken down） (因为集群不会像这样来运行多个混合的版本). 当从补丁版本升级到另一个时(如：从3.0.x 到3.0.y)时，这种情况是不会出现的;这些版本在集群中是可以混合使用的(例外是3.0.0不能与 3.0.x 系列后的版本混合).</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">在主版本与小版本之间升级时，RabbitMQ有必要的话会自动更新其持久化数据. 在集群中，此任务是由第一个磁盘节点来启动的("upgrader"节点). 因此在升级RabbitMQ集群时，你不需要尝试先启动RAM节点，任何启动的RAM节点都会发生错误，并且不能启动.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">虽然不是严格必须的，但使用磁盘节点来作为升级节点通常是好的主意，最后停止那个节点。</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">自动升级只适用于2.1.1及其之后的版本，如果你有更早的集群 ，你必须重新构建升级<span style="line-height: 1.5;">.</span></p></div><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><h2>单台机器上的集群</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">在某些情况下，在一台机器上运行RabbitMQ节点的集群是有用的（试验性质）.&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要在一台机器上运行多个RabbitMQ节点,必须确保节点含有不同的节点名称,数据存储路径，日志文件位置，绑定到不同的端口，并包含那些插件使用的端口等等 .参考配置指南中的<span style="color: #333333; background-color: inherit;">RABBITMQ_NODENAME</span>,&nbsp;<span style="color: #333333; background-color: inherit;">RABBITMQ_NODE_PORT</span>, 和&nbsp;<span style="color: #333333; background-color: inherit;">RABBITMQ_DIST_PORT文档</span>&nbsp;,以及&nbsp;<a href="http://www.rabbitmq.com/relocate.html" style="cursor: pointer; color: #444444; font-weight: bold;">File and Directory Locations guide</a>指南中的&nbsp;<span style="color: #333333; background-color: inherit;">RABBITMQ_MNESIA_DIR</span>,&nbsp;<span style="color: #333333; background-color: inherit;">RABBITMQ_CONFIG_FILE</span>, and&nbsp;<span style="color: #333333; background-color: inherit;">RABBITMQ_LOG_BASE。</span></p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">你可以在同一个主机上通过重复调用<span style="color: #333333;">rabbitmq-server</span>(<span style="color: #333333;">rabbitmq-server.bat</span>&nbsp;on Windows)来手动地启动多个节点&nbsp;. 例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">$ RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=rabbit rabbitmq-server -detached <br />$ RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=hare rabbitmq-server -detached <br />$ rabbitmqctl -n hare stop_app <br />$ rabbitmqctl -n hare join_cluster rabbit@`hostname -s` <br />$ rabbitmqctl -n hare start_app</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">这会设置两个节点的集群，这两个节点都是磁盘节点. 注意，如果你想打开非AMQP的其它端口，你需要通过命令行进行配置<span style="line-height: 1.5;">：</span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">$ RABBITMQ_NODE_PORT=5672 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15672}]" RABBITMQ_NODENAME=rabbit rabbitmq-server -detached <br />$ RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" RABBITMQ_NODENAME=hare rabbitmq-server -detached</pre></div><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><h2>主机名称变更</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ节点使用主机名来相互通信.因此，所有节点名称都集群中的节点应该都能被解析.对于像&nbsp;<span style="color: #333333; background-color: inherit;">rabbitmqctl这样的工具来说，也是如此</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">除此之外，默认情况下，RabbitMQ使用当前系统的主机名称来命名数据库目录.如果主机名变了，将会创建一个空的数据库.为避免数据丢失，应该总是设置一个固定的，可解析的主机名称。无论何时，只要主机名变化了，你就必须要重启RabbitMQ:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">$ /etc/init.d/rabbitmq-server restart</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">类似的效果可通过使用&nbsp;<span style="color: #333333;">rabbit@localhost作为broker节点名称来达到。这个解决方案的影响是集群将不会工作，因为选中的主机名不能被远程主机所解析。当从远程主机调用时，类似地</span><span style="color: #333333; background-color: inherit;">rabbitmqctl命令也会失败</span>. 免遭此缺点的复杂方案是使用DNS,如：如果运行EC2，则使用&nbsp;<a href="http://aws.amazon.com/route53/" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Amazon Route 53</a>&nbsp;。如果你想使用节点名称的全限定主机名（RabbitMQ 默认使用短名称),那么可使用DNS解析， 可设置环境变量&nbsp;<span style="color: #333333; background-color: inherit;">RABBITMQ_USE_LONGNAME=true</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><br style="background-color: inherit;" /></p></div><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><h2>防火墙节点</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当在一个数据中心或可靠网络时，带防火墙的集群节点是存在的，但这些节点通常被防火墙隔离。再一次声明，当各节点之间的网络连接不稳定时，集群不建议在WAN在使用<span style="line-height: 1.5;">。</span></p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">在多数配置中，你需要打开4369和25672端口以使用集群正常工作.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">Erlang 使用Port Mapper Daemon (epmd) 来解析集群中的节点名称. 默认epmd端口是4369,但它可以通过<span style="color: black; background-color: inherit;">ERL_EPMD_PORT环境变量进行修改</span>.所有的节点都必须使用同一个端口。详细信息可参考<a href="http://www.erlang.org/doc/man/epmd.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Erlang epmd manpage</a>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">一旦分布式Erlang节点通过empd解析后，其它节点将会尝试直接通信。默认地通信端口比<span style="color: black; background-color: inherit;">RABBITMQ_NODE_PORT</span>&nbsp;(即，默认是25672)高了20000. 这可以通过<span style="color: black; background-color: inherit;">RABBITMQ_DIST_PORT</span>&nbsp;环境变量修改</p></div><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><h2>跨集群Erlang版本</h2>集群中所有节点必须运行相同版本的<a href="http://www.rabbitmq.com/which-erlang.html" style="cursor: pointer; color: #444444; font-weight: bold; background-color: inherit;">Erlang</a>.</div><div style="font-family: 微软雅黑; color: #555555; background-color: #ffffff;"><h2>从客户端连接集群</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">客户端可以正常连接到集群中的任意节点，如果那个节点发生故障了 ，只要有剩余集群节点幸存，当客户端发现在关闭的连接时，它就能够重新连接到剩余幸存的集群节点上。一般来说，将节点主机名称或IP地址放到客户端程序是极其不明智的，这会导致缺乏灵活性，并需要客户端程序重新编辑，编译，重新配置以适应集群配置变化或者集群节点变化。相反，我们建议采用更抽象的方法<span style="line-height: 1.5;">: 如有简短TTL配置的动态DNS服务或普通的TCP负载均衡器.&nbsp;<span style="color: #35a1d4; text-align: justify; background-color: rgba(255, 255, 255, 0.8);">一般来说,这方面的管理集群内连接节点是超出了RabbitMQ本身的范围,我们建议使用其他技术专门设计来解决这些问题。</span></span></p></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><h2>内存节点集群</h2><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">内存节点只在内存中保存其元数据。它不会像磁盘节点将元数据写入到磁盘中，但它们拥有更好的性能。 然而，也应该注意到，由于持久化队列数据总是存储在磁盘上的，其性能提升只会影响资源管理(如： 添加/删除队列,交换机,或虚拟主机), 但不会影响发布或消费的速度.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">内存节点是一个高级使用例子;当设置你的第一个集群时，你应该不使用它们。你应该用足够的磁盘节点来处理冗余需求，然后如果有必要，再用内存节点进行扩展.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">集群中只含有内存节点是相当脆弱的，如果集群停止了，你将不能再次启动，并且会导致数据丢失。RabbitMQ在许多情况下，会阻止创建只包含内存节点的集群，但不能完全阻止。</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">（译者注：在集群构建中，最好有两个或以上的磁盘节点，然后再考虑使用内存节点进行扩展）</p><div style="background-color: inherit;"><h3>创建内存节点</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">当节点加入集群时，我们可将其声明为内存节点. 我们可以通过使用像先前<span style="color: #333333; background-color: inherit;">rabbitmqctl join_cluster命令再加</span><span style="color: #333333; background-color: inherit;">--ram标志来达到目的</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span> <br />Stopping node rabbit@rabbit2 ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl join_cluster --ram rabbit@rabbit1</span> <br />Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span> Starting node rabbit@rabbit2 ...done.</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;"><br style="background-color: inherit;" /></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; background-color: #eeeeee;">rabbit1$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit1 ... [{nodes,[{disc,[rabbit@rabbit1]},{ram,[rabbit@rabbit2]}]},  {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}] ...done. <br />rabbit2$ <span style="color: #8b0000; background-color: inherit;">rabbitmqctl cluster_status</span> <br />Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1]},{ram,[rabbit@rabbit2]}]},  {running_nodes,[rabbit@rabbit1,rabbit@rabbit2]}] ...done. </pre></div><div style="color: #555555; background-color: inherit;"><h3>改变节点类型</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">我们可以将节点的类型从磁盘修改为内存，反之亦然. 假设我们想反转<span style="color: #333333; background-color: inherit;">rabbit@rabbit2</span>&nbsp;和&nbsp;<span style="color: #333333; background-color: inherit;">rabbit@rabbit1的节点类型</span>,即先将内存节点转换为磁盘节点，随后再将其从磁盘节点转换为内存节点.要做到这点，我们可以使用<span style="color: #333333; background-color: inherit;">change_cluster_node_type命令</span>. 首先节点必须先停止.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit;">rabbit2$ </span><span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span><span style="background-color: inherit;"> <br />Stopping node rabbit@rabbit2 ...done. rabbit2$ <br /></span><span style="color: #8b0000; background-color: inherit;">rabbitmqctl change_cluster_node_type disc</span><span style="background-color: inherit;"> <br />Turning rabbit@rabbit2 into a disc node ... ...done. Starting node rabbit@rabbit2 ...done. <br />rabbit1$ </span><span style="color: #8b0000; background-color: inherit;">rabbitmqctl stop_app</span><span style="background-color: inherit;"> <br />Stopping node rabbit@rabbit1 ...done. <br />rabbit1$ </span><span style="color: #8b0000; background-color: inherit;">rabbitmqctl change_cluster_node_type ram</span><span style="background-color: inherit;"> <br />Turning rabbit@rabbit1 into a ram node ... <br />rabbit1$ </span><span style="color: #8b0000; background-color: inherit;">rabbitmqctl start_app</span><span style="background-color: inherit;"><span style="background-color: inherit;"> <br />Starting node rabbit@rabbit1 ...done.</span></span></pre></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/430784.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-05 19:53 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/05/430784.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ-CookBook-第2章-超越AMQP标准</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/05/430783.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Sun, 05 Jun 2016 11:51:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/05/430783.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430783.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/05/430783.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430783.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430783.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;">本章我们将覆盖:</span><br style="background-color: inherit;" /><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">如何使用消息过期</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">如何使指定队列上的消息过期</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">如何让队列过期</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">管理驳回的(rejected)或过期的消息</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">理解其它备用交换器扩展</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">理解有效user-ID扩展</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">通知队列消息者失败</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">理解交换器到交换器扩展</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">在消息中嵌入消息目的地</span></li></ol></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;">介绍</span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;">在本章中，我们将展示关于RabbitMQ扩展上的一些食谱.这些扩展不是<span style="background-color: inherit;">AMQP 0-9-1标准的一部分，使用它们会破坏其它AMQPbroker的兼容性。<span style="background-color: inherit;"><br style="background-color: inherit;" /><span style="background-color: inherit;">另一方面, 在AMQP&nbsp;<span style="background-color: inherit;">0-10 (<span style="background-color: inherit;">http://www.amqp.org/specification/0-10/amqp-org-download<span style="background-color: inherit;">)中也出现了轻微的变化,这是一个简单通往那里的路径<span style="background-color: inherit;">.最后, 它们通常是优化问题的有效解决方案。</span></span></span></span></span></span></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;"><br style="background-color: inherit;" /></span></span></span></span></span></span></span></span></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">本章中的例子将更为真实，例如,配置参数，如列表和交换器， 以及路由键名称将定义在<span style="line-height: 1.5; background-color: inherit;">Constants接口中。事实上，一个真正的应用程序会遵循这样的准则从配置文件中读取配置文件，以在不同应用程序中共享。</span></div><div style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">然而，在下面的例子中，为了更简短和较好的可读性，我们并没有指定</span><span style="line-height: 1.5; background-color: inherit;">Constants的命名空间。</span></div><div style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何让消息过期</strong></div><div style="background-color: inherit;">在本食谱中，我们将展示如何让消息过期.食谱的资源可在<span style="line-height: 1.5; background-color: inherit;">Chapter02/Recipe01/Java/src/rmqexample中找到，如：</span></div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">Producer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">Consumer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">GetOne.java</span></li></ol></div><div style="background-color: inherit;"><strong style="background-color: inherit;">准备</strong></div><div style="background-color: inherit;">为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何做</strong></div><div style="background-color: inherit;">本示例的核心是Producer.java文件.为了产生在给定生存时间(TTL)后过期的消息，我们需要执行下面的步骤：</div><div style="background-color: inherit;">1. 创建或声明一个用来发送消息的交换器， 并将其绑定到队列上，就像第1章使用AMQP看到的一样：</div><div style="background-color: inherit;">channel.exchangeDeclare(exchange,&nbsp;"direct",&nbsp;false);</div><div style="background-color: inherit;">channel.queueDeclare(queue,&nbsp;false,&nbsp;false,&nbsp;false,&nbsp;null);</div><div style="background-color: inherit;">channel.queueBind(queue,&nbsp;exchange,&nbsp;routingKey);</div><div style="background-color: inherit;">2. 像下面这样初始化可选消息属性TTL:</div><div style="background-color: inherit;">BasicPropertiesmsgProperties&nbsp;=&nbsp;new&nbsp;<span style="line-height: 1.5; background-color: inherit;">BasicProperties.Builder().expiration("20000").build();</span></div><div style="background-color: inherit;">3. 使用下面的代码来发布消息:</div><div style="background-color: inherit;">channel.basicPublish(exchange,&nbsp;routingKey,&nbsp;msgProperties,<span style="line-height: 1.5; background-color: inherit;">statMsg.getBytes());</span></div><div style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;"><strong style="background-color: inherit;">如何工作</strong></span></div><div style="background-color: inherit;">在这个例子中，生产者创建了一个交换器，一个命名队列，并将它们进行了绑定，当队列上没有附着任何消费者，过期消息就显得非常有意义了。</div><div style="background-color: inherit;">设置过期时间TTL&nbsp;(以毫秒设置),会促使RabbitMQ在消息过期时，如果消息没有被客户端及时消费，立即删除消息<span style="line-height: 1.5; background-color: inherit;">.</span></div><div style="background-color: inherit;">在我们的例子中，我们假设应用程序发布了JVM资源统计信息到给定队列，如果存在消费者，那么会像平时一样，获取到实时数据，反之，如果不存在这样的消费者，那么消息会给定生存时间后立即过期<span style="line-height: 1.5; background-color: inherit;">。通过这种方式，可以避免我们收集大量的数据。一旦消息者绑定到了队列中，它会得到先前的消息（未过期）。进一步的试验，你可以用</span><span style="line-height: 1.5; background-color: inherit;">GetOne.java文件来替换Consumer.java文件运行.</span></div><div style="background-color: inherit;">在调用&nbsp;channel.basicGet() 时，会使你一次只能消费一个消息。</div><div style="background-color: inherit;">TIP</div><div style="background-color: inherit;">可使用channel.basicGet()方法来检查未消费消息的队列<span style="line-height: 1.5; background-color: inherit;">.也可以通过为第二参数传递false来调用，即</span><span style="line-height: 1.5; background-color: inherit;">autoAck标志.</span></div><div style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;">在这里我们可以通过调用<span style="line-height: 1.5; background-color: inherit;">rabbitmqctl&nbsp;list_queues来监控RabbitMQ队列的状态。&nbsp;</span>&nbsp;</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;">也可参考</span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">默认情况下，过期消息会丢失，但它们可以路由到其它地方。可参考管理拒绝消息或过期消息食谱来了解更多信息<span style="line-height: 1.5; background-color: inherit;">.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;"><strong style="background-color: inherit;">如何让指定队列上的消息过期</strong></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在本食谱中，我们将展示指定消息TTL的第二种方式.这次，我们不再通过消息属性来指定，而是通过缓存消息的队列来进行指定。在这种情况下，生产者只是简单地发布消息到交换器中，因此，在交换器上绑定标准队列和过期消息队列是可行的。</div><div style="background-color: inherit;">要在这方面进行备注，须存在一个创建自定义的队列的消费者。生产者是相当标准的<span style="line-height: 1.5; background-color: inherit;">.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">像前面的食谱一样，你可以在Chapter02/Recipe02/Java/<span style="line-height: 1.5; background-color: inherit;">src/rmqexample找到这三个源码。</span></div><div style="background-color: inherit;">&nbsp;</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div><strong style="background-color: inherit;">准备</strong></div><div>为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div style="background-color: inherit;"></div><strong style="background-color: inherit;">如何做</strong></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">现在我们将展示创建特定消息TTL队列的必要步骤。在我们的例子中，需要在<span style="line-height: 1.5; background-color: inherit;">Consumer.java文件中执行下面的步骤:</span></div><div style="background-color: inherit;">1. 按下面来声明交换器:</div><div style="background-color: inherit;">channel.exchangeDeclare(exchange,&nbsp;"direct",&nbsp;false);</div><div style="background-color: inherit;">2. 创建或声明队列，像下在这样为x-message-ttl可选参数指定10,000毫秒的超时时间：</div><div style="background-color: inherit;">Map&lt;String,&nbsp;Object&gt;&nbsp;arguments&nbsp;=&nbsp;new&nbsp;HashMap&lt;String,&nbsp;Object&gt;();</div><div style="background-color: inherit;">arguments.put("x-message-ttl",&nbsp;10000);</div><div style="background-color: inherit;">channel.queueDeclare(queue,&nbsp;false,&nbsp;false,&nbsp;false,&nbsp;arguments);</div><div style="background-color: inherit;">3.&nbsp;绑定队列到交换器上:</div><div style="background-color: inherit;">channel.queueBind(queue,&nbsp;exchange,&nbsp;routingKey);</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><strong>如何工作</strong></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在这个例子中，为了最终分析，我们再次假设生产者发送了JVM统计数据给RabbitMQ。最终因为<span style="line-height: 1.5; background-color: inherit;">Producer.java文件将其发到一个交换机，如果无消费者连接的话，消息最终会丢失。</span></div><div style="background-color: inherit;">想要监控或分析这些统计数据的消费有下面三种选择:</div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">绑定到一个临时队列，即调用无参的channel.queueDeclare()方法</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">绑定到一个非自动删除的命名队列</span></li><li style="background-color: inherit;">绑定到一个非自动删除的命名队列，并且指定<span style="line-height: 1.5; background-color: inherit;">x-message-ttl&nbsp;,如步骤2中展示的一样</span><span style="line-height: 1.5; background-color: inherit;">.</span></li></ol></div><div style="background-color: inherit;">在第一种情况中，消费者将获取实时统计数据，但当它掉线期间，它将不能在数据上执行分析。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在第二种情况中，为了能让它掉线期间，能获取到发送的消息，可以使用一个命名队列(最终是持久化的<span style="line-height: 1.5; background-color: inherit;">).但在掉线较长时间后，再重启时，它将有巨大的backlog来进行恢复，因此在队列中可能存在大部分旧消息的垃圾。</span></div><div style="background-color: inherit;">在第三种情况中，旧消息垃圾会通过RabbitMQ自己来执行，以使我们从消费者和broker中获益。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;">更多</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">当设置per-queue TTL, 就像本食谱中看到的一样，只要未到超时时间，消息就不会被丢弃，此时消费者还可以尝试消费它们。</div><div style="background-color: inherit;">当使用queue&nbsp;TTL时, 这里有一个细微的变化,但使用per-message&nbsp;TTL时，在broker队列中可能会存在过期消息<span style="line-height: 1.5; background-color: inherit;">.</span></div><div style="background-color: inherit;">在这种情况下，这些过期消息仍然会占据资源(内存)，同时broker统计数据中仍然会计数，直到它们不会到队列头部时。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;">也中参考</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在这种情况下，过期消息也会恢复。参考管理驳回或过期消息食谱<span style="line-height: 1.5; background-color: inherit;">.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><strong style="background-color: inherit;">如何让队列过期</strong></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在第三种情况中，TTL不关联任何消息，只关联对列。这种情况对于服务器重启和更新，是一个完美的选择。一旦TTL超时，<span style="line-height: 1.5; background-color: inherit;">在最后一个消费者停止消费后，RabbitMQ会丢弃队列.</span></div><div style="background-color: inherit;">前面TTL相关食谱，你可在<span style="line-height: 1.5; background-color: inherit;">Chapter02/Recipe03/Java/src/rmqexample 中找到&nbsp;Producer.java&nbsp;,&nbsp;&nbsp;Consumer.java&nbsp;,and&nbsp;&nbsp;GetOne.java 相关文件。</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div><strong style="background-color: inherit;">准备</strong></div><div>为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div><strong style="background-color: inherit;">如何做</strong></div><div style="background-color: inherit;">在前面的例子中，扩展只需要关注Consumer.java&nbsp;:</div><div style="background-color: inherit;">1. 使用下面的代码来创建或声明交换器:</div><div style="background-color: inherit;">channel.exchangeDeclare(exchange,&nbsp;"direct",&nbsp;false);</div><div style="background-color: inherit;">2.&nbsp;创建或声明队列，并为x-expires可选参数指定30,000毫秒的超时时间：</div><div style="background-color: inherit;">Map&lt;String,&nbsp;Object&gt;&nbsp;arguments&nbsp;=&nbsp;new&nbsp;HashMap&lt;String,<span style="line-height: 1.5; background-color: inherit;">Object&gt;();</span></div><div style="background-color: inherit;">arguments.put("x-expires",&nbsp;30000);</div><div style="background-color: inherit;">channel.queueDeclare(queue,&nbsp;false,&nbsp;false,&nbsp;false,<span style="line-height: 1.5; background-color: inherit;">arguments);</span></div><div style="background-color: inherit;">3. 将队列绑定到交换器上:</div><div style="background-color: inherit;">channel.queueBind(queue,&nbsp;exchange,&nbsp;routingKey);</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><strong style="background-color: inherit;">如何工作</strong></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">当我们运行Consumer.java或 GetOne.java 文件的时候, 超时队列已经创建好了，在消费者附着到队列上或调用<span style="line-height: 1.5; background-color: inherit;">channel.basicGet()时,它将持续存在</span><span style="line-height: 1.5; background-color: inherit;">.</span></div><div style="background-color: inherit;">只有当我们停止这两个操作超过30秒时，队列才会被删除，并且队列包含的消息也会清除。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;">TIP</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">无论生产者是否向其发送了消息，队列事实上都是独立删除的。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在这个试验课程中，我们可通过&nbsp;rabbitmqctl&nbsp;list_queues 命令来监控RabbitMQ 队列状态<span style="line-height: 1.5; background-color: inherit;">.</span></div><div style="background-color: inherit;">因此,我们可以想像一种场景，有一个统计分析程序需要重启来更新其代码。由于命名队列有较长的超时时间，因此重启时，不会丢失任何消息。如果我们停止，队列会在超过TTL后被删除，无价值的消息将不再存储。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><strong style="background-color: inherit;">管理驳回或过期消息</strong></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">在这个例子中，我们将展示如何使用死信交换器来管理过期或驳回的消息<span style="line-height: 1.5; background-color: inherit;">. 死信交换器是一种正常的交换器，死消息会在这里重定向，如果没有指定，死消息会被broker丢弃。</span></div><div style="background-color: inherit;">你可以在Chapter02/Recipe04/Java/src/rmqexample中找到源码文件<span style="line-height: 1.5; background-color: inherit;">:</span></div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">Producer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">Consumer.java</span></li></ol></div><div style="background-color: inherit;">要尝试过期消息,你可以使用第一个代码来发送带TTL的消息，就如如何使指定队列上消息过期食谱中描述的一样<span style="line-height: 1.5; background-color: inherit;">.</span></div><div style="background-color: inherit;">一旦启动了，消费者不允许消息过期，但可以可以驳回消息，最终导致成为死消息。</div><div style="background-color: inherit;"></div><div style="background-color: inherit;"><strong style="background-color: inherit;"></strong></div><div><strong style="background-color: inherit;">准备</strong></div><div>为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div style="background-color: inherit;"></div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何做</strong></div><div style="background-color: inherit;">下面的步骤展示了使用死信交换器来管理过期或驳回消息：</div><div style="background-color: inherit;">1. 创建一个工作交换品节和死信交换器:</div><div style="background-color: inherit;">channel.exchangeDeclare(Constants.exchange,&nbsp;"direct",&nbsp;false);</div><div style="background-color: inherit;">channel.exchangeDeclare(Constants.exchange_dead_letter,<span style="line-height: 1.5; background-color: inherit;">"direct",&nbsp;false);</span></div><div style="background-color: inherit;">2. 创建使用使用死信交换器和&nbsp;x-message-ttle参数的队列<span style="line-height: 1.5; background-color: inherit;">:</span></div><div style="background-color: inherit;">arguments.put("x-message-ttl",&nbsp;10000);</div><div style="background-color: inherit;">arguments.put("x-dead-letter-<span style="line-height: 1.5; background-color: inherit;">exchange",exchange_dead_letter);</span></div><div style="background-color: inherit;">channel.queueDeclare(queue,&nbsp;false,&nbsp;false,&nbsp;false,<span style="line-height: 1.5; background-color: inherit;">arguments);</span></div><div style="background-color: inherit;">3.&nbsp;然后像下面这样绑定队列:</div><div style="background-color: inherit;">channel.queueBind(queue,&nbsp;exchange,&nbsp;"");</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">4.&nbsp;最后使用channel.basicPublish()来向交换器发送消息&nbsp;.</div><div style="background-color: inherit;">5. 要尝试驳回消息，我们需要配置一个消费者，就像前面例子中看到的一样，并使用下面的代码来驳回消息：</div><div style="background-color: inherit;">basicReject(envelope.getDeliveryTag(),&nbsp;false);</div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何工作</strong></div><div style="background-color: inherit;">我们先从第一个场景开始(单独使用producer):&nbsp;the&nbsp;expired&nbsp;messages. 在步骤中，我们创建两个交换器，工作交换器和死信交换器。在步骤2中，我们使用下面两个可选参数来创建队列：</div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">使用arguments.put("x-message-ttl",&nbsp;10000)来设置消息TTL ,正如如何使指定队列上消息过期食谱中描述的一样</span><span style="line-height: 1.5; background-color: inherit;">.</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">使用arguments.put("x-dead-letter-</span><span style="line-height: 1.5; background-color: inherit;">exchange",&nbsp;exchange_dead_letter)来设置死信交换器名称;</span></li></ol></div><div style="background-color: inherit;">正如你所看到的，我们只是在配置中添加了可选的队列参数。因此，当生产者发送消息到交换器时，它会队列参数来路由。消息会在10秒后过期，之后它会重定向到<span style="line-height: 1.5; background-color: inherit;">exchange_dead_</span><span style="line-height: 1.5; background-color: inherit;">letter&nbsp;</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;">TIP</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">死信交换器是一个标准的交换器，因此你可以基于任何目的来使用<span style="line-height: 1.5; background-color: inherit;">.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">对于第二种场景，食谱的消费者会驳回消息.当消费者得到消息后， 它会使用basicReject()方法来发回一个否定应答(nack)，当broker收到nack时，它会将消息重定向到<span style="line-height: 1.5; background-color: inherit;">exchange_dead_letter. 通过在死信交换器上绑定队列，你可以管理这些消息。</span></div><div style="background-color: inherit;">当消息重定向到死信队列时，broker会修改header消息，并在x-dead键中增加下面的值：</div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">reason&nbsp;:&nbsp;表示队列是否过期的或驳回的(requeue&nbsp;=</span><span style="line-height: 1.5; background-color: inherit;">false&nbsp;)</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">queue&nbsp;:&nbsp;表示队列源，例如stat_queue_02/05</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">time&nbsp;:&nbsp;表示消息变为死信的日期和时间</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">exchange&nbsp;:&nbsp;表示交换器，如monitor_</span><span style="line-height: 1.5; background-color: inherit;">exchange_02/05</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">routing-keys&nbsp;: 表示发送消息时原先使用的路由键</span></li></ol></div><div style="background-color: inherit;">要在实践中查看这些值，你可使用GetOneDeadLetterQ 类.这可以创建<span style="line-height: 1.5; background-color: inherit;">queue_dead_letter队列并会绑定到exchange_dead_letter&nbsp;</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"><strong style="background-color: inherit;">更多</strong></div><div style="background-color: inherit;">你也可以使用arguments.put("x-dead-letter-routing-key",&nbsp;"myroutingkey")来指定死信路由键<span style="line-height: 1.5; background-color: inherit;">&nbsp;，它将会代替原来的路由键.这也就意味着你可以用不同的路由键来将不同消息路由到同一个队列中。相当棒。</span></div><div style="background-color: inherit;"><div style="background-color: inherit;"></div><div style="background-color: inherit;">理解交替交换器扩展</div><div style="background-color: inherit;">目前，在第1章使用 AMQP中我们已经展示了如何来处理未路由消息（消息发布到了交换器，但未能达到队列）<span style="line-height: 1.5; background-color: inherit;">.&nbsp;AMQP让生产者通过此条件进行应答，并最终决定是否有需要再次将消息分发到不同的目的地。通过这种扩展，我们可在broker中指定一个交替交换器来路由消息</span><span style="line-height: 1.5; background-color: inherit;">,而并不会对生产者造成更多的干预,本食谱的代码在</span><span style="line-height: 1.5; background-color: inherit;">Chapter02/Recipe05/Java/src/rmqexample&nbsp;.</span></div><div style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;"><strong style="background-color: inherit;"></strong></div><div><strong style="background-color: inherit;">准备</strong></div><div>为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div></div><div><strong style="background-color: inherit;">如何做</strong></div><div style="background-color: inherit;"></div><div style="background-color: inherit;">在本食谱中，我们会在Producer.java中声明交替交换器.</div><div style="background-color: inherit;">1. 将交换器的名字(无目的地路由消息)-<span style="line-height: 1.5; background-color: inherit;">alternateExchange&nbsp;,放到可选参数map的"alternate-</span><span style="line-height: 1.5; background-color: inherit;">exchange"中，如下所示:</span></div><div style="background-color: inherit;">Map&lt;String,&nbsp;Object&gt;&nbsp;arguments&nbsp;=&nbsp;new&nbsp;HashMap&lt;String,<span style="line-height: 1.5; background-color: inherit;">Object&gt;();</span></div><div style="background-color: inherit;">arguments.put("alternate-exchange",&nbsp;alternateExchange);</div><div style="background-color: inherit;">2.&nbsp;通过传递arguments&nbsp;map来声明交换器来发送消息:</div><div style="background-color: inherit;">channel.exchangeDeclare(exchange,&nbsp;"direct",&nbsp;false,&nbsp;false,<span style="line-height: 1.5; background-color: inherit;">arguments);</span></div><div style="background-color: inherit;">3.&nbsp;声明alternateExchange自身(已经在步骤1中指定了),如下所示:</div><div style="background-color: inherit;">channel.exchangeDeclare(alternateExchange,&nbsp;"direct",<span style="line-height: 1.5; background-color: inherit;">false);</span></div></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">4.&nbsp;声明标准化持久化队列，并使用路由键alertRK将其绑定到alternateExchange交换器中<span style="line-height: 1.5; background-color: inherit;">:</span></div><div style="background-color: inherit;">channel.queueDeclare(missingAlertQueue,&nbsp;true,&nbsp;false,&nbsp;false,<span style="line-height: 1.5; background-color: inherit;">null);</span></div><div style="background-color: inherit;">channel.queueBind(missingAlertQueue,&nbsp;alternateExchange,<span style="line-height: 1.5; background-color: inherit;">alertRK);</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"><strong style="background-color: inherit;">如何工作</strong></div><div style="background-color: inherit;">在这个例子中，我们再次使用了生成统计数据的producer,正如先前的例子一样<span style="line-height: 1.5; background-color: inherit;">.但这次，我们添加了路由键来让producer指定一个重要的级别，名为</span><span style="line-height: 1.5; background-color: inherit;">infoRK或alertRK&nbsp;(在例子中是随机分配的).如果你运行一个</span><span style="line-height: 1.5; background-color: inherit;">producer以及至少一个consumer,将不会丢失任何消息，并且一切都会正常工作</span><span style="line-height: 1.5; background-color: inherit;">.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;">TIP</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">Consumers在交换器和队列的声明中，必须传递相同的可选参数，否则会抛出异常。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">但如果没有消费者监听的话，而我们不想丢失报警的话，这就是为什么必须选择让<span style="line-height: 1.5; background-color: inherit;">producer创建alternateExchange&nbsp;(步骤3)并将其绑定到持久队列－</span><span style="line-height: 1.5; background-color: inherit;">missingAlertQueue的原因 (步骤4).</span></div><div style="background-color: inherit;">在单独运行producer的时候,你将看到报警存储在这里.alternate交换器让我们在不丢失消息的情况下可以路由消息<span style="line-height: 1.5; background-color: inherit;">.你可通过调用r</span><span style="line-height: 1.5; background-color: inherit;">abbitmqctllist_queues或运行CheckAlerts.java来检查状态 .</span></div><div style="background-color: inherit;">最后的代码让我们可以查看队列的内容和第一个消息，但不会进行消费。完成这种行为是简单的，它足可以避免这种事实：RabbitMQ client发送了ack,消息未消费，而只是进行监控。</div><div style="background-color: inherit;">现在，如果我们再次运行Consumer.java文件，它会从m<span style="line-height: 1.5; background-color: inherit;">issingAlertQueue队列中获取并消费消息.这不是自动的，我们可以选择性地从此队列中获取消息。</span></div><div style="background-color: inherit;">通过创建第二个消费者实例<span style="line-height: 1.5; background-color: inherit;">(&nbsp;missingAlertConsumer&nbsp;) 并使用相同的代码来从两个不同队列消费消息就可以完成这种效果。如果在处理实时消息时，想要得到不同的行为，那么我们可以创建一个不同的消费者。</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><span style="line-height: 1.5; background-color: inherit;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"><strong style="background-color: inherit;">更多</strong></div><div style="background-color: inherit;">在这个例子中，步骤3和步骤4是可选的。 当定义交换器时，可为交替交换器指定名称，对于其是否存在或是否绑定到任何队列上，并不作强制要求 。如果交替交换器不存在，生产者可通过在丢失消息上设置mandatory标志来得到应答，就如在第1章中处理未路由消息食谱中看到的一样。</div><div style="background-color: inherit;"><span data-aligning="#tran_0,#src_0" style="color: #666666; text-align: justify; background-color: rgba(255, 255, 255, 0.8);">甚至有可能出现另一种交换器－它自己的备用交换器,备用交换器可以是链式的，并且无目的地消息在按序地重试，直到找到一个目的地。</span></div><div style="background-color: inherit;">如果在交换器链的末尾仍然没有找到目的地，消息将会丢失，生产者可通过调设置<span style="line-height: 1.5; background-color: inherit;">mandatory 标志和指定一个合适的</span><span style="line-height: 1.5; background-color: inherit;">ReturnListener参数得到通知。</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"><strong style="background-color: inherit;">理解<span style="color: #333333; font-family: Tahoma, Arial, 宋体, 'Malgun Gothic'; text-align: justify; background-color: rgba(255, 255, 255, 0.8);">经过验证的</span>user-ID扩展</strong></div><div style="background-color: inherit;">依据AMQP, 当消费者得到消息时，它是不知道发送者信息的。一般说来，消费者不应该关心是谁生产的消息，对于生产者－消费者解藕来说是相当有利的。然而，有时出于认证需要，为了达到此目的，<span style="line-height: 1.5; background-color: inherit;">RabbitMQ 提供了有效的user-ID扩展。</span></div><div style="background-color: inherit;">在本例中，我们使用有效user-IDs模拟了订单。你可在<span style="line-height: 1.5; background-color: inherit;">Chapter02/Recipe06/Java/src/rmqexample中找到源码.</span></div><div style="background-color: inherit;"></div><div><strong style="background-color: inherit;">准备</strong></div><div>为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div style="background-color: inherit;"></div><div style="background-color: inherit;"></div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何做</strong></div><div style="background-color: inherit;">完成下面的步骤，以使用经过验证的user IDs来模拟订单:</div><div style="background-color: inherit;">1. 像下面一样声明或使用持久化队列:</div><div style="background-color: inherit;">channel.queueDeclare(queue,&nbsp;true,&nbsp;false,&nbsp;false,&nbsp;null);</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">2.发送消息时，使用BasicProperties对象，在消息头中指定一个user&nbsp;ID<span style="line-height: 1.5; background-color: inherit;">:</span></div><div style="background-color: inherit;">BasicProperties&nbsp;messageProperties&nbsp;=&nbsp;new&nbsp;<span style="line-height: 1.5; background-color: inherit;">BasicProperties.Builder()</span></div><div style="background-color: inherit;">.timestamp(new&nbsp;Date())</div><div style="background-color: inherit;">.userId("guest");</div><div style="background-color: inherit;">channel.basicPublish("",queue,&nbsp;messageProperties,<span style="line-height: 1.5; background-color: inherit;">bookOrderMsg.getBytes());</span></div><div style="background-color: inherit;">3. 消费者获取到订单后，可像下面这样打印订单数据和消息头：</div><div style="background-color: inherit;">System.out.println("The&nbsp;message&nbsp;has&nbsp;been&nbsp;placed&nbsp;by&nbsp;<span style="line-height: 1.5; background-color: inherit;">"+properties.getUserId());</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">如何工作</div><div style="background-color: inherit;">当设置了user-ID时,RabbitMQ 会检查是否是同一个用户打开的连接。在这个例子中，用户是<span style="line-height: 1.5; background-color: inherit;">guest&nbsp;,即RabbitMQ默认用户.</span></div><div style="background-color: inherit;">通过调用properties.getUserId() 方法，消费者可以访问发送者user&nbsp;ID。如果你想在步骤2中设置非当前用户的userId,<span style="line-height: 1.5; background-color: inherit;">channel.basicPublish()会抛出异常.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;">TIP</div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">如果不使用user-ID属性，用户将是非验证的，<span style="line-height: 1.5; background-color: inherit;">properties.getUserId()方法会返回null.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">也可参考</div><div style="background-color: inherit;">要更好的理解这个例子，你应该知道用户和虚拟机管理，这部分内容将在下个章节中讲解。在下个章节中，我们将了解如何通过在应用程序中使用SSL来提高程序的安全性。只使用<span style="line-height: 1.5; background-color: inherit;">user-ID属性，我们可保证用户已认证，但所有信息都是未加密的，因此很容易暴露。</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"><strong style="background-color: inherit;">队列失败时通知消费者</strong></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><strong style="background-color: inherit;"><br style="background-color: inherit;" /></strong></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">根据AMQP标准,消费者不会得到队列删除的通知。一个正在删除队列上等待消息的消费者不会收到任何错误信息，并会无限期地等待。然而，R<span style="line-height: 1.5; background-color: inherit;">abbitMQ&nbsp;client提供了一种扩展来让消息收到一个cancel参数－即消费者cancel通知。我们马上就会看到这个例子，你可在</span><span style="line-height: 1.5; background-color: inherit;">Chapter02/Recipe07/Java/src/rmqexample 中找到代码.</span></div><div style="background-color: inherit;"></div><div><strong style="background-color: inherit;"><br style="background-color: inherit;" /></strong></div><div><strong style="background-color: inherit;">准备</strong></div><div>为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样。</div><div style="background-color: inherit;"></div><div style="background-color: inherit;"><strong style="background-color: inherit;"><br style="background-color: inherit;" /></strong></div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何做</strong></div><div style="background-color: inherit;">为了能让扩展工作，你只需要执行下面的步骤:</div><div style="background-color: inherit;">1.在自定义的消费者中覆盖handleCancel()方法,可继承于<span style="line-height: 1.5; background-color: inherit;">com.rabbitmq.client.DefaultConsumer&nbsp;(指的是</span><span style="line-height: 1.5; background-color: inherit;">ActualConsumer.java&nbsp;):</span></div><div style="background-color: inherit;">public&nbsp;void&nbsp;handleCancel(String&nbsp;consumerTag)&nbsp;throws&nbsp;<span style="line-height: 1.5; background-color: inherit;">IOException&nbsp;{</span></div><div style="background-color: inherit;">...</div><div style="background-color: inherit;">}</div><div style="background-color: inherit;"><strong style="background-color: inherit;">如何工作</strong></div><div style="background-color: inherit;">在我们的例子中，我们选择实现一个消费者，这个消费者只在生产者是持久化的，且队列是由生产者创建的情况下才能工作。</div><div style="background-color: inherit;">因此，如果队列是非持久化的，Consumer.java文件会立即错误退出. 此行为可以通过调用<span style="line-height: 1.5; background-color: inherit;">channel.queueDeclarePassive()来完成 .</span></div><div style="background-color: inherit;">Producer.java类在其启动时会创建队列，并在其关闭时调用channel.queueDelete()方法删除队列，如果当队列关闭时，而消费者正在消费队列，那么RabbitMQ client会调用步骤1中覆盖的handleCancel()方法来立即通知消费者。</div><div style="background-color: inherit;">相对于显示调用channel.basicCancel() 消费者使用handleCancel()方法可以任意理由来退出。只有在这种情况下，<span style="line-height: 1.5; background-color: inherit;">RabbitMQ&nbsp;</span><span style="line-height: 1.5; background-color: inherit;">client&nbsp;library会调用Consumer接口的方法:&nbsp;&nbsp;handleCancelOK()&nbsp;</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;"><strong style="background-color: inherit;">更多</strong></div><div style="background-color: inherit;">消费者cancel通知是client&nbsp;library的扩展,而不是<span style="line-height: 1.5; background-color: inherit;">AMQP&nbsp;client&nbsp;libraries的常规方法.一个实例它们的library必须将其声明为可选属性</span><span style="line-height: 1.5; background-color: inherit;">(参考&nbsp;</span><a href="http://www.rabbitmq.com/consumer-cancel." style="cursor: pointer; line-height: 1.5; background-color: inherit;">http://www.rabbitmq.com/consumer-cancel.</a>&nbsp;<span style="line-height: 1.5; background-color: inherit;">html#capabilities&nbsp;).</span></div><div style="background-color: inherit;">RabbitMQ&nbsp;client&nbsp;library&nbsp;支持并声明了这种特性。</div><div style="background-color: inherit;">也可参考</div><div style="background-color: inherit;">在集群中，如果一个节点失效了，也会发生同样的事情<span style="line-height: 1.5; background-color: inherit;">:client在队列删除后仍然得不到通知，除非它定义了覆盖了自己的</span><span style="line-height: 1.5; background-color: inherit;">handleCancel()方法。关于这点的更多信息，可参考</span><span style="line-height: 1.5; background-color: inherit;">Chapter&nbsp;6,开发可伸缩性应用程序。</span></div><div style="background-color: inherit;"></div><div style="background-color: inherit;">理解交换器到交换器扩展</div><div style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">默认情况下，AMQP支持交换器到队列，但不支持交换器到交换器绑定。在本例中，我们将展示如何使用</span><span style="line-height: 1.5; background-color: inherit;">RabbitMQ 交换机到交换机扩展.</span></div><div style="background-color: inherit;">在本例中，我们将合并来自两个不同交换器的消息到第三个交换器中<span style="line-height: 1.5; background-color: inherit;">.你可以在Chapter02/Recipe08/Java/src/rmqexample找到源码.</span></div><div style="background-color: inherit;">准备</div><div style="background-color: inherit;">为了使用本食谱，我们需要设置Java开发环境，如第1章节(使用AMQP)介绍章节中说明的一样，并像广播消息食谱中来运行生产者以及使用topic交换器来处理消息路由。</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">如何做</div><div style="background-color: inherit;">完成下面的步骤来使用RabbitMQ 交换器到交换器扩展:</div><div style="background-color: inherit;">1. 使用下面的代码来声明我们需要追踪消息的交换器：</div><div style="background-color: inherit;">channel.exchangeDeclare(exchange,&nbsp;"topic",&nbsp;false);</div><div style="background-color: inherit;">2. 使用<span style="line-height: 1.5; background-color: inherit;">exchangeBind()来绑定其它例子中的交换器 :</span></div><div style="background-color: inherit;">channel.exchangeBind(exchange,ref_exchange_c1_8,"#");</div><div style="background-color: inherit;">channel.exchangeBind(exchange,ref_exchange_c1_6,"#");</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">3. 启动追踪消费者:</div><div style="background-color: inherit;">TraceConsumer&nbsp;consumer&nbsp;=&nbsp;new&nbsp;TraceConsumer(channel);</div><div style="background-color: inherit;">String&nbsp;consumerTag&nbsp;=&nbsp;channel.basicConsume(myqueue,&nbsp;false,<span style="line-height: 1.5; background-color: inherit;">consumer);</span></div><div style="background-color: inherit;">如何工作</div><div style="background-color: inherit;">在步骤1中，我们创建了一个新的交换器，在步骤2中我们绑定到了下面的交换器:</div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">ref_exchange_c1_6&nbsp;(广播消息)&nbsp;与exchange绑定.</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">ref_exchange_c1_8&nbsp;(使用topic来处理消息路由)与exchange绑定&nbsp;.</span></li></ol></div><div style="background-color: inherit;">在步骤3中, 消费者可以绑定一个队列到exchange上以任意地获取所有消息<span style="line-height: 1.5; background-color: inherit;">.</span></div><div style="background-color: inherit;">交换器到交换器扩展的工作方式与交换器到队列绑定过程类似，你也可以指定一个路由键来过滤消息.在步骤2中，我们可以使用#（匹配所有消息）来作为路由键。通过改变路由键你可以使用制作一个<span style="line-height: 1.5; background-color: inherit;">filter!</span></div><div style="background-color: inherit;"></div><div style="background-color: inherit;">在消息中内嵌消息目的地</div><div style="background-color: inherit;">在本例子中，我们会展示如何发送单个发布带路由键的的消息<span style="line-height: 1.5; background-color: inherit;">.标准AMQP不提供此特性，但幸运的是，RabbitMQ使用消息属性header提供了此特性</span><span style="line-height: 1.5; background-color: inherit;">. 这种扩展称为sender-selected分发.</span></div><div style="background-color: inherit;">此扩展的行为类似于电子邮件逻辑.它使用Carbon&nbsp;Copy&nbsp;(CC)和Blind&nbsp;<span style="line-height: 1.5; background-color: inherit;">Carbon&nbsp;Copy&nbsp;(BCC).这也是为什么能在&nbsp;Chapter02/Recipe09/Java/src/rmqexample中找到CC和BCC&nbsp;consumers的理由：</span></div><div style="background-color: inherit;"><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit;"><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">Producer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">Consumer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">StatsConsumer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">CCStatsConsumer.java</span></li><li style="background-color: inherit;"><span style="line-height: 1.5; background-color: inherit;">BCCStatsConsumer.java</span></li></ol></div><div style="background-color: inherit;">准备</div><div style="background-color: inherit;">To&nbsp;use&nbsp;this&nbsp;recipe,&nbsp;we&nbsp;need&nbsp;to&nbsp;set&nbsp;up&nbsp;the&nbsp;Java&nbsp;development&nbsp;environment&nbsp;as&nbsp;indicated&nbsp;in&nbsp;the&nbsp;<span style="line-height: 1.5; background-color: inherit;">Introduction&nbsp;section&nbsp;of&nbsp;Chapter&nbsp;1,&nbsp;Working&nbsp;with&nbsp;AMQP.</span></div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">如何做</div><div style="background-color: inherit;">完成下面的步骤来使用单个发布带路由键的的消息<span style="line-height: 1.5; background-color: inherit;">:</span></div><div style="background-color: inherit;">1.&nbsp;使用下面的代码来创建或声明交换器:</div><div style="background-color: inherit;">channel.exchangeDeclare(exchange,&nbsp;"direct",&nbsp;false);</div><div style="background-color: inherit;">2.&nbsp;在消息的header属性中指定CC&nbsp;, BCC路由键<span style="line-height: 1.5; background-color: inherit;">:</span></div><div style="background-color: inherit;">List&lt;String&gt;&nbsp;ccList&nbsp;=&nbsp;new&nbsp;ArrayList&lt;String&gt;();</div><div style="background-color: inherit;">ccList.add(backup_alert_routing_key);</div><div style="background-color: inherit;">headerMap.put("CC",&nbsp;ccList);</div><div style="background-color: inherit;">List&lt;String&gt;&nbsp;ccList&nbsp;=&nbsp;new&nbsp;ArrayList&lt;String&gt;();</div><div style="background-color: inherit;">bccList.add(send_alert_routing_key);</div><div style="background-color: inherit;">headerMap.put("BCC",&nbsp;bccList);</div><div style="background-color: inherit;">BasicProperties&nbsp;messageProperties&nbsp;=&nbsp;new&nbsp;BasicProperties.Builder().<span style="line-height: 1.5; background-color: inherit;">headers(headerMap).</span><span style="line-height: 1.5; background-color: inherit;">build();</span></div><div style="background-color: inherit;">channel.basicPublish(exchange,&nbsp;alert_routing_key,<span style="line-height: 1.5; background-color: inherit;">messageProperties,&nbsp;statMsg.getBytes());</span></div><div style="background-color: inherit;">3.&nbsp;使用下面的三个路由键来绑定三个队列three&nbsp;queues&nbsp;to&nbsp;the&nbsp;exchange&nbsp;using&nbsp;the&nbsp;following&nbsp;three&nbsp;routing&nbsp;keys:</div><div style="background-color: inherit;">channel.queueBind(myqueue,exchange,&nbsp;alert_routing_key);</div><div style="background-color: inherit;">channel.queueBind(myqueueCC_BK,exchange,<span style="line-height: 1.5; background-color: inherit;">backup_alert_routing_key);</span></div><div style="background-color: inherit;">channel.queueBind(myqueueBCC_SA,exchange,<span style="line-height: 1.5; background-color: inherit;">send_alert_routing_key);</span></div><div style="background-color: inherit;">4. 使用三个消费者来消费消息</div><div style="background-color: inherit;">如何工作</div><div style="background-color: inherit;">当生产者使用CC和BCC消息属性来发送消息时，broker会在所有路由键的队列上拷贝消息 。在本例中，stat类会直接使用路由键alert_routing_key来向交换器发送消息，同时它也会将消息拷贝到使用CC和BCC参数信息来将消息拷贝到<span style="line-height: 1.5; background-color: inherit;">myqueueCC_BK，myqueueBCC_SA队列中。</span></div><div style="background-color: inherit;">当像e-mails一样发生时,在分发消息到队列前，BCC信息会被broker从消息头中删除，你可查看所有我们示例消费者的输出来观察这种行为。</div></div><div style="font-family: 微软雅黑; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; background-color: #ffffff;"><div style="background-color: inherit;">更多</div><div style="background-color: inherit;">正常情况下，AMQP不会改变消息头，但BCC扩展是例外。这种扩展可减少发往broker的消息数目。没有此扩展，生产者只能使用不同的路由键来发送多个消息的拷贝。</div><div></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/430783.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-05 19:51 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/05/430783.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>官网指南-RabbitMQ-Java Client API Guide</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/04/430771.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Fri, 03 Jun 2016 16:37:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/04/430771.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430771.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/04/430771.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430771.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430771.html</trackback:ping><description><![CDATA[<h1><span style="line-height: 1.5; font-size: 14px;">概述</span></h1><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">RabbitMQ Java client 将<span style="background-color: inherit; color: #333333;">com.rabbitmq.client作为其顶层包</span>. 关键类和接口有:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; font-size: 14px;"><li style="background-color: inherit;">Channel</li><li style="background-color: inherit;">Connection</li><li style="background-color: inherit;">ConnectionFactory</li><li style="background-color: inherit;">Consumer</li></ul>协议操作可通过<span style="background-color: inherit; color: #333333;">Channel接口来进行.Connection用于开启c</span>hannels,注册connection生命周期事件处理, 并在不需要时关闭connections.<br /><span style="background-color: inherit; color: #333333;">Connections是通过</span><span style="background-color: inherit; color: #333333;">ConnectionFactory来初始化的，在ConnectionFactory中，你可以配置不同的connection设置，如：虚拟主机和用户名等等</span>.</div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>Connections 和 Channels</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">核心API类是<span style="background-color: inherit; color: #333333;">Connection和</span><span style="background-color: inherit; color: #333333;">Channel</span>, 它们代表对应AMQP 0-9-1 connection 和 channel. 在使用前，可像下面这样来导入：</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.Connection; <br /><span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.Channel;</pre><h2>连接到broker</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">下面的代码会使用给定的参数连接到AMQP broker:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory(); <br />factory.setUsername(<span style="background-color: inherit; color: #008b8b;">userName</span>); <br />factory.setPassword(<span style="background-color: inherit; color: #008b8b;">password</span>); <br />factory.setVirtualHost(<span style="background-color: inherit; color: #008b8b;">virtualHost</span>); <br />factory.setHost(<span style="background-color: inherit; color: #008b8b;">hostName</span>); <br />factory.setPort(<span style="background-color: inherit; color: #008b8b;">portNumber</span>); <br />Connection conn = factory.newConnection(); </pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; font-size: 14px;"><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">也可以使用</span><a href="http://www.rabbitmq.com/uri-spec.html" style="cursor: pointer; font-family: 'Microsoft Yahei'; line-height: 1.5; color: #444444; font-weight: bold;">URIs</a><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">&nbsp;来设置连接参数:</span></span></p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory(); <br />factory.setUri("<span style="background-color: inherit; color: #008b8b;">amqp://userName:password@hostName:portNumber/virtualHost</span>"); <br />Connection conn = factory.newConnection(); </pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; font-size: 14px;"><br style="background-color: inherit;" /></span></p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; color: #333333;">Connection</span>&nbsp;接口可用来打开一个channel:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">Channel channel = conn.createChannel(); </pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">channel现在可用来发送和接收消息，正如后续章节中描述的一样.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要断开连接，只需要简单地关闭channel和connection:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.close(); conn.close();</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">关闭channel被认为是最佳实践,但在这里不是严格必须的 - 当底层连接关闭的时候，channel也会自动关闭.</p></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; background-color: #ffffff;"><h2>使用 Exchanges 和 Queues</h2><h2><span style="color: #555555; font-family: 'Microsoft Yahei'; line-height: 1.5; font-size: 14px;">采用交换器和队列工作的客户端应用程序,是AMQP高级别构建模块。在使用前，必须先声明.声明每种类型的对象都需要确保名称存在，如果有必要须进行创建.</span></h2><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">继续上面的例子,下面的代码声明了一个交换器和一个队列，然后再将它们进行绑定.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.exchangeDeclare(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">"direct"</span>, <span style="background-color: inherit; color: #008b8b;">true</span>); <br />String <span style="background-color: inherit; color: #008b8b;">queueName</span> = channel.queueDeclare().getQueue(); <br />channel.queueBind(<span style="background-color: inherit; color: #008b8b;">queueName</span>, <span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>);</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">这实际上会声明下面的对象，它们两者都可以可选参数来定制. 在这里，它们两个都没有特定参数。</p><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; color: #555555; font-size: 14px;"><li style="background-color: inherit;">一个类型为direct，且持久化，非自动删除的交换器</li><li style="background-color: inherit;">采用随机生成名称，且非持久化，私有的，自动删除队列</li></ol><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">上面的函数然后使用给定的路由键来绑定队列和交换器.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">注意，当只有一个客户端时，这是一种典型声明队列的方式:它不需要一个已知的名称，其它的客户端也不会使用它(exclusive),并会被自动清除(autodelete).<br />如果多个客户端想共享带有名称的队列，下面的代码应该更适合:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.exchangeDeclare(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">"direct"</span>, <span style="background-color: inherit; color: #008b8b;">true</span>); <br />channel.queueDeclare(<span style="background-color: inherit; color: #008b8b;">queueName</span>, <span style="background-color: inherit; color: #008b8b;">true</span>, <span style="background-color: inherit; color: #008b8b;">false</span>, <span style="background-color: inherit; color: #008b8b;">false</span>, <span style="background-color: inherit; color: #008b8b;">null</span>); <br />channel.queueBind(<span style="background-color: inherit; color: #008b8b;">queueName</span>, <span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>);</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">这实际上会声明:</p><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; color: #555555; font-size: 14px;"><li style="background-color: inherit;">一个类型为direct，且持久化，非自动删除的交换器</li><li style="background-color: inherit;">一个已知名称，且持久化的，非私有，非自动删除队列</li></ol><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">注意，<span style="background-color: inherit; color: #333333;">Channel</span>&nbsp;API 的方法都是重载的。这些&nbsp;<span style="background-color: inherit; color: #333333;">exchangeDeclare</span>,&nbsp;<span style="background-color: inherit; color: #333333;">queueDeclare</span>&nbsp;和<span style="background-color: inherit; color: #333333;">queueBind</span>&nbsp;都使用的是预设行为.<br />这里也有更多参数的长形式，它们允许你按需覆盖默认行为，允许你完全控制。</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;"><span style="background-color: inherit; font-size: 14px;"><br style="background-color: inherit;" /></span></p></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>发由消息</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要向交换器中发布消息,可按下面这样来使用<span style="background-color: inherit; color: #333333;">Channel.basicPublish方法</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">byte</span>[] messageBodyBytes = <span style="background-color: inherit; color: #008b8b;">"Hello, world!"</span>.getBytes(); <br />channel.basicPublish(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>, <span style="background-color: inherit; color: #008b8b;">null</span>, messageBodyBytes);</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">为了更好的控制，你可以使用重载方法来指定<span style="background-color: inherit; color: #333333;">mandatory标志，或使用预先设置的消息属性来发送消息</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.basicPublish(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>, <span style="background-color: inherit; color: #008b8b;">mandatory</span>, MessageProperties.PERSISTENT_TEXT_PLAIN,messageBodyBytes);</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">这会使用分发模式2(持久化)来发送消息, 优先级为1，且content-type 为"text/plain".你可以使用Builder类来构建你自己的消息属性对象：</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.basicPublish(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>,<span style="background-color: inherit; color: #008b8b;">new</span> AMQP.BasicProperties.Builder().contentType("text/plain").deliveryMode(2).priority(1).userId("bob").build()),messageBodyBytes);</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">下面的例子使用自定义的headers来发布消息:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">Map&lt;String, Object&gt; headers = new HashMap&lt;String, Object&gt;(); <br />headers.put("latitude",  51.5252949); <br />headers.put("longitude", -0.0905493);  <br />channel.basicPublish(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>,<span style="background-color: inherit; color: #008b8b;">new</span> AMQP.BasicProperties.Builder().headers(headers).build()),messageBodyBytes);</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">下面的例子使用expiration来发布消息:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.basicPublish(<span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>,<span style="background-color: inherit; color: #008b8b;">new</span> AMQP.BasicProperties.Builder().expiration("60000").build()),messageBodyBytes);</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; font-size: 14px;"><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; color: #333333;">BasicProperties</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">&nbsp;is an inner class of the autogenerated holder class&nbsp;</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5; color: #333333;">AMQP</span><span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">.</span></span></p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">Invocations of&nbsp;<span style="background-color: inherit; color: #333333;">Channel#basicPublish</span>&nbsp;will eventually block if a&nbsp;<a href="http://www.rabbitmq.com/alarms.html" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">resource-driven alarm</a>&nbsp;is in effect.</p></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>Channels 和并发考虑(线程安全性)</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; color: #333333;">Channel</span>&nbsp;实例不能在多个线程间共享。应用程序必须在每个线程中使用不同的channel实例,而不能将同个channel实例在多个线程间共享。 有些channl上的操作是线程安全的，有些则不是，这会导致传输时出现错误的帧交叉。<br />在多个线程共享channels也会干扰<a href="http://www.rabbitmq.com/confirms.html" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">Publisher Confirms</a>.</p></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; background-color: #ffffff;"><h2>通过订阅来来接收消息</h2><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.Consumer; <span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.DefaultConsumer;</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">接收消息最高效的方式是用<span style="color: #333333;">Consumer接口来订阅。当消息到达时，它们会自动地进行分发，而不需要显示地请求</span>。</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">当在调用<span style="background-color: inherit; color: #333333;">Consumer</span>s的相关方法时, 个别订阅总是通过它们的consumer tags来确定的,&nbsp;consumer tags可通过客户端或服务端来生成，参考&nbsp;<a href="http://www.amqp.org/" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">the AMQP specification document</a>. <br />同一个channel上的消费者必须有不同的consumer tags.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">实现<span style="background-color: inherit; color: #333333;">Consumer的最简单方式是继承便利类</span><span style="background-color: inherit; color: #333333;">DefaultConsumer</span>.子类可通过在设置订阅时，将其传递给<span style="background-color: inherit; color: #333333;">basicConsume调用</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">boolean</span> autoAck = <span style="background-color: inherit; color: #008b8b;">false</span>; <br />channel.basicConsume(queueName, autoAck, "myConsumerTag",<span style="background-color: inherit; color: #008b8b;">new</span> DefaultConsumer(channel) {          <br />@Override          <br /><span style="background-color: inherit; color: #008b8b;">public</span><span style="background-color: inherit; color: #008b8b;">void</span> handleDelivery(String consumerTag,Envelope envelope,AMQP.BasicProperties properties,<span style="background-color: inherit; color: #008b8b;">byte</span>[] body)<span style="background-color: inherit; color: #008b8b;">throws</span> IOException{              <br />String routingKey = envelope.getRoutingKey();              <br />String contentType = properties.getContentType();              <br /><span style="background-color: inherit; color: #008b8b;">long</span> deliveryTag = envelope.getDeliveryTag();              <br /><em style="background-color: inherit; color: #8b0000;">// (process the message components here ...)</em>              <br />channel.basicAck(deliveryTag, <span style="background-color: inherit; color: #008b8b;">false</span>);          <br />}      <br />});</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">在这里，由于我们指定了<span style="background-color: inherit; color: #333333;">autoAck =&nbsp;</span><span style="background-color: inherit; color: black;"><span style="background-color: inherit; color: #333333;">false</span></span>,因此消费者有必要应答分发的消息，最便利的方式是在<span style="background-color: inherit; color: #333333;">handleDelivery</span>&nbsp;方法中处理.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">更复杂的消费者可能需要覆盖更多的方法，实践中，<span style="background-color: inherit; color: #333333;">handleShutdownSignal会在</span>channels和connections关闭时调用，<span style="background-color: inherit; color: #333333;">handleConsumeOk</span>&nbsp;会在其它消费者之前</p><div style="display: inline-block;">调用</div>，传递consumer tag(不明白，要研究)。<p>&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">消费者可实现<span style="background-color: inherit; color: #333333;">handleCancelOk</span>&nbsp;和&nbsp;<span style="background-color: inherit; color: #333333;">handleCancel方法来接收显示和隐式取消操作通知。</span></p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">你可以使用<span style="color: #333333;">Channel.basicCancel来显示地取消某个特定的消费者</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.basicCancel(consumerTag);</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">passing the consumer tag.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">消费者回调是在单独线程上处理的，这意味着消费者可以安全地在Connection或Channel, 如queueDeclare,&nbsp;txCommit,&nbsp;basicCancel或basicPublish上调用阻塞方法。</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">每个Channel都有其自己的dispatch线程.对于一个消费者一个channel的大部分情况来说，这意味着消费者不会阻挡其它的消费者。如果在一个channel上多个消费者，则必须意识到长时间运行的消费者可能阻挡此channel上其它消费者回调调度.</p></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>获取单个消息</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要显示地获取一个消息，可使用<span style="background-color: inherit; color: #333333;">Channel.basicGet</span>.返回值是一个G<span style="background-color: inherit; color: #333333;">etResponse实例</span>, 在它之中，header信息(属性) 和消息body都可以提取:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">boolean</span> autoAck = <span style="background-color: inherit; color: #008b8b;">false</span>; <br />GetResponse response = channel.basicGet(<span style="background-color: inherit; color: #008b8b;">queueName</span>, autoAck); <br /><span style="background-color: inherit; color: #008b8b;">if</span> (response == <span style="background-color: inherit; color: #008b8b;">null</span>) {     <br /><em style="background-color: inherit; color: #8b0000;">// No message retrieved. <br /></em>} <span style="background-color: inherit; color: #008b8b;">else</span> {     <br />AMQP.BasicProperties props = response.getProps();     <br /><span style="background-color: inherit; color: #008b8b;">byte</span>[] body = response.getBody();     <br />long deliveryTag = response.getEnvelope().getDeliveryTag();     ...</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">因为<span style="background-color: inherit; color: #333333;">autoAck</span>&nbsp;=&nbsp;<span style="background-color: inherit; color: #333333;">false</span>,你必须调用<span style="background-color: inherit; color: #333333;">Channel.basicAck来应答你已经成功地接收了消息</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.basicAck(method.deliveryTag, <span style="background-color: inherit; color: #008b8b;">false</span>); <em style="background-color: inherit; color: #8b0000;">// acknowledge receipt of the message</em> }</pre></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>处理未路由消息</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">如果发布消息时，设置了"mandatory"标志,但如果消息不能路由的话，broker会将其返回到发送客户端 (通过&nbsp;<span style="background-color: inherit; color: #333333;">AMQP.Basic.Return</span>&nbsp;命令).</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">要收到这种返回的通知， clients可实现<span style="background-color: inherit; color: #333333;">ReturnListener接口，并调用</span><span style="background-color: inherit; color: #333333;">Channel.setReturnListener</span>.如果channel没有配置return listener,那么返回的消息会默默地丢弃。</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">channel.setReturnListener(<span style="background-color: inherit; color: #008b8b;">new</span> ReturnListener() {     <br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color: inherit; color: #008b8b;">public</span><span style="background-color: inherit; color: #008b8b;">void</span> handleBasicReturn(int replyCode,String replyText,String exchange,String routingKey,AMQP.BasicProperties properties,byte[] body)     <span style="background-color: inherit; color: #008b8b;">throws</span> IOException {<br />         ...     <br />&nbsp;&nbsp;&nbsp;&nbsp;} <br />});</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">&nbsp;return listener将被调用,例如,如果client使用"mandatory"标志向未绑定队列的direct类型交换器发送了消息.</p></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; background-color: #ffffff;"><h2>关闭协议</h2><div style="background-color: inherit;"><h3>AMQP client 关闭概述</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">AMQP 0-9-1 connection和channel 使用相同的方法来管理网络故障,内部故障,以及显示本地关闭.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">AMQP 0-9-1 connection &nbsp;和 channel 有如下的生命周期状态:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; font-size: 14px;"><li style="background-color: inherit;">open: 准备要使用的对象</li><li style="background-color: inherit;">closing: 对象已显示收到收到本地关闭通知, 并向任何支持的底层对象发出关闭请求,并等待其关闭程序完成</li><li style="background-color: inherit;">closed: 对象已收到所有底层对象的完成关闭通知,最终将执行关闭操作</li></ul><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">这些对象总是以closed状态结束的,不管基于什么原因引发的关闭,比如:应用程序请求,内部client library故障, 远程网络请求或网络故障.</p><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">AMQP connection 和channel 对象会持有下面与关闭相关的方法:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; color: #555555; font-size: 14px;"><li style="background-color: inherit;"><span style="background-color: inherit; color: #333333;">addShutdownListener(ShutdownListener 监听器)和</span><span style="background-color: inherit; color: #333333;">removeShutdownListener(ShutdownListener 监听器)</span>,用来管理监听器,当对象转为<span style="background-color: inherit; color: #333333;">closed状态时,将会触发这些监听器</span>.注意,在已经关闭的对象上添加一个ShutdownListener将会立即触发监听器</li><li style="background-color: inherit;"><span style="background-color: inherit; color: #333333;">getCloseReason()</span>, 允许同其交互以了解对象关闭的理由</li><li style="background-color: inherit;"><span style="background-color: inherit; color: #333333;">isOpen()</span>, 用于测试对象是否处于open状态</li><li style="background-color: inherit;"><span style="background-color: inherit; color: #333333;">close(int closeCode, String closeMessage)</span>, 用于显示通知对象关闭</li></ul><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">可以像这样来简单使用监听器:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.ShutdownSignalException; <br /><span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.ShutdownListener;  <br />connection.addShutdownListener(<span style="background-color: inherit; color: #008b8b;">new</span> ShutdownListener() {     <br /><span style="background-color: inherit; color: #008b8b;">public void</span> shutdownCompleted(ShutdownSignalException cause)     {         ...     } }<br />);</pre></div><div style="background-color: inherit;"><h3>关闭环境信息</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">可通过显示调用<span style="color: #333333;">getCloseReason()方法或通过使用ShutdownListener类中的业务方法的cause参数来</span>从<span style="background-color: inherit; color: #333333;">ShutdownSignalException中获取关闭原因的有用信息</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">ShutdownSignalException&nbsp;类提供方法来分析关闭的原因.通过调用isHardError()方法,我们可以知道是connection错误还是channel错误.<span style="background-color: inherit; color: #333333;">getReason()会返回相关cause的相关信息,这些引起cause的方法形式</span>-要么是<span style="background-color: inherit; color: #333333;">AMQP.Channel.Close方法,要么是</span><span style="background-color: inherit; color: #333333;">AMQP.Connection.Close</span>&nbsp;(或者是null,如果是library中引发的异常,如网络通信故障,在这种情况下,可通过<span style="background-color: inherit; color: #333333;">getCause()方法来获取信息</span>).</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; widows: auto;"><span style="background-color: inherit; color: #008b8b;">public void</span> shutdownCompleted(ShutdownSignalException cause) {   <span style="background-color: inherit; color: #008b8b;">if</span> (cause.isHardError())   {     <br />Connection conn = (Connection)cause.getReference();     <br /><span style="background-color: inherit; color: #008b8b;">if</span> (!cause.isInitiatedByApplication())     {       <br />Method reason = cause.getReason();       ...     }     ...   } <br /><span style="background-color: inherit; color: #008b8b;">else</span> {     Channel ch = (Channel)cause.getReference();     ...   } }</pre></pre></div><div style="background-color: inherit;"><h3>原子使用isOpen()方法</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">channel和connection对象的<span style="background-color: inherit; color: #333333;">isOpen()方法不建议在在生产代码中使用,因为此方法的返回值依赖于<span style="color: #555555;">shutdown&nbsp;</span></span>cause的存在性. 下面的代码演示了竟争条件的可能性:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">public void</span> brokenMethod(Channel channel) {     <span style="background-color: inherit; color: #008b8b;">if</span> (channel.isOpen())     {         // The following code depends on the channel being in open state.         // However there is a possibility of the change in the channel state         // between isOpen() and basicQos(1) call         ...         channel.basicQos(1);     } }</pre><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">相反,我们应该忽略这种检查,并简单地尝试这种操作.如果代码执行期间,connection的channel关闭了,那么将抛出<span style="background-color: inherit; color: #333333;">ShutdownSignalException,这就表明对象处于一种无效状态了.当<span style="color: #555555;">broker意外关闭连接时,</span>我们也应该捕获由</span><span style="background-color: inherit; color: #333333;">SocketException引发的IOException,或者当</span>broker清理关闭时,捕获<span style="background-color: inherit; color: #333333;">ShutdownSignalException</span>.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">public void</span> validMethod(Channel channel) {     <span style="background-color: inherit; color: #008b8b;">try</span> {         ...         channel.basicQos(1);     } <span style="background-color: inherit; color: #008b8b;">catch</span> (ShutdownSignalException sse) {         // possibly check if channel was closed         // by the time we started action and reasons for         // closing it         ...     } <span style="background-color: inherit; color: #008b8b;">catch</span> (IOException ioe) {         // check why connection was closed         ...     } }</pre></div></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; background-color: #ffffff;"><h2>高级连接选项</h2><div style="background-color: inherit; color: #555555;"><h3>Consumer线程池</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; color: #333333;">Consumer</span>&nbsp;线程默认是通过一个新的<span style="color: #333333;">ExecutorService线程池来自动分配的</span>(参考下面的<a href="http://www.rabbitmq.com/api-guide.html#consuming" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">Receiving</a>).如果需要在<span style="color: #333333;">newConnection()</span>&nbsp;方法中更好地控制<span style="color: #333333;">ExecutorService,可以使用定制的线程池.下面的示例展示了一个比正常分配稍大的线程池</span>:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ExecutorService <span style="background-color: inherit; color: #008b8b;">es</span> = Executors.newFixedThreadPool(20); Connection conn = factory.newConnection(<span style="background-color: inherit; color: #008b8b;">es</span>); </pre><span style="background-color: inherit; color: #333333;">Executors</span>&nbsp;和&nbsp;<span style="background-color: inherit; color: #333333;">ExecutorService</span>&nbsp;都是<span style="background-color: inherit; color: #333333;">java.util.concurrent包中的类</span>.<p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当连接关闭时,默认的<span style="background-color: inherit; color: #333333;">ExecutorService将会被</span><span style="background-color: inherit; color: #333333;">shutdown()</span>, 但用户自定义的E<span style="background-color: inherit; color: #333333;">xecutorService</span>&nbsp;(如上面所示)将不会被s<span style="background-color: inherit; color: #333333;">hutdown()</span>. 提供自定义<span style="color: #333333;">ExecutorService</span>的Clients必须确保最终它能被关闭(通过调用它的<span style="background-color: inherit; color: #333333;">shutdown()</span>&nbsp;方法), 否则池中的线程可能会阻止JVM终止.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">同一个executor service,可在多个连接之间共享,或者连续地在重新连接上重用,但在shutdown()后,则不能再使用.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; font-size: 14px;">使用这种特性时,唯一需要考虑的是:在消费者回调的处理过程中,是否有证据证明有严重的瓶颈.&nbsp;<span style="color: #666666; text-align: justify; background-color: rgba(255, 255, 255, 0.8);">如果没有消费者执行回调,或很少,默认的配置是绰绰有余.</span>&nbsp;开销最初是很小的,分配的全部线程资源也是有界限的,<strong style="background-color: inherit;"><span style="color: #666666; font-weight: normal; text-align: justify; background-color: rgba(255, 255, 255, 0.8);">即使偶尔可能出现一阵消费活动</span></strong>.</span></p></div><div style="background-color: inherit;"><h3>使用Host列表</h3><p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">可以传递一个<span style="background-color: inherit; color: #333333;">Address数组给</span><span style="background-color: inherit; color: #333333;">newConnection()</span>.&nbsp;<span style="background-color: inherit; color: #333333;">Address只是&nbsp;com.rabbitmq.client 包中包含host和port组件的简单便利类</span>. 例如:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">Address[] addrArr = <span style="background-color: inherit; color: #008b8b;">new</span> Address[]{ <span style="background-color: inherit; color: #008b8b;">new</span> Address(hostname1, portnumber1)                                  , <span style="background-color: inherit; color: #008b8b;">new</span> Address(hostname2, portnumber2)}; Connection conn = factory.newConnection(addrArr); </pre>将会尝试连接<span style="background-color: inherit; color: #333333;">hostname1:portnumber1</span>, 如果不能连接,则会连接hostname2:portnumber2,然后会返回数组中第一个成功连接<span style="color: #555555;">(不会抛出</span><span style="color: #333333;">IOException</span><span style="color: #555555;">)</span>上broker的连接.这完全等价于在factory上重复调用<span style="color: #333333;">factory.newConnection()</span>方法来设置host和port, 直到有一个成功返回.<p style="margin-right: 0px; margin-left: 0px; color: #555555; background-color: inherit;">如果提供了<span style="background-color: inherit; color: #333333;">ExecutorService</span>(在<span style="background-color: inherit; color: #333333;">factory.newConnection(es, addrArr)中使用</span>),那么线程池将与第一个成功连接相关联.</p></div><div style="background-color: inherit; color: #555555;"><h3><span style="background-color: inherit; line-height: 21px; font-size: 14px;">心跳超时</span></h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">参考<a href="http://www.rabbitmq.com/heartbeats.html" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">Heartbeats guide</a>&nbsp;来了解更多关于心跳及其在Java client中如何配置的更多信息.</p></div><div style="background-color: inherit; color: #555555;"><h3>自定义线程工厂</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">像Google App Engine (GAE)这样的环境会<a href="https://developers.google.com/appengine/docs/java/#Java_The_sandbox" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">限制线程直接实例化</a>. 在这样的环境中使用RabbitMQ Java client, 需要配置一个定制的<span style="background-color: inherit; color: #333333;">ThreadFactory,即使用合适的方法来实例化线程,如:</span>&nbsp;GAE's&nbsp;<span style="background-color: inherit; color: #333333;">ThreadManager</span>. 下面是Google App Engine的相关代码.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">import com.google.appengine.api.ThreadManager;  ConnectionFactory cf = new ConnectionFactory(); cf.setThreadFactory(ThreadManager.backgroundThreadFactory()); </pre></div></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>网络故障时自动恢复</h2><div style="background-color: inherit;"><h3><span style="background-color: inherit; font-size: 14px;">Connection<span style="background-color: inherit; font-family: 'Microsoft Yahei'; line-height: 1.5;">恢复</span></span></h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">clients和RabbitMQ节点之间的连接可发生故障. RabbitMQ Java client 支持连接和拓扑(queues, exchanges, bindings, 和consumers)的自动恢复. 大多数应用程序的连接自动恢复过程会遵循下面的步骤:</p><ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; font-size: 14px;"><li style="background-color: inherit;">重新连接</li><li style="background-color: inherit;">恢复连接监听器</li><li style="background-color: inherit;">重新打开通道</li><li style="background-color: inherit;">恢复通道监听器</li><li style="background-color: inherit;">恢复通道<span style="background-color: inherit; color: #333333;">basic.qos</span>&nbsp;设置,发布者确认和事务设置</li></ol>拓扑恢复包含下面的操作,每个通道都会执行下面的步骤:<ol data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; font-size: 14px;"><li style="background-color: inherit;">重新声明交换器(except for predefined ones)</li><li style="background-color: inherit;">重新声明队列</li><li style="background-color: inherit;">恢复所有绑定</li><li style="background-color: inherit;">恢复所有消费者</li></ol>要启用自动连接恢复,须使用<span style="background-color: inherit; color: #333333;">factory.setAutomaticRecoveryEnabled(true)</span>:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory(); factory.setUsername(<span style="background-color: inherit; color: #008b8b;">userName</span>); factory.setPassword(<span style="background-color: inherit; color: #008b8b;">password</span>); factory.setVirtualHost(<span style="background-color: inherit; color: #008b8b;">virtualHost</span>); factory.setHost(<span style="background-color: inherit; color: #008b8b;">hostName</span>); factory.setPort(<span style="background-color: inherit; color: #008b8b;">portNumber</span>); factory.setAutomaticRecoveryEnabled(true); // connection that will recover automatically Connection conn = factory.newConnection();</pre>如果恢复因异常失败(如. RabbitMQ节点仍然不可达),它会在固定时间间隔后进行重试(默认是5秒). 时间间隔可以进行配置:<pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory(); // attempt recovery every 10 seconds factory.setNetworkRecoveryInterval(10000);</pre><span style="background-color: inherit; font-size: 14px;">当提供了address列表时,将会在所有address上逐个<span style="font-family: 'Microsoft Yahei'; line-height: 1.5;">进行尝试:</span></span></div><div style="background-color: inherit;"><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory();  Address[] addresses = {new Address("192.168.1.4"), new Address("192.168.1.5")}; factory.newConnection(addresses);</pre></div><div style="background-color: inherit;"><h3>恢复监听器</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">可在可恢复连接和通道上注册一个或多个恢复监听器. 当启用了连接恢复时,<span style="background-color: inherit; color: #333333;">ConnectionFactory#newConnection</span>&nbsp;和&nbsp;<span style="background-color: inherit; color: #333333;">Connection#createChannel</span>&nbsp;的连接已实现了<span style="background-color: inherit; color: #333333;">com.rabbitmq.client.Recoverable</span>,并提供了两个方法:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; background-color: inherit; font-size: 14px;"><li style="background-color: inherit;">addRecoveryListener</li><li style="background-color: inherit;">removeRecoveryListener</li></ul>注意,在使用这些方法时,你需要将connections和channels强制转换为<span style="background-color: inherit; color: #333333;">Recoverable</span>.</div><div style="background-color: inherit;"><h3>发布影响</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当连接失败时,使用<span style="background-color: inherit; color: #333333;">Channel.basicPublish方法发送的消息将会丢失</span>. client不会保证在连接恢复后,消息会得到分发.要确保发布的消息到达了RabbitMQ,应用程序必须使用<a href="http://www.rabbitmq.com/confirms.html" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">Publisher Confirms</a>&nbsp;</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="font-family: 'Microsoft Yahei'; color: #ff6600; line-height: 1.5; font-size: 14px;"><br style="background-color: inherit;" /></span></p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="font-family: 'Microsoft Yahei'; color: #ff6600; line-height: 1.5; font-size: 14px;">拓扑恢复</span></p></div><div style="background-color: inherit;"><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">拓扑恢复涉及交换器,队列,绑定以及消费者恢复.默认是启用的,但也可以禁用:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory();  Connection conn = factory.newConnection(); factory.setAutomaticRecoveryEnabled(true); factory.setTopologyRecoveryEnabled(false);</pre></div><div style="background-color: inherit;"><h3>手动应答和自动恢复</h3><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">当使用手动应答时,在消息分发与应答之间可能存在网络连接中断. 在连接恢复后,RabbitMQ会在所有通道上重设delivery标记. 也就是说,使用旧delivery标记的<em style="background-color: inherit;">basic.ack</em>,&nbsp;<em style="background-color: inherit;">basic.nack</em>, 以及<em style="background-color: inherit;">basic.reject将会引发</em>channel exception. 为了避免发生这种情况, RabbitMQ Java client可以跟踪,更新,以使它们在恢复期间单调地增长.&nbsp;<span style="background-color: inherit; color: #333333;">Channel.basicAck</span>,&nbsp;<span style="background-color: inherit; color: #333333;">Channel.basicNack</span>, 以及<span style="background-color: inherit; color: #333333;">Channel.basicReject</span>&nbsp;然后可以转换这些 delivery tags,并且不再发送过期的<span style="background-color: inherit; color: black;">delivery tags</span>. 使用手动应答和自动恢复的应用程序必须负责处理重新分发.</p></div></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>未处理异常</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">关于connection, channel, recovery, 和consumer lifecycle 的异常将会委派给exception handler,Exception handler是实现了<span style="background-color: inherit; color: #333333;">ExceptionHandler接口的任何对象</span>. 默认情况下,将会使用<span style="background-color: inherit; color: #333333;">DefaultExceptionHandler实例,它会将异常细节输出到标准输出上</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">可使用<span style="background-color: inherit; color: #333333;">ConnectionFactory#setExceptionHandler来覆盖原始handler,它将被用于由此</span>factory创建的所有连接:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory(); cf.setExceptionHandler(customHandler);         </pre>Exception handlers 应该用于异常日志.</div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2><span style="background-color: inherit; font-size: 14px;">Google App Engine上的<span style="background-color: inherit; font-family: 'Microsoft Yahei'; line-height: 1.5;">RabbitMQ Java Client</span></span></h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">在Google App Engine (GAE) 上使用RabbitMQ Java client,必须使用一个自定义的线程工厂来初始化线程,如使用GAE's&nbsp;<span style="background-color: inherit; color: #333333;">ThreadManager</span>. 此外,还需要设置一个较小的心跳间隔(4-5 seconds) 来避免<span style="background-color: inherit; color: #333333;">InputStream</span>&nbsp;上读超时:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;">ConnectionFactory factory = <span style="background-color: inherit; color: #008b8b;">new</span> ConnectionFactory(); cf.setRequestedHeartbeat(5);         </pre></div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; background-color: #ffffff;"><h2><span style="font-weight: normal; text-align: justify; font-size: 14px; background-color: inherit;">警告和限制</span></h2><p style="margin-right: 0px; margin-left: 0px; color: #555555;">为了能使拓扑恢复, RabbitMQ Java client 维持了声明队列,交换器,绑定的缓存. 缓存是基于每个连接的.某些RabbitMQ的特性使得客户端不能观察到拓扑的变化,如,当队列因TTL被删除时. RabbitMQ Java client 会尝试在下面的情况中使用缓存实体失效:</p><ul data-front-font-size="14px" style="margin-top: 0px; margin-bottom: 0px; color: #555555; font-size: 14px;"><li style="background-color: inherit;">当队列被删除时.</li><li style="background-color: inherit;">当交换器被删除时.</li><li style="background-color: inherit;">当绑定被删除时.</li><li style="background-color: inherit;">当消费者在自动删除队列上退出时.</li><li style="background-color: inherit;">当队列或交换器不再绑定到自动删除的交换器上时.</li></ul>然而, 除了单个连接外,client不能跟踪这些拓扑变化. 依赖于自动删除队列或交换器的应用程序,正如TTL队列一样 (注意:不是消息TTL!), 如果使用了自动连接恢复,在知道不再使用或要删除时,必须明确地删除这些缓存实体,以净化 client-side 拓扑cache. 这些可通过<span style="background-color: inherit; color: #333333;">Channel#queueDelete</span>,&nbsp;<span style="background-color: inherit; color: #333333;">Channel#exchangeDelete</span>,<span style="background-color: inherit; color: #333333;">Channel#queueUnbind</span>, and&nbsp;<span style="background-color: inherit; color: #333333;">Channel#exchangeUnbind</span>来进行.</div><div style="font-family: 微软雅黑; font-size: 16px; line-height: 24px; widows: auto; color: #555555; background-color: #ffffff;"><h2>RPC (Request/Reply) 模式</h2><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">为了便于编程, Java client API提供了一个使用临时回复队列的<span style="background-color: inherit; color: #333333;">RpcClient类来提供简单的</span><a href="http://www.rabbitmq.com/tutorials/tutorial-six-java.html" style="background-color: inherit; cursor: pointer; color: #444444; font-weight: bold;">RPC-style communication</a>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">此类不会在RPC参数和返回值上强加任何特定格式. 它只是简单地提供一种机制来向带特定路由键的交换器发送消息,并在回复队列上等待响应.</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">import</span> com.rabbitmq.client.RpcClient;  <br />RpcClient rpc = <span style="background-color: inherit; color: #008b8b;">new</span> RpcClient(<span style="background-color: inherit; color: #008b8b;">channel</span>, <span style="background-color: inherit; color: #008b8b;">exchangeName</span>, <span style="background-color: inherit; color: #008b8b;">routingKey</span>);</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">(其实现细节为:请求消息使用<span style="background-color: inherit; color: #333333;">basic.correlation_id唯一值字段来发送消息</span>,并使用<span style="background-color: inherit; color: #333333;">basic.reply_to来设置响应队列的名称</span>.)</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">一旦你创建此类的实例,你可以使用下面的任意一个方法来发送RPC请求:</p><pre style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; color: #333333; background-color: #eeeeee;"><span style="background-color: inherit; color: #008b8b;">byte</span>[] primitiveCall(<span style="background-color: inherit; color: #008b8b;">byte</span>[] message); <br />String stringCall(String message) Map mapCall(Map message) Map mapCall(Object[] keyValuePairs)</pre><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; color: #333333;">primitiveCall</span>&nbsp;方法会将原始byte数组转换为请求和响应的消息体. s<span style="background-color: inherit; color: #333333;">tringCall只是一个</span><span style="background-color: inherit; color: #333333;">primitiveCall的简单包装</span>,将消息体视为带有默认字符集编码的<span style="background-color: inherit; color: #333333;">String实例</span>.</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;"><span style="background-color: inherit; color: #333333;">mapCall</span>&nbsp;变种稍为有些复杂: 它会将原始java值包含在<span style="background-color: inherit; color: #333333;">java.util.Map中,并将其编码为</span>AMQP 0-9-1二进制表示形式,并以同样的方式来解码response. (注意:在这里,对一些值对象类型有所限制,具体可参考javadoc.)</p><p style="margin-right: 0px; margin-left: 0px; background-color: inherit;">所有的编组/解组便利方法都使用<span style="background-color: inherit; color: #333333;">primitiveCall来作为传输机制,其它方法只是在它上面的做了一个封装</span>.</p><div></div></div><img src ="http://www.blogjava.net/qbna350816/aggbug/430771.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-04 00:37 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/04/430771.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RabbitMQ CookBook-第1章-使用AMQP</title><link>http://www.blogjava.net/qbna350816/archive/2016/06/03/430769.html</link><dc:creator>胡小军</dc:creator><author>胡小军</author><pubDate>Fri, 03 Jun 2016 15:22:00 GMT</pubDate><guid>http://www.blogjava.net/qbna350816/archive/2016/06/03/430769.html</guid><wfw:comment>http://www.blogjava.net/qbna350816/comments/430769.html</wfw:comment><comments>http://www.blogjava.net/qbna350816/archive/2016/06/03/430769.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qbna350816/comments/commentRss/430769.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qbna350816/services/trackbacks/430769.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在本章中,将包含下面的内容:连接中间件生产消息消费消息使用JSON序列化消息使用RPC消息&nbsp;&nbsp;广播消息使用direct交换器来处理消息路由使用topic交换器来处理消息路由保证消息处理分发消息到多个消费者使用消息属性事务消息处理未路由消息要运行本章内的示例,你需要首先:安装Java JDK 1.6+安装Java RabbitMQ client library正确地配置CLASS...&nbsp;&nbsp;<a href='http://www.blogjava.net/qbna350816/archive/2016/06/03/430769.html'>阅读全文</a><img src ="http://www.blogjava.net/qbna350816/aggbug/430769.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qbna350816/" target="_blank">胡小军</a> 2016-06-03 23:22 <a href="http://www.blogjava.net/qbna350816/archive/2016/06/03/430769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>