How to access an object from the topology context into a bolt when using storm?

后端 未结 2 1374
一整个雨季
一整个雨季 2021-02-05 23:58

We need to pass an object when creating a topology so that the bolt can access that and do some further processing based on that object. Is it possible to pass the object via

2条回答
  •  遥遥无期
    2021-02-06 00:17

    I am not very sure what you mean, but your bolt class can always take a parameter on initialization, and you can initialize that with the object you want to pass when creating the topology.

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout( "spout", new mySpout() );
    builder.setBolt( "bolt", new myBolt1(myObj) ).shuffleGrouping("spout");
    

    And your bolt constructor could take this object as the argument.

    Edit: If you want the data to be accessible without passing it explicitly to a constructor, you can again always make a static class to store this data and access it from the bolt objects

提交回复
热议问题