Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati
Upcoming SlideShare
Loading in...5
×
 

Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati

on

  • 1,322 views

Introduction to message brokers; demo session with ActiveMQ and Python; quick overview of alternatives to ActiveMQ; Q&A

Introduction to message brokers; demo session with ActiveMQ and Python; quick overview of alternatives to ActiveMQ; Q&A

Statistics

Views

Total Views
1,322
Views on SlideShare
1,322
Embed Views
0

Actions

Likes
1
Downloads
18
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati Python Ireland 2012 - Message brokers and Python by Fernando Ciciliati Presentation Transcript

    • Message Brokers and PythonPython Ireland Meetup - Jun/2012 Fernando Ciciliati ciciliati@gmail.com
    • Contents What sort of problems are we trying to solve? Messaging concepts A solution based on ActiveMQ ActiveMQ + Python: STOMP and Stomp.py ActiveMQ Queues and Topics Other ActiveMQ concepts Alternatives to ActiveMQ AMQP RabbitMQ ZeroMQ Others
    • Problems Time decoupling Scalability / Architecture flexibility Technology mix
    • Concepts Producer Consumer Message Control x Data x Hybrid Small x Large Durability Queue Message Broker
    • Apache ActiveMQ Disclaimer: Each broker has its own view of the world! Apache Project Written in Java Designed for high performance Flexible storage layer Multiple communication protocols Clustering capabilities Very active community -> constant evolution -> ... bugs
    • Apache ActiveMQ Web console on port 8161 lets have a look at it... STOMP is not enabled by default Configuration: activemq.xml Running? Check it with netstat -ltn
    • ActiveMQ and Python Easiest way (IMHO): STOMP Libraries stomp.py stompy twisted + stomper/stompest Our choice stomp.py
    • STOMP Simple (or Streaming) Text Orientated Messaging Protocol. in-band (like HTTP or SMTP) Headers + body Text, not binary Simple Lets telnet...
    • stomp.py Created by Jason Briggs Currently at version 3.x Supports Python 2 and Python 3 Has a CLI ! lets have a look at it...
    • More ActiveMQ Persistence Producer: Receipt Consumer: Ack/NoAck Exclusive Consumers Selectors Queues X Topics Prefetch
    • A simple Python producer def sendJMS(message, host, queue, port=61613, user=, password=, persistent=True): # Size of a buffer for storing MQServer STOMP answers to commands. bufsize = 200 # Establish a TCP connection t = socket.socket(socket.AF_INET, socket.SOCK_STREAM) t.connect ((host, port)) # Establish a STOMP connection frame = CONNECTnnx00 t.sendall(frame) resp = t.recv(bufsize) if resp[0:9] != CONNECTED: print (sendJMS: Failed to connect to MQ server) return 1 # Send the message if persistent: persist="true" else: persist="false" frame = SENDndestination:%snpersistent:%snn%sx00 % (queue,persist,message) t.sendall(frame) # Disconnect STOMP frame = DISCONNECTnnx00 t.sendall(frame) # Disconnect TCP t.close() del(t) return 0
    • A simple stomp.py producer import time import sys import stomp USAGE = """ producer.py <destination> <message> <destination> should start by /queue or /topic <message> is the text to be sent as message body (blank spaces accepted). """ if len(sys.argv) < 3: print USAGE else: conn = stomp.Connection() # with default parameters conn.start() conn.connect() conn.send( .join(sys.argv[2:]), destination=sys.argv[1]) time.sleep(2) conn.disconnect()
    • A simple stomp.py consumer import sys import time import stomp class MyListener(object): def on_error(self, headers, message): print *** received an error:n%sn*** % message def on_message(self, headers, message): print *** received a message:n%sn*** % message conn = stomp.Connection() conn.set_listener(, MyListener()) conn.start() conn.connect() conn.subscribe(destination=sys.argv[1], ack=auto) try: while True: time.sleep(1) except KeyboardInterrupt: pass finally: print "nDisconnecting..." conn.disconnect()
    • AMQP """ OUR VISION: To become the standard protocol for interoperability between all messaging middleware """ OASIS working group
    • RabbitMQ Message broker written in Erlang Supports AMQP Concepts: Producers Messages Exchanges Queues Consumers
    • ZeroMQ A "brokerless" approach to messaging "The Intelligent Transport Layer" ØMQ zeromq:  Ø  The socket library that acts as a concurrency framework.  Ø  Faster than TCP, for clustered products and supercomputing.  Ø  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.  Ø  Large and active open source community.  Ø  30+ languages including C, C++, Java, .NET, Python.  Ø  Most OSes including Linux, Windows, OS X.  Ø  LGPL free software with full commercial support from iMatix. (text from http://www.zeromq.org)
    • Even more questions? :) Thanks!