Top Banner
a practical introduction
61
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: øMQ Vortrag

a practical introduction

Page 2: øMQ Vortrag
Page 3: øMQ Vortrag
Page 4: øMQ Vortrag
Page 5: øMQ Vortrag
Page 6: øMQ Vortrag

structure1. Introduction

2. Why use ?

3. Architecture

4. Hands on!

5. Projects using

6. Future?

Page 7: øMQ Vortrag

1. Introduction

Page 8: øMQ Vortrag

What is ?

is a high-performance asynchronous messaging library

developed by the “iMatix Corporation“ and an open sourcecommunity

it is a “message queue” system, unlike “message oriented middleware” (no broker architecture)

developed as a simple way contrary to AMQP (Advanced Message Queuing Protocol)

LGPL/GPLv3 Software

written in C++

1. Introduction

Page 9: øMQ Vortrag

1. Introduction

: it allows designing complex communication

systems without much effort

it is not a complete messaging system

no out of the box product

like unwrap it, configure it, start it up

it is a higher level socket interface to build up

your own messaging system

Page 10: øMQ Vortrag

History

the original designer of AMQP (Pieter

Hintjens, CEO from iMatrix) started ZeroMQ on

March 30, 2010

he left AMQP working group and now supports

AMQP 1.0 with the new project ZeroMQ

now the latest version is 2.0.10

1. Introduction

Page 11: øMQ Vortrag

entity 1queue

entity 2

1. Introduction

Page 12: øMQ Vortrag

2.Why use ?

Page 13: øMQ Vortrag

2. Why use ?

“If you've done any work with

threads, protocols, or networks,

you'll realize this is pretty much

impossible. It's a dream.

Even connecting a few programs across a

few sockets is plain nasty,

when you start to handle real life

situations.”

Page 14: øMQ Vortrag

Scalability◦ one ZeroMQ socket can connect to multiple endpoints

◦ it automatically provides load balancing

Simplicity◦ the API looks simple

◦ compared with raw sockets it is really simple to deliver

messages

◦ no buffer management is needed

Performance◦ no overhead of an over-engineered protocol

2. Why use ?

Page 15: øMQ Vortrag

language bindings

Ada

Basic

C

C++

C# (.NET & Mono)

Common Lisp

D

Erlang

Go

Haskell

2. Why use ?

Page 16: øMQ Vortrag

language bindings

node.js Objective-C Perl PHP Python Racket Ruby Ruby Tcl Lua

2. Why use ?

Page 17: øMQ Vortrag

3. Architecture

Page 18: øMQ Vortrag

3. Architecture

Page 19: øMQ Vortrag

general architectureapplication

Socket_base.cpp

ctx.cpp

tcp_connecter.cpp tcp_socket.cpp

zmq.cpp/zmq.h

Page 20: øMQ Vortrag

3. Architecture

concurrency model

ØMQ's concurrency model may a bit confusing

at first

ØMQ is a multithreaded application without

◦ mutexes

◦ condition variables

◦ semaphores

instead, each object will live in its own thread

other threads never touch them

Page 21: øMQ Vortrag

3. Architecture

concurrency model

threads communicate with the aid of messages

they called 'commands' to distinguish from user-

level ØMQ-messages

same way the objects can speak to other

objects

Page 22: øMQ Vortrag

3. Architecture

threading model

ZeroMQ

Application

I/O ThreadsApplication

Thread

Page 23: øMQ Vortrag

3. Architecture

threading model

ZeroMQ

Application

I/O ThreadsApplication

Threadcreated outside of

ØMQ to access

the API

created inside of

ØMQ to send

messages

Page 24: øMQ Vortrag

3. Architecture

mailbox system

threads are only objects with a 'mailbox„

basically mailboxes are queues to store

commands

threads retrieve

commands from

the mailbox

mailbox.cpp

Page 25: øMQ Vortrag

3. Architecture

API from zmq.cpp

Page 26: øMQ Vortrag

3. Architecturezmq.cpp

Page 27: øMQ Vortrag

3. Architecturezmq.cpp

Page 28: øMQ Vortrag

3. Architecture

3 steps to set up ZeroMQ

1. choose a transport mechanism

2. set up the infrastructure

3. select a messaging pattern

Page 29: øMQ Vortrag

3. Architecture

choose a transport mechanism

Page 30: øMQ Vortrag

3. Architecture

possible ways to deliver a message:

INPROC:◦ an In-Process communication model

IPC:◦ an Inter-Process communication model

MULTICAST:◦ multicast via PGM, possibly encapsulated in UDP

TCP:◦ a network based transport

Page 31: øMQ Vortrag

3. Architecture

PGM (Pragmatic General Multicast)

is a reliable multicast transport protocol

provides a reliable sequence of packets to

multiple recipients simultaneously

making it suitable for applications like multi-

receive

Page 32: øMQ Vortrag

3. Architecture

set up the infrastructure

Page 33: øMQ Vortrag

3. Architecture

possible infrastructures

QUEUE:◦ a forwarder for the request/response messaging

pattern

FORWARDER:◦ a forwarder for the publish/subscribe messaging

pattern

STREAMER:◦ a forwarder for the pipelined messaging pattern

Page 34: øMQ Vortrag

3. Architecture

select a messaging pattern

Page 35: øMQ Vortrag

3. Architecture

REQUEST/REPLY:◦ bidirectional, load balanced and state based

PUBLISH/SUBSCRIBE:◦ publish to multiple recipients at once

UPSTREAM / DOWNSTREAM:◦ distribute data to nodes arranged in a pipeline

PAIR:◦ communication exclusively between peers

◦ old pattern only for specific applications

Page 36: øMQ Vortrag

3. Architecture

valid socket combinations

PUB and SUB REQ and REP REQ and XREP XREQ and REP XREQ and XREP XREQ and XREQ XREP and XREP PUSH and PULL PAIR and PAIR zmq.h

Page 37: øMQ Vortrag

3. Architecture

REQUEST/REPLY:

Page 38: øMQ Vortrag

3. Architecture

PUBLISH/SUBSCRIBE:

Page 39: øMQ Vortrag

3. Architecture

UPSTREAM / DOWNSTREAM:

Page 40: øMQ Vortrag

4. Hands on!

Page 41: øMQ Vortrag

4. Hands on!

basic concepts

hwserver.cpp

Page 42: øMQ Vortrag

4. Hands on!

basic concepts

hwserver.py

Page 43: øMQ Vortrag

4. Hands on!

basic concepts

hwserver.cpp

Page 44: øMQ Vortrag

4. Hands on!ctx.cpp

Page 45: øMQ Vortrag

4. Hands on!ctx.cpp

Page 46: øMQ Vortrag

4. Hands on!

basic concepts

ctx.h

Page 47: øMQ Vortrag

4. Hands on!

basic concepts

ctx.h

Page 48: øMQ Vortrag

4. Hands on!

basic concepts

zmq.cpp

Page 49: øMQ Vortrag

4. Hands on!

basic concepts

hwserver.cpp

Page 50: øMQ Vortrag

4. Hands on!

basic concepts

zmq.cpp

Page 51: øMQ Vortrag

4. Hands on!Socket_base.cpp

Page 52: øMQ Vortrag

4. Hands on!Socket_base.cpp

Page 53: øMQ Vortrag

4. Hands on!

config.hpp

Page 54: øMQ Vortrag

4. Hands on!

example!!

Page 55: øMQ Vortrag

4. Hands on!

get : (only source code version)

1. download source code (git://github.com/zeromq/zeromq2.git)

2. build libraries (Windows MSVS or your favorite

Compiler on Linux )

3. install on system

4. additional language bindings only available as

source package

Page 56: øMQ Vortrag

5. Projects using ZeroMQ

Page 57: øMQ Vortrag

5. Projects using ZeroMQ

Projects using ZeroMQ

Dripdrop (Javascript Reactor pattern) Zeromqt (Qt) Soaplib (Python) C++ wrapper of zmq::poll zdevices devices project JeffMQ (peer to peer queue framework) 0MQ plugin for RabbitMQ TCP thin streams ZMQMachine (Ruby) (reactor pattern)

Page 58: øMQ Vortrag

6. Future?

Page 59: øMQ Vortrag

Future?

ØMQ 3.0 Roadmap

TCP virtual services / virtual endpoints

Pattern Checking

API Simplifikation

Removals

Page 60: øMQ Vortrag

Future?

ØMQ 3.0 Roadmap

context configuration

it is not possible to dynamically configure a

context at this time

Page 61: øMQ Vortrag

thanks for your attention!