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
 
Yg byev2e
Yg byev2eYg byev2e
Yg byev2e
longphi2812
 
C99.php
C99.phpC99.php
C99.php
veng33k
 
Debugging: Rules & Tools
Debugging: Rules & ToolsDebugging: Rules & Tools
Debugging: Rules & Tools
Ian Barber
 
Yy
YyYy
Yy
yygh
 
Nouveau document texte
Nouveau document texteNouveau document texte
Nouveau document texte
Sai Ef
 
C99[2]
C99[2]C99[2]
C99[2]
guest8914af
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
Flavio Poletti
 
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
 
C99
C99C99
C99
sifo12
 
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 no39
Jay Patel
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
Yasuharu 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 Tokyo
Masahiro Nagano
 
Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
Thomas 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 2013
Srinivasan 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 Clojure
Dmitry 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 scala
lunfu 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.io
Rick 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
 
Npc14
Npc14Npc14
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
Eleanor McHugh
 
Ssaw08 0624
Ssaw08 0624Ssaw08 0624
Ssaw08 0624
Atsushi Tadokoro
 
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
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
Hidekazu Tanaka
 
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

[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
saastr
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 

Recently uploaded (20)

[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
9 CEO's who hit $100m ARR Share Their Top Growth Tactics Nathan Latka, Founde...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 

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!