Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Scala.io 2013 - Scala and ZeroMQ: Events beyond the JVM

4,671 views

Published on

After a short presentation of Message Oriented Middleware history and the birth of ZeroMQ in reaction to AMQP drift, these slides show how ZeroMQ and Scala can be used, either with a direct binding or trought an Akka layer, to make events propagate beyound the boundaries of a JVM system.
The final example

Published in: Technology, Education

Scala.io 2013 - Scala and ZeroMQ: Events beyond the JVM

  1. 1. 2013-10-{24,25} Scala and ZeroMQ  Events beyond the JVM François ARMAND Directeur R&D - Normation far@normation.com
  2. 2. Speaker François @fanf42 ARMAND far@normation.com Lead-dev Co-founder Scala since... (for personal projects) PSUG !!! Projet LaFoSec Sécurité des langages fonctionnels (Scala from the point of view of IT security) French paper for the Agence Nationnal de la Sécurité de SI (ANSSI) 2
  3. 3. What's next ? ▣ ▣ Integration with Scala ▣ 3 ZeroMQ presentation Code, code, code, code...
  4. 4. 2013-10-{24,25} ZeroMQ : Ounce upon a time, the quest for the GrailMOM
  5. 5. MOM : Grail of IT integration ▣ Message Oriented Middleware (and Architecture) ■ 5 Grails of IT integration
  6. 6. ZeroMQ : history and presentation ▣ In the '90s, messaging middlewares : ▣ Banks / trading places: ■ Need for hight speed Events interchange queues and EAI ■ 2003 : Advanced Message Queuing Protocol « Toward a commodity (message oriented) middleware » □ □ Queuing □ Routing (including point-to-point and publish-and-subscribe), □ Reliability □ 6 Message orientation Security.
  7. 7. From AMQP to Nano ▣ AMQP version 1.0 : October 2011 (!!!) ▣ AMQP : Oasis Standard : October 2012 ■ ▣ RabbitMQ still refuses to implements v1.0 2004: iMatix, initiator of the project resigned and starts ZeroMQ Hi Folks, Here at iMatix we've participated since 2004 in AMQP but today we've decided to end that. We're going to be killing support for OpenAMQ and migrating our users to ZeroMQ, which is simpler, faster, and in our view a better bet for our users. We have serious, long lived, and unaddressed concerns with the AMQP development process and today our worst predictions seem to have come true: AMQP is a game for large firms, and ignores the needs of the majority of users and vendors. For us, that means failure. ▣ 2012: iMatix, founder of the ZeroMQ project and starts Crossroads.io ■ ▣ 7 But it's dead because... 2013: Martin Sustrik, original author of ZeroMQ and Crossroads.io, leaves to build Nano...
  8. 8. From AMQP to Nano ▣ AMQP version 1.0 : October 2011 (!!!) ▣ AMQP : Oasis Standard : October 2012 ■ ▣ RabbitMQ still refuses to implements v1.0 2004: iMatix, initiator of the project resigned and starts ZeroMQ Hi Folks, Here at iMatix we've participated since 2004 in AMQP but today we've decided to end that. We're going to be killing support for OpenAMQ and migrating our users to ZeroMQ, which is simpler, faster, and in our view a better bet for our users. We have serious, long lived, and unaddressed concerns with the AMQP development process and today our worst predictions seem to have come true: AMQP is a game for large firms, and ignores the needs of the majority of users and vendors. For us, that means failure. ▣ 2012: iMatix, founder of the ZeroMQ project and starts Crossroads.io ■ ▣ 8 But it's dead because... 2013: Martin Sustrik, original author of ZeroMQ and Crossroads.io, leaves to build Nano...
  9. 9. ZeroMQ Ø Not a MOM (no broker, no queues, etc)  Ø Socket library that acts as a concurrency framework. Ø Carries messages across inproc, IPC, TCP, and multicast. Ø Connect N-to-N via fanout, pubsub, pipeline, request-reply. Ø Asynch I/O for scalable multicore message-passing apps. Ø 40+ languages including C, C++, Java, .NET, Python. Ø http://zguide.zeromq.org/ 9
  10. 10. 2013-10-{24,25} Sockets for this millenium
  11. 11. ZeroMQ sockets ▣ « It's sockets on steroids. It's like mailboxes with routing. It's fast! » ▣ ZeroMQ patterns (and sockets) : ■ Request-Reply □ □ ■ Connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern. Pub-Sub □ □ ■ Connects a set of publishers to a set of subscribers. This is a data distribution pattern. Pipelines □ □ ■ Connects nodes in a fan-out/fan-in pattern that can have multiple steps and loops. This is a parallel task distribution and collection pattern. Exclusive pair □ □ This is a pattern for connecting two threads in a process □ 11 Connects two sockets exclusively. Not to be confused with "normal" pairs of sockets.
  12. 12. ZeroMQ sockets ▣ « It's sockets on steroids. It's like mailboxes with routing. It's fast! » ▣ ZeroMQ patterns (and sockets) : ■ Request-Reply □ □ ■ Connects a set of clients to a set of services. This is a remote procedure call and task distribution pattern. Pub-Sub □ □ ■ Connects a set of publishers to a set of subscribers. This is a data distribution pattern. Pipelines □ □ ■ Connects nodes in a fan-out/fan-in pattern that can have multiple steps and loops. This is a parallel task distribution and collection pattern. Exclusive pair □ □ This is a pattern for connecting two threads in a process □ 12 Connects two sockets exclusively. Not to be confused with "normal" pairs of sockets.
  13. 13. 2013-10-{24,25} Scala and ZeroMQ
  14. 14. Scala and ZeroMQ ▣ C-Scala native binding ■ ■ Uses JNA ■ ▣ http://zeromq.org/bindings:scala-binding Only supports libzmq v2.1 Akka integration ■ ■ http://doc.akka.io/docs/akka/2.2.0/scala/zeromq.html ■ 14 Akka-zeromq module Documentation and examples are sparse
  15. 15. Scala and ZeroMQ - remarks ▣ I'm still believing AKKA is Scala killer-app ■ ■ ▣ ▣ (if such a thing exists / is needed) It went a looooooooong way since my last try 3 years ago I'm believing ZeroMQ (or a successor) will be in all IT infrastructures soon I'm still HATING AKKA untyped model ■ ■ Next time, I'm going to try Typed Actor / Channel ■ 15 I want to be able to define SYSTEMS with BOUNDARIES Or perhaps Clojure core.typed + core.async
  16. 16. 2013-10-{24,25} Pub/Sub. Young people these days have got it easy
  17. 17. ZeroMQ sockets : Pub / Sub ▣ Publish / Subscribes sockets ■ 17 It's just work, nothing to add
  18. 18. Raw Pub/Sub code 18
  19. 19. Raw Pub/Sub code 19
  20. 20. AKKA Pub/Sub Scala (Server) ZMQ Socket Actor ZMQ Socket Actor Client (Akka) 20
  21. 21. AKKA Pub/Sub code 21
  22. 22. AKKA Pub/Sub code 22
  23. 23. 2013-10-{24,25} Req/Rep Because waiting for answer is hard.
  24. 24. ZeroMQ sockets : Req / Rep ▣ Request / Reply sockets ■ 24 Statefull request ↔ reply cycles
  25. 25. Raw Req / Rep code 25
  26. 26. Raw Req / Rep code 26
  27. 27. Ask pattern with ZeroMQ AKKA "ASK" Pattern build on top of ZeroMQ ■ Integrate non-JVM elements in your AKKA system 8/ Answer Actor ZmqClient Actor MessageCollector 1/ ASK 4/ Server get message Server 2/ Send message to ZMQ socket ZMQ Socket Actor (Req) 3/ Get query by ZMQ socket ZMQ Socket (Rep) 5/ Server response 27 7/ Get response by ZMQ socket Outside the JVM Into the wild ▣ 6/ Send response to ZMQ socket
  28. 28. Ask pattern with ZeroMQ 1 28 8
  29. 29. Ask pattern with ZeroMQ 4 5 29
  30. 30. Ask pattern with ZeroMQ 1 2 7 8 30
  31. 31. 2013-10-{24,25} Questions ?

×