Source: U2Canvas 2012
不知道最近寫的blog算不算是策展(Curation)的一種,正因為我遇到一些問題,有一些疑問,所以我就自問自答的整理了網路上收集來的資料(Reference),用自以為類似寫論文的方式整理這些資料,並且嘗試消化吸收,看看可不可以提出自己的一些見解? 嗯這都是題外話~XD
今天要自問自答的題目是 - 同樣都是Message Queue到底AMQP跟JMS 有什麼差別? AMQP 優點在哪?
Message Queue
在介紹JMS和AMQP之前先說一下什麼時候會需要用到Message Queue,就如同下圖所示,如果你今天需要一個Reliable (保證傳達) 且 Async (允許非同步) 的訊息傳達和交換方式,這時候你就需要Message Queue,而首選就是AMQP。此外對於Cloud 和SOA 來說 AMQP也是佔了很重要的角色。JMS的是什麼?
JMS 是Java的標準 API 使用兩種機制來傳遞訊息:
- store-and-forward
- publish/subscribe
但是 JMS 就像許多JSR的標準一樣,只是制定Interface以及行為模式,所以本身並沒有實作,必須倚賴其他的3rd-party實作,此外就如同它的名字,它只能在Java的環境使用,所以不適合跨平台跨系統的整合。而AMQP的出現就是為了要解決這個問題,不但實作了JMS的標準更提供了API for C, C++, Python, C# or any other language on Linux, Solaris, Windows, Z/OS, etc... [1]
AMQP 的緣起
AMQP 全名 Advanced Message Queuing Protocol 是一個由OASIS公開的標準,它誕生是在 2006年 由金融業 JP Morgan 的 John O;Hara 了解決異質平台訊息交換所的問題所提議,目的是要建立一個標準的協定與平台 - 包含資料的結構(binary wire-level protocol) 、如何傳遞,另外也定義了以下的特點 message orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and security.[1]
AMQP與JMS主要差異
這一段就直接貼原文了,這種東西真的很難翻譯..@@
AMQP mandates the behavior of the messaging provider and client to the extent that implementations from different vendors are truly interoperable, in the same way as SMTP, HTTP, FTP, etc. have created interoperable systems. Previous attempts to standardize middleware have happened at the API level (e.g. JMS) and this did not create interoperability.[3] Unlike JMS, which merely defines an API, AMQP is a wire-level protocol. A wire-level protocol is a description of the format of the data that is sent across the network as a stream of octets. Consequently any tool that can create and interpret messages that conform to this data format can interoperate with any other compliant tool irrespective of implementation language.
AMQP主要定義了以下主要元件
AMQP (note that Rabbit works with many protocols including STOMP, HTTP, HTTPS, XMPP, and SMTP), here are some basic component descriptions:
- Exchange
- The entity within the server which receives messages from producer applications and optionally routes these to message queues within the server
- Exchange type
- The algorithm and implementation of a particular model of exchange. In contrast to the "exchange instance", which is the entity that receives and routes messages within the server
- Message queue
- A named entity that holds messages and forwards them to consumer applications,Queues are bound to exchanges with patterns
- Binding
- An entity that creates a relationship between a message queue and an exchange. Message are routing to queues by matching routing keys against binding patterns.
- Routing key
- A virtual address that an exchange may use to decide how to route a specific message. Message are published with a routing key.
所以AMQP最主要就是多了Exchange的機制,除了 store-and-forward、publish/subscribe外還多了許多的Routing 方法 [5]:
- Direct Exchange
- Fanout Exchange
- Topic Exchange
- Header Exchange
- System Exchange
Refernece:
[1] How is this different from the Java Messaging Service (JMS)?
[2] Advanced Message Queuing Protocol
[3] Migrating From JMS to AMQP: RabbitMQ, Spring, Apache Camel, and Apache Qpid
[4] Introduction to amqp messaging with Rabbitmq
[5] Exchanges
沒有留言:
張貼留言