SlideShare a Scribd company logo
messaging
made simple
Ian Barber
http://phpir.com - http://zero.mq/ib
ianb@php.net - @ianbarber
“0MQ is
unbelievably cool
– if you haven’t
got a project that
needs it, make
one up”
jon gifford - loggly
queue        esb


pipeline    async



pub/sub    gateway
request/response
run() ->                       erlrep.erl
 {ok, Ctx} = erlzmq:context(),
 {ok, Sock} = erlzmq:socket(Ctx, rep),
 ok = erlzmq:bind(Sock,"tcp://*:5454"),
 loop(Sock).

loop(Sock) ->
 {ok, Msg, _F} = erlzmq:recv(Sock),
 Rep = binary_to_list(Msg) ++ " World",
 io:format("Sending ~s~n", [Rep]),
 ok = erlzmq:send(Sock,
              list_to_binary(Rep)),
 loop(Sock).
import zmq                   rep.py
context = zmq.Context()
server = context.socket(zmq.REP)
server.bind("tcp://*:5454")

while True:
    message = server.recv()
    print "Sending", message, "Worldn"
    server.send(message + " World")
request/response

$ctx = new ZMQContext();      req.php
$req =
  new ZMQSocket($ctx, ZMQ::SOCKET_REQ);
$req->connect("tcp://localhost:5454");

$req->send("Hello");
echo $req->recv();
git clone http://github.com/zeromq/erlzmq2.git

make
make test



   http://download.zeromq.org/
   http://github.com/zeromq/zeromq2-1
   http://github.com/zeromq/libzmq
atomic   bytes   multipart



messaging
Post Office Image: http://www.flickr.com/photos/10804218@N00/4315282973
        Post Box Image: http://www.flickr.com/photos/kenjonbro/3027166169
queue
queue
run() ->
 {ok, Ctx} = erlzmq:context(),
 {ok, Front} = erlzmq:socket(Ctx,
                 [xrep, {active,true}]),
 {ok, Back} = erlzmq:socket(Ctx,
                 [xreq, {active,true}]),
 ok = erlzmq:bind(Front, "tcp://*:5454"),
 ok = erlzmq:bind(Back, "tcp://*:5455"),

loop(Front, Back),
ok = erlzmq:close(Front),
ok = erlzmq:close(Back),
                                  que ue.erl
ok = erlzmq:term(Ctx).
loop(Front, Back) ->
 receive
  {zmq, Front, Msg, Flags} ->
    io:format("Sending Back: ~p~n",[Msg]),
    sendall(Back, Msg, Flags),
    loop(Front, Back);
  {zmq, Back, Msg, Flags} ->
    io:format("Sending Front: ~p~n",[Msg]),
    sendall(Front, Msg, Flags),
    loop(Front, Back)
 end.

sendall(To, Part,   [rcvmore|_Flags]) ->
  erlzmq:send(To,   Part, [sndmore]);
sendall(To, Part,   _Flags) ->
  erlzmq:send(To,   Part).
stable / unstable




  Image: http://www.flickr.com/photos/pelican/235461339/
pipeline
logging
processes




                local log
               ag gregators



  log writer
pipeline
<?php                          logger.php
$ctx = new ZMQContext();
$out = $ctx->getSocket(ZMQ::SOCKET_PUSH);
$out->connect("ipc:///tmp/logger");
$msg = array("time" => time());
$msg['msg'] = $_SERVER['argv'][1];
$out->send(json_encode($msg));
loglocal.py
import zmq; bufSz = 3; msgs = []
ctx = zmq.Context()
inp = ctx.socket(zmq.PULL)
out = ctx.socket(zmq.PUSH)
inp.bind("ipc:///tmp/logger")
out.connect("tcp://localhost:5555")

while True:
 msgs.append(inp.recv())
 print "Received Log"
 if(len(msgs) == bufSz):
   print "Forwarding Buffer"
   for i, msg in enumerate(msgs):
    out.send( msg,
              (0,zmq.SNDMORE)[i< bufSz-1])
    msgs = []
logserv.erl
run() ->
 {ok, Ctx} = erlzmq:context(),
 {ok, In} = erlzmq:socket(Ctx,
                   [pull, {active,true}]),
 ok = erlzmq:bind(In, "tcp://*:5555"),
 loop(In).

loop(In) ->
 receive
  {zmq, In, Msg, _F} ->
  {ok,{obj, [{_, Time}, {_, Log}] }, [] }
   = rfc4627:decode(Msg),
  io:format("~B ~s~n", [Time, Log]),
  loop(In)
 end.
pub/sub




  Image: http://www.flickr.com/photos/nikonvscanon/4519133003/
pub/sub
pub/sub
                              repeater.e
                                        rl
init(_) ->
  spawn_link(?MODULE, run, []).

terminate(Pid) ->
  Pid ! {cmd, kill}.

handle_event(Event, Pid) ->
  Pid ! Event.
run() ->
  {ok, Ctx} = erlzmq:context(),
  {ok, Sock} = erlzmq:socket(Ctx, [pub]),
  ok = erlzmq:bind(Sock, "tcp://*:5656"),
  loop(Sock).

loop(Sock) ->
  receive
    {cmd, kill} ->
      ok;
    {Action, Id, Event} ->
      Json = rfc4627:encode({obj,
              [{action, Action},
               {id, Id}, {event, Event}]}),
      erlzmq:send(Sock,
                     list_to_binary(Json)),
      loop(Sock)
  end.
types of transport

     inproc         ipc




   tcp        pgm
distro   sub   web
client
                   sub   web
         sub

event
         sub       sub   web
 pub

          distro   sub   web
client
         sub       db
import zmq
from zmq.devices.basedevice
     import ProcessDevice

pd = ProcessDevice(zmq.STREAMER,
                   zmq.PULL, zmq.PUB)
pd.bind_in("tcp://*:6767")
pd.connect_out("epgm://eth0;239.192.0.1:7601")
pd.setsockopt_out(zmq.RATE, 10000)
pd.start()

# Do other things here


                         eventhub.php
int main(void) {
  void *ctx = zmq_init(1);
  void *in = zmq_socket(ctx, ZMQ_SUB);
  void *out = zmq_socket(ctx, ZMQ_PUB);
  zmq_setsockopt(in, ZMQ_SUBSCRIBE, "", 0);
  int rcin = zmq_connect(in,
              "epgm://;239.192.0.1:7601");
  int rcout = zmq_bind(out,
              "ipc:///tmp/events");
  int rcd =   zmq_device(ZMQ_FORWARDER,
              in, out);

    zmq_close(in); zmq_close(out);
    zmq_term(ctx);
    return 0;
}                             distro.c
$ctx = new ZMQContext();
$in = $ctx->getSocket(ZMQ::SOCKET_SUB);
for($i = 0; $i<100; $i++) {
   $in->setSockOpt(
           ZMQ::SOCKOPT_SUBSCRIBE,
           rand(100000, 999999));
}
$in->connect("ipc:///tmp/events");
$i = 0;
while($i++ < 1000) {
  $who = $in->recv();
  $msg = $in->recv();
  printf("%s %s %s", $who, $msg, PHP_EOL);
}
                                cli ent.php
amqp /= ømq



http://zero.mq/amqp
[{r0mq,
  [{services,
    [
{<<"PIPELINE">>, pull, "tcp://127.0.0.1:5557"},
{<<"PIPELINE">>, push, "tcp://127.0.0.1:5558"},
{<<"PUBSUB">>, pub, "tcp://127.0.0.1:5555"},
{<<"PUBSUB">>, sub, "tcp://127.0.0.1:5556"}
     ]
  }]
}].

                          rabbitmq.config
Helpful Links
http://zero.mq
        Ian Barber
http://zguide.zero.mq
        http://phpir.com
http://zero.mq/ib
        ian.barber@gmail.com @ianbarber




      thanks!

More Related Content

What's hot

The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
Wim Godden
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
vanphp
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
Steve Rhoades
 
C99.php
C99.phpC99.php
C99.php
veng33k
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
Ian Barber
 
Yy
YyYy
Yyyygh
 
Nouveau document texte
Nouveau document texteNouveau document texte
Nouveau document texteSai Ef
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
✅ William Pinaud
 
Any event intro
Any event introAny event intro
Any event intro
qiang
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
Wim Godden
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHPThomas Weinert
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
Nova Patch
 

What's hot (19)

The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
React PHP: the NodeJS challenger
React PHP: the NodeJS challengerReact PHP: the NodeJS challenger
React PHP: the NodeJS challenger
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
 
C99.php
C99.phpC99.php
C99.php
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
 
Yy
YyYy
Yy
 
Nouveau document texte
Nouveau document texteNouveau document texte
Nouveau document texte
 
C99[2]
C99[2]C99[2]
C99[2]
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
C99
C99C99
C99
 
Any event intro
Any event introAny event intro
Any event intro
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
 
Modern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in PerlModern Getopt for Command Line Processing in Perl
Modern Getopt for Command Line Processing in Perl
 

Similar to ZeroMQ: Messaging Made Simple

Zeromq - Pycon India 2013
Zeromq - Pycon India 2013Zeromq - Pycon India 2013
Zeromq - Pycon India 2013Srinivasan R
 
Python queue solution with asyncio and kafka
Python queue solution with asyncio and kafkaPython queue solution with asyncio and kafka
Python queue solution with asyncio and kafka
Ondřej Veselý
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
Saúl Ibarra Corretgé
 
Lego: A brick system build by scala
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scalalunfu zhong
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
matuura_core
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioRick Copeland
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
명신 김
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()
Kiwamu Okabe
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
Eleanor McHugh
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
Guilherme Garnier
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
Dongmin Yu
 
Distributed Computing Patterns in R
Distributed Computing Patterns in RDistributed Computing Patterns in R
Distributed Computing Patterns in R
armstrtw
 
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando CoroutinesTDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
tdc-globalcode
 
Introduction to asyncio
Introduction to asyncioIntroduction to asyncio
Introduction to asyncio
Saúl Ibarra Corretgé
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
Frank Lyaruu
 

Similar to ZeroMQ: Messaging Made Simple (20)

Zeromq - Pycon India 2013
Zeromq - Pycon India 2013Zeromq - Pycon India 2013
Zeromq - Pycon India 2013
 
Python queue solution with asyncio and kafka
Python queue solution with asyncio and kafkaPython queue solution with asyncio and kafka
Python queue solution with asyncio and kafka
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
A deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio moduleA deep dive into PEP-3156 and the new asyncio module
A deep dive into PEP-3156 and the new asyncio module
 
Lego: A brick system build by scala
Lego: A brick system build by scalaLego: A brick system build by scala
Lego: A brick system build by scala
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()start_printf: dev/ic/com.c comstart()
start_printf: dev/ic/com.c comstart()
 
Npc14
Npc14Npc14
Npc14
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
Ssaw08 0624
Ssaw08 0624Ssaw08 0624
Ssaw08 0624
 
Goroutines and Channels in practice
Goroutines and Channels in practiceGoroutines and Channels in practice
Goroutines and Channels in practice
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
Distributed Computing Patterns in R
Distributed Computing Patterns in RDistributed Computing Patterns in R
Distributed Computing Patterns in R
 
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando CoroutinesTDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
TDC2018SP | Trilha Kotlin - Programacao assincrona utilizando Coroutines
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Introduction to asyncio
Introduction to asyncioIntroduction to asyncio
Introduction to asyncio
 
Non Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJavaNon Blocking I/O for Everyone with RxJava
Non Blocking I/O for Everyone with RxJava
 

More from Ian Barber

Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
Ian Barber
 
In Search Of: Integrating Site Search (PHP Barcelona)
In Search Of: Integrating Site Search (PHP Barcelona)In Search Of: Integrating Site Search (PHP Barcelona)
In Search Of: Integrating Site Search (PHP Barcelona)
Ian Barber
 
In Search Of... (Dutch PHP Conference 2010)
In Search Of... (Dutch PHP Conference 2010)In Search Of... (Dutch PHP Conference 2010)
In Search Of... (Dutch PHP Conference 2010)
Ian Barber
 
In Search Of... integrating site search
In Search Of... integrating site search In Search Of... integrating site search
In Search Of... integrating site search
Ian Barber
 
Document Classification In PHP - Slight Return
Document Classification In PHP - Slight ReturnDocument Classification In PHP - Slight Return
Document Classification In PHP - Slight Return
Ian Barber
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHP
Ian Barber
 

More from Ian Barber (6)

Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
In Search Of: Integrating Site Search (PHP Barcelona)
In Search Of: Integrating Site Search (PHP Barcelona)In Search Of: Integrating Site Search (PHP Barcelona)
In Search Of: Integrating Site Search (PHP Barcelona)
 
In Search Of... (Dutch PHP Conference 2010)
In Search Of... (Dutch PHP Conference 2010)In Search Of... (Dutch PHP Conference 2010)
In Search Of... (Dutch PHP Conference 2010)
 
In Search Of... integrating site search
In Search Of... integrating site search In Search Of... integrating site search
In Search Of... integrating site search
 
Document Classification In PHP - Slight Return
Document Classification In PHP - Slight ReturnDocument Classification In PHP - Slight Return
Document Classification In PHP - Slight Return
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHP
 

Recently uploaded

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 

Recently uploaded (20)

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 

ZeroMQ: Messaging Made Simple

  • 1. messaging made simple Ian Barber http://phpir.com - http://zero.mq/ib ianb@php.net - @ianbarber
  • 2. “0MQ is unbelievably cool – if you haven’t got a project that needs it, make one up” jon gifford - loggly
  • 3.
  • 4.
  • 5.
  • 6. queue esb pipeline async pub/sub gateway
  • 7. request/response run() -> erlrep.erl {ok, Ctx} = erlzmq:context(), {ok, Sock} = erlzmq:socket(Ctx, rep), ok = erlzmq:bind(Sock,"tcp://*:5454"), loop(Sock). loop(Sock) -> {ok, Msg, _F} = erlzmq:recv(Sock), Rep = binary_to_list(Msg) ++ " World", io:format("Sending ~s~n", [Rep]), ok = erlzmq:send(Sock, list_to_binary(Rep)), loop(Sock).
  • 8. import zmq rep.py context = zmq.Context() server = context.socket(zmq.REP) server.bind("tcp://*:5454") while True: message = server.recv() print "Sending", message, "Worldn" server.send(message + " World")
  • 9. request/response $ctx = new ZMQContext(); req.php $req = new ZMQSocket($ctx, ZMQ::SOCKET_REQ); $req->connect("tcp://localhost:5454"); $req->send("Hello"); echo $req->recv();
  • 10.
  • 11. git clone http://github.com/zeromq/erlzmq2.git make make test http://download.zeromq.org/ http://github.com/zeromq/zeromq2-1 http://github.com/zeromq/libzmq
  • 12. atomic bytes multipart messaging
  • 13. Post Office Image: http://www.flickr.com/photos/10804218@N00/4315282973 Post Box Image: http://www.flickr.com/photos/kenjonbro/3027166169
  • 14. queue
  • 15. queue run() -> {ok, Ctx} = erlzmq:context(), {ok, Front} = erlzmq:socket(Ctx, [xrep, {active,true}]), {ok, Back} = erlzmq:socket(Ctx, [xreq, {active,true}]), ok = erlzmq:bind(Front, "tcp://*:5454"), ok = erlzmq:bind(Back, "tcp://*:5455"), loop(Front, Back), ok = erlzmq:close(Front), ok = erlzmq:close(Back), que ue.erl ok = erlzmq:term(Ctx).
  • 16. loop(Front, Back) -> receive {zmq, Front, Msg, Flags} -> io:format("Sending Back: ~p~n",[Msg]), sendall(Back, Msg, Flags), loop(Front, Back); {zmq, Back, Msg, Flags} -> io:format("Sending Front: ~p~n",[Msg]), sendall(Front, Msg, Flags), loop(Front, Back) end. sendall(To, Part, [rcvmore|_Flags]) -> erlzmq:send(To, Part, [sndmore]); sendall(To, Part, _Flags) -> erlzmq:send(To, Part).
  • 17. stable / unstable Image: http://www.flickr.com/photos/pelican/235461339/
  • 19. logging processes local log ag gregators log writer
  • 20. pipeline <?php logger.php $ctx = new ZMQContext(); $out = $ctx->getSocket(ZMQ::SOCKET_PUSH); $out->connect("ipc:///tmp/logger"); $msg = array("time" => time()); $msg['msg'] = $_SERVER['argv'][1]; $out->send(json_encode($msg));
  • 21. loglocal.py import zmq; bufSz = 3; msgs = [] ctx = zmq.Context() inp = ctx.socket(zmq.PULL) out = ctx.socket(zmq.PUSH) inp.bind("ipc:///tmp/logger") out.connect("tcp://localhost:5555") while True: msgs.append(inp.recv()) print "Received Log" if(len(msgs) == bufSz): print "Forwarding Buffer" for i, msg in enumerate(msgs): out.send( msg, (0,zmq.SNDMORE)[i< bufSz-1]) msgs = []
  • 22. logserv.erl run() -> {ok, Ctx} = erlzmq:context(), {ok, In} = erlzmq:socket(Ctx, [pull, {active,true}]), ok = erlzmq:bind(In, "tcp://*:5555"), loop(In). loop(In) -> receive {zmq, In, Msg, _F} -> {ok,{obj, [{_, Time}, {_, Log}] }, [] } = rfc4627:decode(Msg), io:format("~B ~s~n", [Time, Log]), loop(In) end.
  • 23.
  • 24. pub/sub Image: http://www.flickr.com/photos/nikonvscanon/4519133003/
  • 26. pub/sub repeater.e rl init(_) -> spawn_link(?MODULE, run, []). terminate(Pid) -> Pid ! {cmd, kill}. handle_event(Event, Pid) -> Pid ! Event.
  • 27. run() -> {ok, Ctx} = erlzmq:context(), {ok, Sock} = erlzmq:socket(Ctx, [pub]), ok = erlzmq:bind(Sock, "tcp://*:5656"), loop(Sock). loop(Sock) -> receive {cmd, kill} -> ok; {Action, Id, Event} -> Json = rfc4627:encode({obj, [{action, Action}, {id, Id}, {event, Event}]}), erlzmq:send(Sock, list_to_binary(Json)), loop(Sock) end.
  • 28. types of transport inproc ipc tcp pgm
  • 29.
  • 30. distro sub web client sub web sub event sub sub web pub distro sub web client sub db
  • 31. import zmq from zmq.devices.basedevice import ProcessDevice pd = ProcessDevice(zmq.STREAMER, zmq.PULL, zmq.PUB) pd.bind_in("tcp://*:6767") pd.connect_out("epgm://eth0;239.192.0.1:7601") pd.setsockopt_out(zmq.RATE, 10000) pd.start() # Do other things here eventhub.php
  • 32. int main(void) { void *ctx = zmq_init(1); void *in = zmq_socket(ctx, ZMQ_SUB); void *out = zmq_socket(ctx, ZMQ_PUB); zmq_setsockopt(in, ZMQ_SUBSCRIBE, "", 0); int rcin = zmq_connect(in, "epgm://;239.192.0.1:7601"); int rcout = zmq_bind(out, "ipc:///tmp/events"); int rcd = zmq_device(ZMQ_FORWARDER, in, out); zmq_close(in); zmq_close(out); zmq_term(ctx); return 0; } distro.c
  • 33. $ctx = new ZMQContext(); $in = $ctx->getSocket(ZMQ::SOCKET_SUB); for($i = 0; $i<100; $i++) { $in->setSockOpt( ZMQ::SOCKOPT_SUBSCRIBE, rand(100000, 999999)); } $in->connect("ipc:///tmp/events"); $i = 0; while($i++ < 1000) { $who = $in->recv(); $msg = $in->recv(); printf("%s %s %s", $who, $msg, PHP_EOL); } cli ent.php
  • 35. [{r0mq,   [{services,     [ {<<"PIPELINE">>, pull, "tcp://127.0.0.1:5557"}, {<<"PIPELINE">>, push, "tcp://127.0.0.1:5558"}, {<<"PUBSUB">>, pub, "tcp://127.0.0.1:5555"}, {<<"PUBSUB">>, sub, "tcp://127.0.0.1:5556"} ] }] }]. rabbitmq.config
  • 36. Helpful Links http://zero.mq Ian Barber http://zguide.zero.mq http://phpir.com http://zero.mq/ib ian.barber@gmail.com @ianbarber thanks!