Advanced Message Queuing Protocol ( 1 ) 概述
The Advanced Message Queuing Protocol (AMQP)是一个标准开放的应用层的消息中间件(Message Oriented Middleware)协议。AMQP定义了通过网络发送的字节流的数据格式。因此兼容性非常好,任何实现AMQP协议的程序都可以和与AMQP协议兼容的其他程序交互,可以很容易做到跨语言,跨平台。
Development
AMQP由JPMorgan Chase & Co于2006年中旬发布。JPMorgan Chase & Co和iMatix定义协议规范,并由包括Red Hat, Cisco Systems, TWIST, IONA, and iMatix参与开发。截至2009年11月,工作组的成员包括 Bank of America, Barclays, Cisco Systems, Credit Suisse, Deutsche Börse Systems, Envoy Technologies, Inc., Goldman Sachs, Progress Software, iMatix Corporation, JPMorgan Chase Bank Inc. N.A, Microsoft Corporation, Novell, Rabbit Technologies Ltd., Red Hat, Inc., Solace Systems, Tervela Inc., TWIST Process Innovations ltd, WS02 and 29West Inc.
值得一提的是,AMQP的设计目标是建立开放工业标准协议。虽然AMQP的起源于金融服务行业,但是它的用途并不局限于金融行业内。
The AMQP model
分布式模型
AMQP 定义了一系列实体(Entity), 从连接的角度来看, 他们是
Message Broker:连接Client的服务器,他使用AMQP协议与Client交互,并且可以作为集群运行, 但是这些细节并没有写入AMQP的规范。
User: 用户可以连接到Message Broker
Connection: 物理连接, 绑定到用户
Channel:Channel是有状态的逻辑连接。Client连接上执行并行操作应维护不同的Channel。
所有发送和接收的实体(Entity)都在Channel中定义。任何试图声明一个已具名的有不同属性的实体(Entity),都将导致错误。如果需要改变实体(Entity)的属性, 必须先将该实体删除,之后重新定义。实体(Entity)名字必须唯一, Broker根据实体(Entity)名字来判断Client的操作权限。
Exchanges
Exchange 从Client接收消息,并把它们分发到Message Queue
Exchange 的属性
passive: Exchange不必被声明,但是如果不存在,将会产生错误
durable:如果Broker重起,Exchange 是否还有效
auto-delete:只要发现它没有被绑定到Queue,Exchange将被删除。
Queues
Queue用于存放Message,直到有客户端可以处理这个Message。
Queue的属性
alternate-Exchange:当信息被拒绝接收,将转发到这个Exchange,并从Queue中删除。
passive: Queue 不必被声明, 但是如果不存在, 将会产生错误
durable:如果Broker重起,Queue 是否还有效
exclusive:只能有一个Client一个具体的Queue。
auto-delete:如果Queue未被订阅, 则自动删除Queue
Messages
Message一律不具名,并被发送到Exchange。它们由一个Message header和Message content的构成。body是一个包含若干可选的属性的不可见的Message header:
routing-key:这个属性取决于Exchange的类型
immediate:如果Message不能立即被处理, 则将其视为unroutable
delivery-mode:表明该Message是否需要持久保存。
priority:Message的优先级
expiration:Message多久之后失效, 之后将作为unroutable处理
Bindings
Binding 是一个Queue和Exchange的逻辑绑定,并指定一个Message如何从Exchange发送到Queue。
Unconditional :请求Exchange的所有的Message。
Conditional on a fixed string :请求Exchange上具有指定routing key的所有Message
Conditional on a pattern match : 请求Exchange上具有指定routing key, 并且符合指定pattern的所有Message
Conditional on multiple fixed strings:请求Exchange上属性符合要求的所有Message
Conditional on multiple fixed strings:请求Exchange上模式符合要求的所有Message
Conditional on algorithmic comparison:请求Exchange上符合算法要求的所有Message
Conditional on content inspection:请求Exchange上内容符合要求的所有Message
Implementations
These are the known publicly available AMQP implementations:
OpenAMQ, original open-source implementation of AMQP, written in C by iMatix. Runs on Linux, AIX, Solaris, Windows, OpenVMS. Includes Broker, APIs in C/C++ and Java JMS, remote admin shell, scripting, federation, failover, and AMQP-over-HTTP via the RestMS protocol.
Apache Qpid, a project in the Apache Foundation with Client APIs that support C++, Ruby, Java, JMS, Python and .NET.
Red Hat Enterprise MRG implements the latest version of AMQP 0-10 providing rich set of features like full management, federation, Active-Active clustering using Qpid as upstream, adds a web console and many enterprise features and "C++, Ruby, Java, JMS, Python .NET" Clients.
RabbitMQ, an independent open-source implementation. The server is written in Erlang, and multiple Clients including Python, Ruby, .NET, Java, JMS, C, PHP, Actionscript, XMPP, STOMP, and AJAX are provided. RabbitMQ is distributed with Ubuntu, FreeBSD ports.
AMQP Infrastructure yum installable AMQP 0-10 (maintained in the latest 3 versions of Fedora) which includes the Broker, management tools, agents and Clients.
ØMQ, a high-performance messaging platform that is able to treat AMQP-compliant Brokers as nodes in distributed messaging network.
Zyre, a Broker that implements RestMS and AMQP to provide RESTful HTTP access to AMQP networks.
reference:
http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol