def emit_many(self, tuples, stream=None, anchors=[], direct_task=None): """A more efficient way to send many tuples, dumps out all tuples to STDOUT instead of writing one at a time. :param tuples: an iterable of ``list``s representing the tuples to send to Storm. All tuples should contain only JSON-serializable data. :param stream: a ``str`` indicating the ID of the steram to emit these tuples to. Specify ``None`` to emit to default stream. :param anchors: a `` list`` of IDs the tuples these tuples should be anchored to. :param direct_task: an ``int`` which indicates the task to send the tuple to. """ if _ANCHOR_TUPLE is not None: anchors = [_ANCHOR_TUPLE] msg = { 'command': 'emit', 'anchors': [a.id for a in anchors], } if stream is not None: msg['stream'] = stream if direct_task is not None: msg['task'] = direct_task lines = [] for tup in tuples: msg['tuple'] = tup lines.append(json.dumps(msg)) _stdout.write("{}\nend\n".format("\nend\n".join(lines))) _stdout.flush()
def emit_many(self, tuples, tup_id=None, stream=None, direct_task=None): """A more efficient way to send many tuples, dumps out all tuples to STDOUT instead of writing one at a time. :param tuples: a two-dimensional ``list`` representing the tuples to send to Storm. Tuples should contain only JSON-serializable data. :param tup_id: ``str`` or ``int`` which is the id for the tuple. Leave this blank for unreliable emits. :param stream: ``str`` ID of the stream these tuples should be emitted to. Leave empty to emit to the default stream. :param direct_task: ``int`` indicating the task to send the tuple to if performing a direct emit. """ msg = { 'command': 'emit', } if tup_id is not None: msg['id'] = tup_id if stream is not None: msg['stream'] = stream if direct_task is not None: msg['task'] = direct_task lines = [] for tup in tuples: msg['tuple'] = tup lines.append(json.dumps(msg)) _stdout.write("{}\nend\n".format("\nend\n".join(lines))) _stdout.flush()
def emit_many(self, tuples, stream=None, anchors=[], direct_task=None): """A more efficient way to send many tuples. Dumps out all tuples to STDOUT instead of writing one at a time. :param tuples: a ``list`` containing ``list`` s of tuple payload data to send to Storm. All tuples should contain only JSON-serializable data. :type tuples: list :param stream: the ID of the steram to emit these tuples to. Specify ``None`` to emit to default stream. :type stream: str :param anchors: IDs the tuples which the emitted tuples should be anchored to. :type anchors: list :param direct_task: indicates the task to send the tuple to. :type direct_task: int """ msg = { 'command': 'emit', 'anchors': [a.id for a in anchors], } if stream is not None: msg['stream'] = stream if direct_task is not None: msg['task'] = direct_task lines = [] for tup in tuples: msg['tuple'] = tup lines.append(json.dumps(msg)) _stdout.write("{}\nend\n".format("\nend\n".join(lines))) _stdout.flush()