def router_share_async(obj, address): """ :param obj: :param address: :returns: AsyncRouterExport """ socket = ZmqREPConnection(ZmqFactory(), ZmqEndpoint("bind", address)) return AsyncRouterExport(obj, socket)
def add_rep(self, endpoint, callBack=onPrint): ''' 设置 rep 对象 :param endpoint: :param callBack: :return: ''' if endpoint: logger.debug("开始运行 REP 服务器,监听地址为:{}...".format(endpoint)) self.rep_ = ZmqREPConnection(ZmqFactory(), ZmqEndpoint('bind', endpoint)) self.rep_.gotMessage = callBack
def add_rep(self, endpoint, callBack=None): ''' 设置 rep 对象 :param endpoint: :param callBack: :return: ''' if endpoint: logger.debug("开始运行 REP 服务器,监听地址为:{}...".format(endpoint)) self._rep = ZmqREPConnection(ZmqFactory(), ZmqEndpoint('bind', endpoint)) if callBack: self._rep.gotMessage = callBack else: self._rep.gotMessage = self.doDataReceived
def __init__(self, app): self.app = app self.config = app.config self.cache = app.mcache self.db = app.db self.syslog = app.syslog self.secret = app.config.system.secret zfactory = ZmqFactory() self.listen = "tcp://*:{0}".format(int(self.config.admin.zauth_port)) endpoint = ZmqEndpoint('bind', self.listen) self.agent = ZmqREPConnection(zfactory, endpoint) self.agent.gotMessage = self.process self.register() self.syslog.info('zmq authorize agent running %s' % self.listen)
def __init__(self, config, dbengine, radcache = None): self.config = config self.load_plugins(load_types=['radius_auth_req', 'radius_accept']) self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary')) self.db_engine = dbengine or get_engine(config) self.aes = utils.AESCipher(key=self.config.system.secret) self.mcache = radcache self.stat_pusher = ZmqPushConnection(ZmqFactory()) self.zmqrep = ZmqREPConnection(ZmqFactory()) self.stat_pusher.tcpKeepalive = 1 self.zmqrep.tcpKeepalive = 1 self.stat_pusher.addEndpoints([ZmqEndpoint('connect', config.mqproxy.task_connect)]) self.zmqrep.addEndpoints([ZmqEndpoint('connect', config.mqproxy.auth_connect)]) self.zmqrep.gotMessage = self.process self.reject_debug = int(self.get_param_value('radius_reject_debug', 0)) == 1 logger.info('radius auth worker %s start' % os.getpid()) logger.info('init auth worker : %s ' % self.zmqrep) logger.info('init auth stat pusher : %s ' % self.stat_pusher)
def __init__(self, config, dbengine, radcache = None): self.config = config self.load_plugins(load_types=['radius_acct_req']) self.db_engine = dbengine or get_engine(config) self.mcache = radcache self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary')) self.stat_pusher = ZmqPushConnection(ZmqFactory()) self.zmqrep = ZmqREPConnection(ZmqFactory()) self.stat_pusher.tcpKeepalive = 1 self.zmqrep.tcpKeepalive = 1 self.stat_pusher.addEndpoints([ZmqEndpoint('connect', config.mqproxy.task_connect)]) self.zmqrep.addEndpoints([ZmqEndpoint('connect', config.mqproxy.acct_connect)]) self.zmqrep.gotMessage = self.process self.acct_class = {STATUS_TYPE_START: RadiusAcctStart, STATUS_TYPE_STOP: RadiusAcctStop, STATUS_TYPE_UPDATE: RadiusAcctUpdate, STATUS_TYPE_ACCT_ON: RadiusAcctOnoff, STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff} logger.info('radius acct worker %s start' % os.getpid()) logger.info('init acct worker : %s ' % self.zmqrep) logger.info('init acct stat pusher : %s ' % self.stat_pusher)
import os import sys from twisted.internet import reactor rootdir = os.path.realpath(os.path.join(os.path.dirname(sys.argv[0]), '..')) sys.path.insert(0, rootdir) os.chdir(rootdir) from txzmq import ZmqEndpoint, ZmqFactory, ZmqREQConnection, ZmqREPConnection zf = ZmqFactory() endpoint = "ipc:///tmp/txzmq-test" req = ZmqREQConnection(zf, ZmqEndpoint("connect", endpoint)) rep = ZmqREPConnection(zf, ZmqEndpoint("bind", endpoint)) def gotMessage(messageId, message): rep.reply(messageId, b"REP: " + message) rep.gotMessage = gotMessage exitCode = 0 def start(): def gotReply(reply): if reply != [b"REP: REQ1"]: print("Unexpected reply: %r" % (reply, ))
def produce(): # data = [str(time.time()), socket.gethostname()] data = str(time.time()) print "Requesting %r" % data try: d = s.sendMsg(data) def doPrint(reply): print("Got reply: %s" % (reply)) d.addCallback(doPrint) except zmq.error.Again: print "Skipping, no pull consumers..." reactor.callLater(1, produce) reactor.callWhenRunning(reactor.callLater, 1, produce) else: s = ZmqREPConnection(zf, e) def doPrint(messageId, message): print "Replying to %s, %r" % (messageId, message) s.reply(messageId, "%s %r " % (messageId, message)) s.gotMessage = doPrint reactor.run()