txZMQ

Twisted bindings for ZeroMQ
Download

txZMQ Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Publisher Name:
  • Andrey Smirnov
  • Publisher web site:
  • http://smira.ru

txZMQ Tags


txZMQ Description

Twisted bindings for ZeroMQ txZMQ is a Python library that allows to integrate easily ZeroMQ sockets into Twisted event loop (reactor).txZMQ introduces support for general ZeroMQ sockets by class ZmqConnection that can do basic event loop integration, sending-receiving messages in non-blocking manner, scatter-gather for multipart messages.Special descendants of that class, ZmqPubConnection and ZmqSubConnection add special nice features for PUB/SUB sockets.Other socket types could be easily derived from ZmqConnection except for REQ/REP sockets that may require more work, as reply should be send immediately upon receiving message (currently ZmqConnection will try to read all available message and write queued messages in parallel).Example:import sysfrom optparse import OptionParserfrom twisted.internet import reactor, deferfrom twisted.python import logobserver = log.FileLogObserver(sys.stderr)log.addObserver(observer.emit)parser = OptionParser("")parser.add_option("-m", "--method", dest="method", help="0MQ socket connection: bind|connect")parser.add_option("-e", "--endpoint", dest="endpoint", help="0MQ Endpoint")parser.add_option("-M", "--mode", dest="mode", help="Mode: publisher|subscriber")parser.set_defaults(method="connect", endpoint="epgm://eth1;239.0.5.3:10011")(options, args) = parser.parse_args()from txZMQ import ZmqFactory, ZmqEndpoint, ZmqPubConnection, ZmqSubConnectionimport timezf = ZmqFactory()e = ZmqEndpoint(options.method, options.endpoint)if options.mode == "publisher": s = ZmqPubConnection(zf, e) def publish(): data = str(time.time()) print "publishing %r" % data s.publish(data) reactor.callLater(1, publish) publish()else: s = ZmqSubConnection(zf, e) s.subscribe("") def doPrint(*args): print "message received: %r" % (args, ) s.gotMessage = doPrintreactor.run() Requirements: · Python · ZeroMQ library >= 2.1 (heavily tested with 2.1.4) · PyZMQ · Twisted


txZMQ Related Software