420 likes | 693 Views
AMQP, Erlang, and RabbitMQ. OOI Cyberinfrastructure Design Meeting San Diego, 17 th -19 th October 2007. Matthias Radestock matthias@lshift.net. distributed reliable & resilient manageable secure. So you want to build a computing infrastructure for ocean observation ….
E N D
AMQP, Erlang, and RabbitMQ OOI Cyberinfrastructure Design Meeting San Diego, 17th-19th October 2007 Matthias Radestock matthias@lshift.net
distributed reliable & resilient manageable secure 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 evolves,so it needs to be • scaleable • portable • pluggable • interoperable … like an enterprise messaging system!
AMQP Everyone uses email without thinking, so then why is universal commercial business messaging so hard? “business dialtone” → need an OpenStandard 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 20th 2006
AMQP’s place in the “stack” Product Layer Use Standard User Applications bank CDL-BPM-CEP treasury ESB / SOA / EDA settlement WS-* “Document Model” reports FpML WCF “Rich Object Model” positions Transaction participant trades FIX, FAST MQ Store & forward orders JMS AMQP Guaranteed Delivery send/ack AMQP Tibco Content based routing (1-Many, 1-1) ticks Utility Services e.g. exchange access links Cisco Network (TCP/IP, UDP, SCTP) data
Comparison with some other protocols • 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
How does it work? Queue File Transfer Queue Exchange Messaging Queue Bindings Transactions • 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, EC2, …) • reliable • interoperable • manageable • performant • scaleable
A typical AMQP client program # Addresses where a particular broker is reachable. endpoints = [amqp.Endpoint('hostname', 5672), amqp.Endpoint('alternate', 5673)] # Construct a session. session = amqp.Session("1234", 600, endpoints) # Set up some resources on the broker. session.ExchangeDeclare("xname",amqp.ExchangeTypes.DIRECT) session.QueueDeclare("qname") session.QueueBind("xname","qname","routingkey") # Publish a message. session.MessageTransfer("xname","routingkey","body") # Set up a consumer. session.MessageConsume("qname",MyConsumer(session)) class MyConsumer: def __init__(self,session): self.session = session def handle_MessageTransfer(self,destination,exchange, routingkey,body): print "Received message: " + body return amqp.Constants.ACCEPT
Under the covers – AMQP Layering Application queues, exchanges, messages, transactions, … API calls Model command segmentation / assembly, ordering and acknowledgement commands Execution frameset sequencingframeset (dis)assemblyframe flow controlreliability (exactly once) and failover framesets Session frames Framing (de)multiplexing by channel/stream heartbeating framing, integrity check bytes / packets Transport
Communication between peers messages Application Application Model commands Model controls Execution Execution control frames Session Session control frames Framing Framing Transport
Apache AMQP - Inclusive Governance Products Protocol JPMorgan D/Borse Credit Suisse Goldman Sachs TWIST Novell 29West Envoy Community Feedback Cisco Network iMatix OpenAMQ Red Hat Enterprise Messaging IonaCeltixAM RabbitMQ AMQP Working Group controls the standard Diverse products implement the standard
distributed reliable & resilient manageable secure 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 evolves,so it needs to be • scaleable • portable • pluggable • interoperable … like a telecommunications system!
Erlang History 2007: A NewBook! 1996: Open Telecom Platform No language was well suited for telecom systems development 1998: Open Source Erlang 1994: First Product 1993: Distributed Erlang 1987: Early Erlang Prototype projects 1993: The First Book 1984: Ericsson Computer Science Lab formed 1991: First fast implementation
Erlang Highlights High abstraction level Concise readable programs No mutable state • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable
Erlang Highlights • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable Light-weight processes Highly scalable Message Passing
Erlang Highlights: Concurrency Processes communicate by asynchronous message passing receive {start} -> ……… {stop} -> ……… {data,X,Y} -> ……… end Pid ! {data,12,13}
Erlang Highlights • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable Response times in the low milliseconds Per-process garbage collection
Erlang Highlights • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable Simple and consistent error recovery Supervision hierarchies "Program for the correct case"
Erlang Highlights: Robustness Cooperating processes may be linked together
Erlang Highlights: Robustness When a process terminates, an exit signal is sent to all linked processes … and the termination is propagated
Erlang Highlights: Robustness Exit signals can be trapped and received as messages receive {‘EXIT’,Pid,...} -> ... end
Erlang Highlights: Robustness Robust systems can be built by layering “Supervisors” “Workers”
Erlang Highlights • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable Explicit or transparent distribution Network-aware runtime system
Erlang Highlights: Distribution B ! Msg C ! Msg Erlang Run-Time System Erlang Run-Time System network
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.
Erlang Highlights Easily change code in a running system Enables non-stop operation Simplifies testing • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable
Erlang Highlights • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable "Ports" to the outside world behave as Erlang processes
Erlang Highlights: External Interfaces External process Port Port ! {self(), {command, [1,2,3]}},receive {Port, {data, Info}} -> ...end
Erlang Highlights • Functional • Concurrent • Soft real-time • Robust • Distributed • Hot code loading • External interfaces • Portable Erlang runs on a Virtual Machine ported to UNIX, Windows, VxWorks, OS X, … Supports heterogeneous networks.
T O P Open Telecom Platform Applications, Libraries & Tools System Design Principles
Credits • Alexis Richardson, CohesiveFT –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!
AMQP features • In some ways like email but: • What goes in must come out • Very fast - think big - global scale communication • In some ways like TCP and HTTP, but delivers true MESSAGING • Routing and addressing - “to:phil@cohesiveft.com”, “buy.ibm.100” • Guaranteed Delivery • Delegation - the concept of a middleman → security, reliability, translation, …
Mule binding <mule-configuration id="RabbitMQ_Demo" version="1.0"> <model name="rabbitmqDemo"> <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 matchAll="true"> <router className="org.mule.routing.outbound.OutboundPassThroughRouter"> <endpoint address="amqp://localhost/?vhost=/&realm=/data& exchange=chat&exchange-type=fanout&routing-key="/> </router> </outbound-router> </mule-descriptor> </model> </mule-configuration>
WCF binding service = new ServiceHost(typeof(Calculator), new Uri("soap.amq://dev.rabbitmq.com:5672/")); service.AddServiceEndpoint(typeof(ICalculator), new RabbitMQDualBinding(), "Calculator"); service.Open(); fac = new ChannelFactory<ICalculator>( new RabbitMQDualBinding() { ClientBaseAddress = new Uri("soap.amq://dev.rabbitmq.com:5672/")}, "soap.amq://dev.rabbitmq.com:5672/Calculator"); fac.Open(); calc = fac.CreateChannel(); Console.WriteLine("{0} + {1} = {2}", x, y, calc.Add(3, 4)); ((IChannel)calc).Close(); service.Close();
Erlang Highlights: High-level Constructs Parsing an IP Datagram using the Bit Syntax -define(IP_VERSION, 4). -define(IP_MIN_HDR_LEN, 5). ……DgramSize = size(Dgram), <<?IP_VERSION:4, HLen:4, SrvcType:8, TotLen:16, ID:16, Flgs:3, FragOff:13, TTL:8, Proto:8, HdrChkSum:16, SrcIP:32, DestIP:32, Body/binary>> = Dgram, if (HLen >= 5) and (4*HLen =< DgramSize) -> OptsLen = 4*(HLen - ?IP_MIN_HDR_LEN), <<Opts:OptsLen/binary, Data/binary>> = Body, ….. end.