def main(): import optparse parser = optparse.OptionParser('usage: %prog <zmqCentral-messages-xxx.txt>') parser.add_option('-t', '--topic', action='append', help='Only print specified topics, can specify multiple times') ZmqPublisher.addOptions(parser, 'zmqPlayback') opts, args = parser.parse_args() if len(args) != 1: parser.error('expected exactly 1 arg') logging.basicConfig(level=logging.DEBUG) pb = ZmqPlayback(args[0], opts) pb.start() zmqLoop()
def main(): import optparse parser = optparse.OptionParser( 'usage: %prog <zmqCentral-messages-xxx.txt>') parser.add_option( '-t', '--topic', action='append', help='Only print specified topics, can specify multiple times') ZmqPublisher.addOptions(parser, 'zmqPlayback') opts, args = parser.parse_args() if len(args) != 1: parser.error('expected exactly 1 arg') logging.basicConfig(level=logging.DEBUG) pb = ZmqPlayback(args[0], opts) pb.start() zmqLoop()
class ZmqPlayback(object): def __init__(self, logPath, opts): self.logPath = logPath self.opts = opts self.publisher = ZmqPublisher(**ZmqPublisher.getOptionValues(opts)) print 'topics:', self.opts.topic def start(self): self.publisher.start() # the delay gives a chance to connect to central before publishing self.publishTimer = ioloop.DelayedCallback(self.playLog, 100) self.publishTimer.start() def playLog(self): self.logFile = open(self.logPath, 'rb') self.log = LogParser(self.logFile) i = 0 for rec in self.log: topicMatch = False if self.opts.topic: for topic in self.opts.topic: if rec.msg.startswith(topic): topicMatch = True break else: topicMatch = True if topicMatch: self.publisher.pubStream.send(rec.msg) if i % 100 == 0: sys.stdout.write('.') sys.stdout.flush() i += 1 print print 'message count:', i
def main(): import optparse parser = optparse.OptionParser('usage: %prog') ZmqPublisher.addOptions(parser, 'testPublishAttachments') opts, args = parser.parse_args() if args: parser.error('expected no args') logging.basicConfig(level=logging.DEBUG) # set up networking p = ZmqPublisher(**ZmqPublisher.getOptionValues(opts)) p.start() # start publishing an arbitrary message that central should forward pubTimer = ioloop.PeriodicCallback(lambda: pubMessage(p), 1000) pubTimer.start() zmqLoop()
def __init__(self, logPath, opts): self.logPath = logPath self.opts = opts self.publisher = ZmqPublisher(**ZmqPublisher.getOptionValues(opts)) print 'topics:', self.opts.topic