Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Spout or Bolt access the ID by which it is known in the Topology?

Tags:

apache-storm

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.

like image 704
Daryl Odnert Avatar asked Oct 20 '22 20:10

Daryl Odnert


1 Answers

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.

like image 103
Chris Gerken Avatar answered Oct 30 '22 02:10

Chris Gerken