示例#1
0
 def emit(self, values, stream=None, id=None, direct_task=None, need_task_ids=False):
     """Emit a tuple"""
     msg = {"command": "emit", "tuple": values, "need_task_ids": need_task_ids}
     if id is not None:
         msg["id"] = id
     if stream is not None:
         msg["stream"] = stream
     if direct_task is not None:
         msg["task"] = direct_task
     ipc.write(msg)
     if need_task_ids:
         return ipc.read()
示例#2
0
    def run(self):
        # Init IPC to get conf info and then init bolt
        self.conf, self.context = ipc.initialize()
        self.initialize(self.conf, self.context)

        # Synchronous loop to process incoming messages.
        # Unlike Bolts, this doesn't need to be threaded or evented because
        # spouts get messages in-order
        # See: https://github.com/nathanmarz/storm/wiki/Multilang-protocol#spouts
        try:
            while True:
                msg = ipc.read()
                command = msg["command"]
                log.info("command: %s", command)
                if command == "next":
                    self.next_tuple()
                elif command == "ack":
                    self.ack(msg["id"])
                elif command == "fail":
                    self.fail(msg["id"])
                ipc.send_sync()
        except Exception, e:
            self.report_exception("E_SPOUTFAILED", e)
            log.exception("Caught exception in Spout.run: %s", str(e))