2cc2f341cf6a9456524b9788e8136f69.ppt
- Количество слайдов: 41
AMQP, Erlang, and Rabbit. MQ OOI Cyberinfrastructure Design Meeting San Diego, 17 th-19 th October 2007 Matthias Radestock matthias@lshift. net October 18, 2007 1
So you want to build a computing infrastructure for ocean observation … …that transfers, routes, transforms, processes and stores a variety of data streams, and works, so it needs to be n n distributed reliable & resilient manageable secure evolves, so it needs to be n n scaleable portable pluggable interoperable … like an enterprise messaging system! October 18, 2007 2
AMQP Everyone uses email without thinking, so then why is universal commercial business messaging so hard? → need an Open Standard Protocol for Message Oriented Middleware AMQP aims to become THE standard for enterprise messaging Made to satisfy real needs: • created by users and technologists working together • in development for 3+ years, went public on June 20 th 2006 “business dialtone” October 18, 2007 3
AMQP’s place in the “stack” Product Layer User Applications CDL-BPM-CEP ESB / SOA / EDA WCF “Document Model” “Rich Object Model” Use bank treasury settlement reports AMQP Fp. ML trades MQ Store & forward orders Tibco Guaranteed Delivery Cisco October 18, 2007 WS-* positions Transaction participant JMS Standard Content based routing (1 -Many, 1 -1) Network (TCP/IP, UDP, SCTP) FIX, FAST send/ack ticks data AMQP Utility Services e. g. exchange access links 4
Comparison with some other protocols n n n n SMTP – unreliable, slow HTTP – synchronous, unreliable, no routing XMPP – no delivery fidelity or queue management FTP – point to point, transient, does not work well with NAT/SSL MQ – exactly once TCP – at least once, reliable but short lived, no app level state mgmt UDP – fast but has no delivery guarantees AMQP - can do all of the above as ‘use cases’ … and switch between them October 18, 2007 5
How does it work? Queue File Transfer Exchange Queue Messaging Bindings Queue Transactions n n n any language (C, C++, Java, C#, Python, Javascript, Erlang, Lisp, Ruby, Tcl, PHP, …) any model (native, JMS, Mule, WCF, …) any payload (binary, XML, SOAP, JSON, …) any transport (TCP, SCTP, HTTP, …) any platform (desktop, router, mobile, EC 2, …) October 18, 2007 n n n reliable interoperable manageable performant scaleable 6
A typical AMQP client program # Addresses where a particular broker is reachable. endpoints = [amqp. Endpoint('hostname', 5672), amqp. Endpoint('alternate', 5673)] # Construct a session = amqp. Session("1234", 600, endpoints) # Set up some resources on the broker. session. Exchange. Declare("xname", amqp. Exchange. Types. DIRECT) session. Queue. Declare("qname") session. Queue. Bind("xname", "qname", "routingkey") # Publish a message. session. Message. Transfer("xname", "routingkey", "body") # Set up a consumer. session. Message. Consume("qname", My. Consumer(session)) class My. Consumer: def __init__(self, session): self. session = session def handle_Message. Transfer(self, destination, exchange, routingkey, body): print "Received message: " + body return amqp. Constants. ACCEPT October 18, 2007 7
Under the covers – AMQP Layering Application API calls Model commands queues, exchanges, messages, transactions, … command segmentation / assembly, ordering and acknowledgement Execution framesets Session frameset sequencing frameset (dis)assembly frame flow control reliability (exactly once) and failover Framing bytes / packets Transport October 18, 2007 (de)multiplexing by channel/stream heartbeating framing, integrity check 8
Communication between peers Application Model Execution Session Framing messages commands control frames Application Model Execution Session Framing Transport October 18, 2007 9
Under the covers: session reattachment October 18, 2007 10
AMQP - Inclusive Governance Products Protocol TWIST JPMorgan 29 West D/Borse Novell Credit Suisse Envoy Goldman Sachs Apache Community Feedback AMQP Working Group controls the standard October 18, 2007 i. Matix Open. AMQ Red Hat Enterprise Messaging Iona Celtix AM Rabbit. MQ Cisco Network Diverse products implement the standard 11
So you want to build a computing infrastructure for ocean observation … …that transfers, routes, transforms, processes and stores a variety of data streams, and works, so it needs to be n n distributed reliable & resilient manageable secure evolves, so it needs to be n n scaleable portable pluggable interoperable … like a telecommunications system! October 18, 2007 12
Erlang History 2007: A New Book! No language was well suited for telecom systems development 1984: Ericsson Computer Science Lab formed October 18, 2007 1987: Early Erlang Prototype projects 1996: Open Telecom Platform 1994: First Product 1998: Open Source Erlang 1993: Distributed Erlang 1993: The First Book 1991: First fast implementation 13
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 High abstraction level Concise readable programs No mutable state 14
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 Light-weight processes Highly scalable Message Passing 15
Erlang Highlights: Concurrency Processes communicate by asynchronous message passing Pid ! {data, 12, 13} October 18, 2007 receive {start} -> ……… {stop} -> ……… {data, X, Y} -> ……… end 16
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust Response times in the low milliseconds n Distributed Per-process garbage collection n Hot code loading n External interfaces n Portable October 18, 2007 17
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 Simple and consistent error recovery Supervision hierarchies "Program for the correct case" 18
Erlang Highlights: Robustness Cooperating processes may be linked together October 18, 2007 19
Erlang Highlights: Robustness When a process terminates, an exit signal is sent to all linked processes … and the termination is propagated October 18, 2007 20
Erlang Highlights: Robustness Exit signals can be trapped and received as messages receive {‘EXIT’, Pid, . . . } ->. . . end October 18, 2007 21
Erlang Highlights: Robustness Robust systems can be built by layering “Supervisors” “Workers” October 18, 2007 22
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 Explicit or transparent distribution Network-aware runtime system 23
Erlang Highlights: Distribution B ! Msg C ! Msg Erlang Run-Time System network October 18, 2007 24
Erlang Highlights: Distribution Simple Remote Procedure Call {rex, Node} ! {self(), {apply, M, F, A}}, receive {rex, Node, What} -> What end loop() -> receive {From, {apply, M, F, A}} -> Answer = apply(M, F, A), From ! {rex, node(), Answer} loop() end. October 18, 2007 25
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 Easily change code in a running system Enables non-stop operation Simplifies testing 26
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 "Ports" to the outside world behave as Erlang processes 27
Erlang Highlights: External Interfaces Port External process Port ! {self(), {command, [1, 2, 3]}}, receive {Port, {data, Info}} ->. . . end October 18, 2007 28
Erlang Highlights n Functional n Concurrent n Soft real-time n Robust n Distributed n Hot code loading n External interfaces n Portable October 18, 2007 Erlang runs on a Virtual Machine ported to UNIX, Windows, Vx. Works, OS X, … Supports heterogeneous networks. 29
Open Telecom Platform Applications, Libraries & Tools System Design Principles T O P October 18, 2007 30
October 18, 2007 31
Credits n n Alexis Richardson, Cohesive. FT – for providing much of the AMQP material Francesco Cesarini, Erlang Consulting – for providing much of the Erlang material Tony Garnock-Jones, LShift – for the sample code Matthew Arrott – for inviting me Thank you! October 18, 2007 32
Backup slides October 18, 2007 33
AMQP features n In some ways like email but: q q n What goes in must come out Very fast - think big - global scale communication In some ways like TCP and HTTP, but delivers true MESSAGING q q q Routing and addressing “to: phil@cohesiveft. com”, “buy. ibm. 100” Guaranteed Delivery Delegation - the concept of a middleman → security, reliability, translation, … October 18, 2007 34
AMQP version history and roadmap Q 2’ 06 0 -8 routing Q 4’ 06 0 -9 clarifications & bug fixes, experimental work-in-progress extensions Q 4’ 07 0 -10 guaranteed delivery, transport independence, general tidying up Q 1’ 08 0 -11 management, security, federation, addressing Q 2’ 08 1 -0 October 18, 2007 release 35
Under the covers: session creation October 18, 2007 36
Under the covers: configuration October 18, 2007 37
Under the covers: message transfer October 18, 2007 38
Mule binding <mule-configuration id="Rabbit. MQ_Demo" version="1. 0"> <model name="rabbitmq. Demo"> <mule-descriptor name="Mulebot“ implementation="com. rabbitmq. examples. muledemo. Mulebot"> <inbound-router> <endpoint address="amqp: //localhost/? vhost=/& realm=/data& exchange=chat& exchange-type=fanout& routing-key </inbound-router> <outbound-router match. All="true"> <router class. Name="org. mule. routing. outbound. Outbound. Pass. Through <endpoint address="amqp: //localhost/? vhost=/& realm=/data&am exchange=chat& exchange-type=fanout& routing-key </router> </outbound-router> </mule-descriptor> </model> </mule-configuration> October 18, 2007 39
WCF binding service = new Service. Host(typeof(Calculator), new Uri("soap. amq: //dev. rabbitmq. com: 5672/")); service. Add. Service. Endpoint(typeof(ICalculator), new Rabbit. MQDual. Binding(), "Calculator"); service. Open(); fac = new Channel. Factory<ICalculator>( new Rabbit. MQDual. Binding() { Client. Base. Address = new Uri("soap. amq: //dev. rabbitmq. com: 5672/")}, "soap. amq: //dev. rabbitmq. com: 5672/Calculator"); fac. Open(); calc = fac. Create. Channel(); Console. Write. Line("{0} + {1} = {2}", x, y, calc. Add(3, 4)); ((IChannel)calc). Close(); service. Close(); October 18, 2007 40
Erlang Highlights: High-level Constructs Parsing an IP Datagram using the Bit Syntax -define(IP_VERSION, 4). -define(IP_MIN_HDR_LEN, 5). …… Dgram. Size = size(Dgram), <<? IP_VERSION: 4, HLen: 4, Srvc. Type: 8, Tot. Len: 16, ID: 16, Flgs: 3, Frag. Off: 13, TTL: 8, Proto: 8, Hdr. Chk. Sum: 16, Src. IP: 32, Dest. IP: 32, Body/binary>> = Dgram, if (HLen >= 5) and (4*HLen =< Dgram. Size) -> Opts. Len = 4*(HLen - ? IP_MIN_HDR_LEN), <<Opts: Opts. Len/binary, Data/binary>> = Body, …. . end. October 18, 2007 41
2cc2f341cf6a9456524b9788e8136f69.ppt