Top Banner
Normation – CC-BY-SA normation.com 1 Scala and ZeroMQ Events beyond the JVM Scala and ZeroMQ Events beyond the JVM François ARMAND Directeur R&D - Normation [email protected]
22

Scala and ZeroMQ: Events beyond the JVM

Sep 01, 2014

Download

Technology

Normation

Some slides demonstrating what ZeroMQ is and how it can be used from Scala, with the native Scala-ZeroMQ binding or the Akka-zeromq module.
Acually, code examples are on a GitHub repository here: https://github.com/fanf/scala_zeromq.

The presentation was given on 2013-08-21 at the Paris Scala User Group.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 1

Scala and ZeroMQ Events beyond the JVM

Scala and ZeroMQ Events beyond the JVM

François ARMANDDirecteur R&D - [email protected]

Page 2: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 2

Qui suis-je ?

Scalaist since...

● mid-2006 for personnal projects

● Rudder : full time Scala since mid-2009

● Projet LaFoSec : sécurité des langages fonctionnels (in French)

– Scala from the point of view of IT security

– 2010 paper for the Agence Nationnal de la Sécurité de SI (ANSSI)

– http://www.ssi.gouv.fr/fr/anssi/publications/publications-scientifiques/autres-publications/lafosec-securite-et-langages-fonctionnels.html

Co-founderLead-architect

[email protected] @fanf42

François ARMAND

Page 3: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 3

De quoi va-t-on parler ?

● ZeroMQ presentation

● Integration with Scala

● Code, code, code, code...

Page 4: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 4

Scala and ZeroMQ Events beyond the JVM

ZeroMQ : Ounce upon a time,

the quest for the GrailMOM

François ARMANDDirecteur R&D - [email protected]

Page 5: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 5

MOM : Grail of IT integration

● Message Oriented Middleware (and Architecture)

● Grails of IT integration

Page 6: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 6

ZeroMQ : history and presentation

● In the '90s, messaging middlewares :

● Banks / trading places:

● Need for hight speed Events interchange queues

● 2003 : Advanced Message Queuing Protocol

« Toward a commodity (message oriented) middleware »

– Message orientation

– Queuing

– Routing (including point-to-point and publish-and-subscribe),

– Reliability

– Security.

Page 7: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 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'vedecided to end that. We're going to be killing support for OpenAMQand migrating our users to ZeroMQ, which is simpler, faster, and inour view a better bet for our users.We have serious, long lived, and unaddressed concerns with the AMQPdevelopment process and today our worst predictions seem to have cometrue: AMQP is a game for large firms, and ignores the needs of themajority of users and vendors. For us, that means failure.

● 2012: iMatix, iniator of the ZeroMQ project and starts Crossroads.io

● But it's dead because...

● 2013: Martin Sustrik, original author of ZeroMQ and Crossroads.io, leaves to build Nano...

Page 8: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 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'vedecided to end that. We're going to be killing support for OpenAMQand migrating our users to ZeroMQ, which is simpler, faster, and inour view a better bet for our users.We have serious, long lived, and unaddressed concerns with the AMQPdevelopment process and today our worst predictions seem to have cometrue: AMQP is a game for large firms, and ignores the needs of themajority of users and vendors. For us, that means failure.

● 2012 : iMatix, iniator of the ZeroMQ project and starts crossroads.io

● But that dead because...

● 2013 : Martin Sustrik, original author of ZeroMQ and Crossroads.io, leaves to build Nano...

Page 9: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 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/

Page 10: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 10

Scala and ZeroMQ Events beyond the JVM

Sockets for this millenium

François ARMANDDirecteur R&D - [email protected]

Page 11: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 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

– Connects two sockets exclusively.

– This is a pattern for connecting two threads in a process

– Not to be confused with "normal" pairs of sockets.

Page 12: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 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

– Connects two sockets exclusively.

– This is a pattern for connecting two threads in a process

– Not to be confused with "normal" pairs of sockets.

Page 13: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 13

Scala and ZeroMQ Events beyond the JVM

Scala and ZeroMQ

François ARMANDDirecteur R&D - [email protected]

Page 14: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 14

Scala and ZeroMQ

● C-Scala native binding

● http://zeromq.org/bindings:scala-binding

● Uses JNA

● Only supports libzmq v2.1

● Akka integration

● Akka-zeromq module

● http://doc.akka.io/docs/akka/2.2.0/scala/zeromq.html

● Documentation and example are sparses

Page 15: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 15

Scala and ZeroMQ - remarks

● I'm still believing AKKA is Scala killer-app

● It went a looooooooooooooooooong way since my last try 3 years ago

● I'm believing ZeroMQ will be in all IT infrastructures soon

● I'm still HATING AKKA untyped model

● Next time, I'm going to try Typed Actor / Channel

Page 16: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 16

Scala and ZeroMQ Events beyond the JVM

Pub/Sub. Young people these days

have got it easy

François ARMANDDirecteur R&D - [email protected]

Page 17: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 17

ZeroMQ sockets : Pub / Sub

● Publish / Subscribes sockets

● It's just work, nothing to add

Page 18: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 18

ZeroMQ sockets : Pub / Sub

Code !

https://github.com/fanf/scala_zeromq/tree/master/src/main/scala/psug/zeromq/pubsub

Page 19: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 19

Scala and ZeroMQ Events beyond the JVM

Req/Rep. Because waiting for answer

is hard.

François ARMANDDirecteur R&D - [email protected]

Page 20: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 20

ZeroMQ sockets : Req / Rep

● Request / Reply sockets

● Statefull request ↔ reply cycles

Page 21: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 21

ZeroMQ sockets : Req / Rep

Code !

https://github.com/fanf/scala_zeromq/tree/master/src/main/scala/psug/zeromq/reqrep

Page 22: Scala and ZeroMQ: Events beyond the JVM

Normation – CC-BY-SAnormation.com 22

Scala and ZeroMQ Events beyond the JVM

Questions ?

François ARMANDDirecteur R&D - [email protected]