def initialize(self): self.forwarddevice = Device(zmq.QUEUE, zmq.PULL, zmq.PUB) self.forwarddevice.bind_in('tcp://%s:%d' % (self.pulladdr, self.pullport)) self.forwarddevice.bind_out('tcp://%s:%d' % (self.pubaddr, self.pubport)) logger.info('created broker in: PULL@%s:%d out: PUB@%s:%d' % (self.pulladdr, self.pullport, self.pubaddr, self.pubport))
def entrypoint(): """runs a ZMQ Device. :param ``--bind-in``: the ZMQ address to bind in :param ``--bind-out``: the ZMQ address to bind out :param ``--connect-in``: the ZMQ address to connect in :param ``--connect-out``: the ZMQ address to connect out :param ``--hwm-in``: the high-water-mark in :param ``--hwm-out``: the high-water-mark out :: $ agentzero queue \\ --type-in=dealer --bind-in=tcp://0.0.0.0.2210 \\ --type-out=router \\ --bind-out=tcp://0.0.0.0.2211 """ parser = argparse.ArgumentParser( prog='agentzero (queue|pipeline|forwarder)', description= 'master server that orchestrates minions and controller by a backend API' ) parser.add_argument('device_type', help='the type of ZMQ device to run') parser.add_argument('--bind-in', help='a valid zmq address') parser.add_argument('--bind-out', help='a valid zmq address') parser.add_argument('--connect-in', help='a valid zmq address') parser.add_argument('--connect-out', help='a valid zmq address') parser.add_argument( '--type-in', help='the type of zmq socket that should handle input data') parser.add_argument( '--type-out', help='the type of zmq socket that should handle output data') parser.add_argument( '--hwm-in', help= 'an integer representing the number of messages to buffer incoming data before either dropping messages or blocking process execution' ) parser.add_argument( '--hwm-in', help= 'an integer representing the number of messages to buffer outcoming data before either dropping messages or blocking process execution' ) args = parser.parse_args() device_type = getattr(zmq, args.device_type.upper()) type_in = getattr(zmq, args.type_in.upper()) type_out = getattr(zmq, args.type_out.upper()) device = Device(device_type, type_in, type_out) coloredlogs.install(level=logging.INFO) device.run()
def entrypoint(): """runs a ZMQ Device. :param ``--bind-in``: the ZMQ address to bind in :param ``--bind-out``: the ZMQ address to bind out :param ``--connect-in``: the ZMQ address to connect in :param ``--connect-out``: the ZMQ address to connect out :param ``--hwm-in``: the high-water-mark in :param ``--hwm-out``: the high-water-mark out :: $ agentzero queue \\ --type-in=dealer --bind-in=tcp://0.0.0.0.2210 \\ --type-out=router \\ --bind-out=tcp://0.0.0.0.2211 """ parser = argparse.ArgumentParser( prog="agentzero (queue|pipeline|forwarder)", description="master server that orchestrates minions and controller by a backend API", ) parser.add_argument("device_type", help="the type of ZMQ device to run") parser.add_argument("--bind-in", help="a valid zmq address") parser.add_argument("--bind-out", help="a valid zmq address") parser.add_argument("--connect-in", help="a valid zmq address") parser.add_argument("--connect-out", help="a valid zmq address") parser.add_argument( "--type-in", help="the type of zmq socket that should handle input data" ) parser.add_argument( "--type-out", help="the type of zmq socket that should handle output data", ) parser.add_argument( "--hwm-in", help="an integer representing the number of messages to buffer incoming data before either dropping messages or blocking process execution", ) parser.add_argument( "--hwm-in", help="an integer representing the number of messages to buffer outcoming data before either dropping messages or blocking process execution", ) args = parser.parse_args() device_type = getattr(zmq, args.device_type.upper()) type_in = getattr(zmq, args.type_in.upper()) type_out = getattr(zmq, args.type_out.upper()) device = Device(device_type, type_in, type_out) device.run()
class ZMQSampleBroker(object): def __init__(self, cfg): self.cfg = ConfigWrapper(other=cfg.get('zmq')) self.pulladdr = cfg.get('pulladdr', '0.0.0.0') self.pubaddr = cfg.get('pubaddr', '0.0.0.0') self.pullport = cfg.get('pullport', 59000) self.pubport = cfg.get('pubport', 59001) def initialize(self): self.forwarddevice = Device(zmq.QUEUE, zmq.PULL, zmq.PUB) self.forwarddevice.bind_in('tcp://%s:%d' % (self.pulladdr, self.pullport)) self.forwarddevice.bind_out('tcp://%s:%d' % (self.pubaddr, self.pubport)) logger.info('created broker in: PULL@%s:%d out: PUB@%s:%d' % (self.pulladdr, self.pullport, self.pubaddr, self.pubport)) def start(self): logger.info('starting broker') self.forwarddevice.start()
import sys from zmq import FORWARDER, PUB, SUB, SUBSCRIBE from zmq.devices import Device if __name__ == "__main__": usage = 'usage: chat_bridge sub_address pub_address' if len(sys.argv) != 3: print(usage) sys.exit(1) sub_addr = sys.argv[1] pub_addr = sys.argv[2] print("Recieving on %s" % sub_addr) print("Sending on %s" % pub_addr) device = Device(FORWARDER, SUB, PUB) device.bind_in(sub_addr) device.setsockopt_in(SUBSCRIBE, "") device.bind_out(pub_addr) device.start()
def execute_command_streamer(): from oldspeak.console.parsers.streamer import parser args = parser.parse_args(get_sub_parser_argv()) bootstrap_conf_with_gevent(args) device = Device(zmq.STREAMER, zmq.PULL, zmq.PUSH) device.bind_in(args.pull) device.bind_out(args.push) if args.pull_hwm: device.setsockopt_in(zmq.RCVHWM, args.pull_hwm) if args.push_hwm: device.setsockopt_out(zmq.SNDHWM, args.push_hwm) print "oldspeak streamer started" print "date", datetime.utcnow().isoformat() print "pull", (getattr(args, 'pull')) print "push", (getattr(args, 'push')) device.start()
def execute_command_forwarder(): from oldspeak.console.parsers.streamer import parser args = parser.parse_args(get_sub_parser_argv()) bootstrap_conf_with_gevent(args) device = Device(zmq.FORWARDER, zmq.SUB, zmq.PUB) device.bind_in(args.subscriber) device.bind_out(args.publisher) device.setsockopt_in(zmq.SUBSCRIBE, b'') if args.subscriber_hwm: device.setsockopt_in(zmq.RCVHWM, args.subscriber_hwm) if args.publisher_hwm: device.setsockopt_out(zmq.SNDHWM, args.publisher_hwm) print "oldspeak forwarder started" print "date", datetime.utcnow().isoformat() print "subscriber", (getattr(args, 'subscriber')) print "publisher", (getattr(args, 'publisher')) device.start()