ekbpy'2012 - Антон Патрушев - ZeroMQ
Transcript of ekbpy'2012 - Антон Патрушев - ZeroMQ
: Intro
Антон Патрушев
ZeroMQ: WTF ?
● high-performance● asynchronous● messaging library
● provides a message queue● ... but can run without a dedicated message broker
● behaves like a sockets● ... like an awesome sockets
● programming language neutral (many bindings)● protocol agnostic
Категории в wikipedia
● Concurrent programming libraries● Inter-process communication● Message-oriented middleware
"The socket library that acts as a concurrency framework."(c) zeromq.org
История iMatix
2004 – AMQP standard for JPMorganChase
2005 – OpenAMQ message broker/client
2008 – ØMQ/0.x for the avant-garde
2009 – ØMQ/1.x for pioneers (finance)
2010 – ØMQ/2.x for early adopters (foss) (аргументированный) отказ iMatix от поддержки AMQP
2011 – ØMQ/3.x for mass market (cloud)
Давайте знакомиться
● простой socket-like API○ zmq_bind/zmq_connect/zmq_close○ zmq_poll○ zmq_recv/zmq_send
● передача __сообщений__○ атомарность○ multipart○ any payload (ProtoBuf / XDR / JSON ...)
Клиент
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect ("tcp://localhost:5555")
for request in range (1,10):print "Sending request ", request, "…"
socket.send ("Hello")
message = socket.recv()print "Received reply ", request, "[", message, "]"
Сервер
import zmq
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind ("tcp://localhost:5555")
while True:
message = socket.recv()
print "Received request, sending reply"
socket.send ("World")
Доставка сообщений
● протоколы○ inproc○ ipc○ tcp○ epgm (!!!)
● набор паттернов маршрутизации○ REQUEST/REPLY (task distribution)○ PUBLISH/SUBSCRIBE (data distribution)○ PUSH/PULL (task distribution/collection)
Request/Reply
f
Publisher/Subscriber
f
Pipeline
f
Mongrel2
● Request -> PUSH (LB)● Response -> PUB● Pipelining
State replication
а
Devices (1)
f
Devices (2)
f
Forwarder
f
Request-Reply Broker (1)
f
Request-Reply Broker (2)
f
Devices (последний, инфа 146%)
● встроенные○ QUEUE - request/reply broker○ FORWARDER - pub-sub proxy○ STREAMER - forwarder for pipelines
● ваши собственные○ соединяем backend и frontend сокеты○ реализуем собственную логику маршратизации○ выстраиваем топологию приложения
А был ли мальчик ? (про аналоги)
● Berkeley sockets (transport dependent)
● Sun RPC● DCOM● Corba● XML-RPC -> SOAP● JMS● ZeroC Ice● Java RMI● Thrift
License
"ØMQ is available under the LGPLv3 with a static linking exception including for iPhone apps. We do not offer a commercial license alternative."
(c) zeromq.org
ØMQ is 100% owned by the communityWhich iMatix is a happy part of
What's next ?
"0MQ is unbelievably cool - if you haven't got a project that needs it, make on up"
Jon Gifford - Loggly
What's next (again) ?
● www.imatix.com/articles:whats-wrong-with-amqp
● zguide.zeromq.org
● rfc.zeromq.org
● api.zeromq.org
● bhavin.directi.com/selecting-a-message-queue-amqp-or-zeromq/
●
Вопросы ?
Этот доклад о самой технологиий, истории и предпосылках ее возникновения, текущем состоянии и вариантах применения, преимуществах, недостатках и альтернативах
в случае гетерогенной, многокомпонентной среды встает вопрос выноса некоторых компонент в отдельные процессы
в erlang есть хорошая парадигма Let it dieReliable multicast (best for pub/sub) !!!