Is there an API for a Storm Spout or Bolt to access its ID? The ID I am referring to is the String
that was passed to the setSpout
or setBolt
method in class backtype.storm.topology.TopologyBuilder
.
It would be useful to access this string for the logging purposes.
You can use getThisComponentId() on the passed topology context in the prepare method for bolts:
@Override
public void prepare(Map config, TopologyContext context, OutputCollector collector) {
this.collector = collector;
String componentId = context.getThisComponentId();
}
and in the open method for spouts.
There's also a more general method getComponentId(int taskId) that returns the component id for any given task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With