예제 #1
0
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()
예제 #2
0
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
예제 #3
0
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