Tuple.getStringByField("ABC") 在 Storm 中有什么用

what is use of Tuple.getStringByField("ABC") in Storm

我无法理解 Apache Storm 中 Tuple.getStringByField("ABC") 的用法。

代码如下:

   Public Void execute(Tuple input){ 
       try{
          if (input.getSourceStreamId.equals("signals"))
            {
                str=input.getStringByField("action")

                if ("refresh".equals(str))
                  {....}
             }
             }...

这里 input.getStringByField("action") 正是这样做的..

谢谢。

getStringByField()getString() 相似,只是它通过字段名称而不是位置查找字段。

在风暴中,喷口和螺栓都发出元组。但问题是每个元组中包含什么。每个 spout 和 bolt 都可以使用下面的方法来定义元组模式。

  @Override
  public void declareOutputFields(
      OutputFieldsDeclarer outputFieldsDeclarer)
  {
    // tell storm the schema of the output tuple
    // tuple consists of columns called 'mycolumn1' and 'mycolumn2'
    outputFieldsDeclarer.declare(new Fields("mycolumn1", "mycolumn2"));
  }

随后的bolt可以使用getStringByField("mycolumn1")根据列名检索值。