问题描述
我遇到了以下情况:
- 有许多计算不同值的螺栓
- 这个值被发送到可视化螺栓
- 可视化螺栓打开一个网络套接字并发送值以某种方式可视化
问题是,可视化螺栓总是相同的,但它为可以作为其输入的每种类型的螺栓发送带有不同标头的消息.例如:
The thing is, visualization bolt is always the same, but it sends a message with a different header for each type of bolt that can be its input. For example:
- BoltSum 计算总和
- BoltDif 计算差异
BoltMul 计算倍数
- BoltSum calculates sum
- BoltDif calculates difference
BoltMul calculates multiple
所有这些螺栓都使用 VisualizationBolt 进行可视化
All this bolts use VisualizationBolt for visualization
我的问题是,我应该创建 3 个独立的实例,每个实例都有一个线程,例如
My question is, should I create 3 independent instances, where each instance will have one thread, e.g.
builder.setBolt("forSum", new VisualizationBolt(),1).globalGrouping("bolt-sum");
builder.setBolt("forDif", new VisualizationBolt(),1).globalGrouping("bolt-dif");
builder.setBolt("forMul", new VisualizationBolt(),1).globalGrouping("bolt-mul");
或者我应该做以下事情
builder.setBolt("forAll", new VisualizationBolt(),3)
.fieldsGrouping("forSum", new Fields("type"))
.fieldsGrouping("forDif", new Fields("type"))
.fieldsGrouping("forMul", new Fields("type"));
并从前面的每个 bolt 发出类型,以便可以根据它对它们进行分组?
And emit type from each of the previous bolts, so they can be grouped on based on it?
有什么优势?
另外,我是否应该期望每次bolt-sum都会进入第一个可视化bolt,bolt-dif会进入第二个可视化bolt,bolt-mul会进入第三个可视化bolt?他们不会混在一起吗?
Also, should I expect that each and every time bolt-sum will go to first visualization bolt, bolt-dif will go to second visualization bolt and bolt-mul will go to third visualization bolt? They won't be mixed?
我认为应该是这样,但它目前不在我的实现中,所以我不确定这是一个错误还是我遗漏了什么?
I think that that should be the case, but it currently isn't in my implementation, so I'm not sure if it's a bug or I'm missing something?
推荐答案
使用三个实例的第一种方法是正确的方法.使用 fieldsGrouping
并不确保sum"值转到Sum-Visualization-Bolt"并且 sum/diff/mul 值都不是不同的(即,在不同的螺栓实例).
The first approach using three instances is the correct approach. Using fieldsGrouping
does not ensure, that "sum" values go to "Sum-Visualization-Bolt" and neither that sum/diff/mul values are distinct (ie, in different bolt instances).
fieldGrouping
的语义更宽松:它只保证,所有相同类型的元组都将被一个单一的 bolt 实例处理,即永远不会是这种情况,两个不同的 bolt 实例得到相同的类型.
The semantic of fieldGrouping
is more relaxed: it only guarantees, that all tuples of the same type will be processed by a single bolt instance, ie, that it will never be the case, that two different bolt instances get the same type.
这篇关于风暴场分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!