﻿<?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-永恒瞬间-随笔分类-分布式</title><link>http://www.blogjava.net/cdredfox/category/49379.html</link><description>一个小小程序员的信口开河</description><language>zh-cn</language><lastBuildDate>Mon, 02 Jan 2012 09:42:00 GMT</lastBuildDate><pubDate>Mon, 02 Jan 2012 09:42:00 GMT</pubDate><ttl>60</ttl><item><title>AMQP与QPID简介</title><link>http://www.blogjava.net/cdredfox/archive/2012/01/02/367727.html</link><dc:creator>永恒瞬间</dc:creator><author>永恒瞬间</author><pubDate>Mon, 02 Jan 2012 09:18:00 GMT</pubDate><guid>http://www.blogjava.net/cdredfox/archive/2012/01/02/367727.html</guid><wfw:comment>http://www.blogjava.net/cdredfox/comments/367727.html</wfw:comment><comments>http://www.blogjava.net/cdredfox/archive/2012/01/02/367727.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cdredfox/comments/commentRss/367727.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cdredfox/services/trackbacks/367727.html</trackback:ping><description><![CDATA[<div><div style="line-height: 1.4; height: 100%; width: 100%; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; overflow-x: auto; overflow-y: auto; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; cursor: text; word-wrap: break-word; font-family: arial, 'Microsoft YaHei', 微软雅黑, simsun, 宋体; color: #333333; text-align: left; "><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">自已整理的一些零散的知识点<br /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong style="line-height: 1.4; ">简介</strong></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">AMQP（消息队列协议，Advanced Message Queuing Protocol）是一种消息协议 ，等同于JMS，但是JMS只是java平台的方案，AMQP是一个跨语言的协议。</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">AMQP 不分语言平台,最初来自JPMorgon,因为业务需要而滋生，很快从金融界推广到整个计算机界流行起来。</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">AMQP 目前还是一个草案，最新版本是：0.10</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><br style="line-height: 1.4; " /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Publisher ---&gt;Exchange ---&gt; MessageQueue ---&gt;Consumer</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">整个过程是异步的.Publisher,Consumer相互不知道对方的存在</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Exchange负责交换/路由，依靠Routing Key,每个消息者有一个Routing Key</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">每个Binding将自已感兴趣的RoutingKey告诉Exchange,以便Exchange将相关的</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">消息转发给相应的Queue</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><br style="line-height: 1.4; " /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong style="line-height: 1.4; ">几个概念</strong></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Producer,Routing Key,Exchange,Binding,Queue,Consumer.</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Producer: 消息的创建者，消息的发送者</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Routing Key：唯一用来映射消息该进入哪个队列的标识</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Exchange：负责消息的路由，交换</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Binding:定义Queue和Exchange的映射关系</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Queue：消息队列</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Consumer：消息的使用者</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><br style="line-height: 1.4; " /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong style="line-height: 1.4; ">Exchange类型</strong></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Fan-Out:类似于广播方式，不管RoutingKey</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Direct:根据RoutingKey,进行关联投寄&nbsp;</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Topic:类似于Direct,但是支持多个Key关联，以组的方式投寄。</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">&nbsp; &nbsp; &nbsp; key以.来定义界限。类似于usea.news,usea.weather.这两个消息是一组的。</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><br style="line-height: 1.4; " /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><strong style="line-height: 1.4; ">QPID</strong></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">QPID是AMQP的一个实现，提供C++，JAVA版本的broker,支持多种语言客户端。</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">基本功能外提供以下特性：</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">采用 Corosync(?)来保证集群环境下的Fault-tolerant(?) 特性</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">支持XML的Exchange,消息为XML时，彩用Xquery过滤</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">支持plugin</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">提供安全认证，可对producer/consumer提供身份认证</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">qpidd --port --no-data-dir --auth</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">port:端口</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">--no-data-dir:不指定数据目录</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">--auth：不启用安全身份认证</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><br style="line-height: 1.4; " /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">启动后自动创建一些Exchange,amp.topic,amp.direct,amp.fanout</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">tools:</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Qpid-config:维护Queue,Exchange,内部配置&nbsp;</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Qpid-route:配置broker Federation(联盟？集群？)</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">Qpid-tool:监控</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; "><br style="line-height: 1.4; " /></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">参考：</p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">关于AMQP更多信息可参考：&nbsp;<a target="_blank" rel="nofollow" href="http://www.openamq.org/doc:amqp-background" style="line-height: 1.4; color: #7594b3; ">http://www.openamq.org/doc:amqp-background</a></p><p style="line-height: 1.4; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; ">关于QPID的更多和使用可参考：<a target="_blank" rel="nofollow" href="http://qpid.apache.org/" style="line-height: 1.4; color: #7594b3; ">http://qpid.apache.org/</a></p></div></div><img src ="http://www.blogjava.net/cdredfox/aggbug/367727.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cdredfox/" target="_blank">永恒瞬间</a> 2012-01-02 17:18 <a href="http://www.blogjava.net/cdredfox/archive/2012/01/02/367727.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分布式事务简述</title><link>http://www.blogjava.net/cdredfox/archive/2011/08/21/356970.html</link><dc:creator>永恒瞬间</dc:creator><author>永恒瞬间</author><pubDate>Sat, 20 Aug 2011 16:02:00 GMT</pubDate><guid>http://www.blogjava.net/cdredfox/archive/2011/08/21/356970.html</guid><wfw:comment>http://www.blogjava.net/cdredfox/comments/356970.html</wfw:comment><comments>http://www.blogjava.net/cdredfox/archive/2011/08/21/356970.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/cdredfox/comments/commentRss/356970.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cdredfox/services/trackbacks/356970.html</trackback:ping><description><![CDATA[&nbsp; 随着系统越来越大，不断的模块化和SOA化，你的系统可能被分散于不同的机器上，这时候，你原先的单机本地事务可能已经无法满足你的需求，你可能要跨系统跨资源的去使用事务。这就是分布式事务。<br />&nbsp;<strong> 事务有四个特性：</strong><br /><ol><li>&nbsp; &nbsp;原子性</li><li>&nbsp; &nbsp;一致性</li><li>&nbsp; &nbsp;隔离性</li><li>&nbsp; &nbsp;持久性</li></ol>&nbsp; 具体就不多介绍了，相信大家都能明白ACID特性的基本含义。<br /><br /><strong>事务模型<br /></strong><br />而一个具体的事务需要涉及到的模型（无论哪种模型）一般由下面几部分组成：<br /><ol><li>AP 应用程序</li><li>RM 资源管理器</li><li>TM 事务管理器</li></ol>这里的资源管理器一般指数据库资源，而事务管理器，大多是由数据库厂商提供。<br />那么其实在分布式事务中，也应该符合以上事务的特性和模型，只是资源管理器(RM)变得多了起来.<br /><br /><strong>分布式事务介绍<br /></strong><br />分布式事务最大的问题在于<strong>如何确定资源的状态，以及保证一致性，原子性</strong>。<br />一般来说分布事务由 <br /><ol><li>原子提交协议&nbsp;</li><li>协调器</li><li>参与者</li><li>事务恢复器</li><li>死锁检测器</li></ol> 五部分组成。<br /><br /><strong>原子提交协议</strong>指的是如何保证原子提交，一般分为<strong>单阶段原子提交协议</strong>，<strong>两阶段原子提交协议</strong>，<strong>三阶段原子提交协议</strong>。<br /><br /><strong>对于单阶段原子提交协议</strong>来说，根本没有办法保证分布式事务的原子性，所以不适用于分布式事务中。<br /><br /><strong>两阶段原子提交协议则</strong>是各种分布式事务实现中使用最广泛的一种原子提交协议：它主要是交事务提交的过程分为二阶段，投票和最终提交。事务由协调者发起一个事务，参与者加入到事务中后，第一阶段时候，所有的参与者准备资源，并将资源hold住，协调者询问所有的参与者是否可以提交？所有的参与者向协调者响应结果YES/NO,当所有的协调者都响应YES的时候，协调者才会发起第二阶段，向所有的参与者通知提交事务，当所有的参与者都提交确认会会再通知协调者。至此事务处理完毕。<br /><br /><strong>三阶段提交协议</strong>由于协调者与参与者多次进行沟通所以代价很大，一般不会使用。但是它能缩小事务处理&#8220;不确定&#8221;状态的延迟时间。<br /><br />所谓&#8220;不确定&#8221;状态就是指当参与者向协调者反馈可以提交的时候，长时间没有收到协调者的通知，这时候参与者没有办法确定事务最终需要如何处理，所以状态为不确定状态。<br /><br /><strong>协调者，参与者一般通过如下动作来进行通信：</strong><br /><ol><li>join:由协调者提供，用来注册新的参与者</li><li>canCommit：协调者询问参与者是否能够提交</li><li>doCommit ：协调者通知参与者提交事务</li><li>doAbort：协调者通知参与者放弃事务</li><li>haveCommit：参与者向协调者确认已经提交事务</li><li>getDecision：当处于&#8220;不确定&#8221;状态时，参与者用来询问协调者事务的目前状态。</li></ol>对于haveCommit特别说明一下，是当第一阶段的时候，协调者发现长时间参与者没有向协调者反馈事务状态，则协调者会主动调用该接口事务的情况，如果仍然无响应，则会通知所有的参与者放弃该事务。<br /><br />任何事情都会有意外产生，特别是对于跨系统间的通信更容易产生问题，比如网络异常，机器down机，这个时候就需要事务恢复器来作相应的处理。<br /><strong><br />对于处于第一阶段的事务，</strong>如果参与者发生意外，则协调者会通知所有的参与者进行事务放弃，但是如果协调者出生故障时，就必须要能 够就行事务恢复，所以协调者必须在开始事务的时候，产生唯一的事务ID,并且对事务进行持久化，在协调者恢复的时候，参够让人参与者继续进行事务。<br /><strong><br />而对于第二阶段出现的故障，</strong>由于第一阶段进行了资源的个决，则事务认为是必然能成功的，这个事候，如果这个时候参与者发生故障，则协调者需要一套重试机制，让参与者在恢复过来后，能够将事务进行完成或者人工介入。<br /><br />关于死锁检测器这里就不多描述了，以后有机会再描述。<br /><br /><strong>语言组织能力比较差，太久没有写东西，凑合着写给自已看吧。</strong><img src ="http://www.blogjava.net/cdredfox/aggbug/356970.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cdredfox/" target="_blank">永恒瞬间</a> 2011-08-21 00:02 <a href="http://www.blogjava.net/cdredfox/archive/2011/08/21/356970.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>分布式系统领域经典论文翻译集</title><link>http://www.blogjava.net/cdredfox/archive/2011/08/16/356622.html</link><dc:creator>永恒瞬间</dc:creator><author>永恒瞬间</author><pubDate>Tue, 16 Aug 2011 04:20:00 GMT</pubDate><guid>http://www.blogjava.net/cdredfox/archive/2011/08/16/356622.html</guid><wfw:comment>http://www.blogjava.net/cdredfox/comments/356622.html</wfw:comment><comments>http://www.blogjava.net/cdredfox/archive/2011/08/16/356622.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/cdredfox/comments/commentRss/356622.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/cdredfox/services/trackbacks/356622.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 转自: 弯曲评论【陈怀临：这个年轻人很优秀。优秀的不仅仅是能把这些经典论文看完，而是还花心思翻译出来。他的博客是：银河里的星星。其联系方式是phylips@bmy】分布式领域论文译序sql&amp;nosql年代记海量数据的存储计算和查询一．google论文系列1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;google系列论文译序2. &nbsp; &nbsp; &n...&nbsp;&nbsp;<a href='http://www.blogjava.net/cdredfox/archive/2011/08/16/356622.html'>阅读全文</a><img src ="http://www.blogjava.net/cdredfox/aggbug/356622.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/cdredfox/" target="_blank">永恒瞬间</a> 2011-08-16 12:20 <a href="http://www.blogjava.net/cdredfox/archive/2011/08/16/356622.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>