one bolt recive from 2 others in streamparse python

27 views Asked by At

i want to implement a topology like below picture in that topology bolt1 send a number to bolt3 and bolt2 send another number to bolt3 and i want to calculate some of this two number in bolt3 but i can't receive both values with following code

see topology

class SumBolt(Bolt):
    #outputs = ["number","result"]
    def process(self, tup):
        duble = tup.values[1]
        square = tup.values[0]
        self.logger.info(
                f"bolt4 duble is {duble} and square is {square}"
            )
        total_sum = duble + square
        self.emit([total_sum], anchors=[tup])
        time.sleep(20)

and topology is

class MyTopology(Topology):
    spout = RandomNumberSpout.spec()
    bolt1 = MultiplyByTwoBolt.spec(inputs={spout: Grouping.fields('number')},par=1)
    bolt2 = SquareBolt.spec(inputs={spout: Grouping.fields('number')},par=1)
    bolt3 = FileStorageBolt.spec(inputs={spout: Grouping.fields('number')},par=1)
    bolt4 = SumBolt.spec(inputs={bolt1: Grouping.SHUFFLE.fields('result1'),
                                bolt2: Grouping.SHUFFLE.fields('result2')},par=1)

the error is index is out of range(only one item sent to bolt3)

i have explaind my tries on codes

0

There are 0 answers