云计算
今天就跟大家聊聊有关Storm 中Fields有什么用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
TransactionalTopologyBuilder builder = new TransactionalTopologyBuilder(\”test\”, \”spout\”, new TweetsTransactionalSpout()); builder.setBolt(\”users-splitter\”, new UserSplitterBolt(), 4).shuffleGrouping(\”spout\”);builder.setBolt(\”hashtag-splitter\”, new HashtagSplitterBolt(), 4).shuffleGrouping(\”spout\”); builder.setBolt(\”user-hashtag-merger\”, new UserHashtagJoinBolt(), 4) .fieldsGrouping(\”users-splitter\”,\”users\”, new Fields(\”tweet_id\”)) .fieldsGrouping(\”hashtag-splitter\”, \”hashtags\”, new Fields(\”tweet_id\”));
这里有两个bolt在向user-hashtag-merger发送数据,两个bolt在 emit的时候可能发送了不同的tuple比如:
users-splitter中emit(new Values(a, b, c)); declarer.declare(new Fields(\”id\”, \”name\”, \”tweet_id\”));
hashtag-splitter中则emit(new Values(a, b)); declarer.declare(new Fields(\”id\”, \”tweet_id\”));
比如user-hashtag-merger中需要的是users-splitter中的c,hashtag-splitter 中的b,而在user-hashtag-merger
中接收数据的时候无法知道数据是哪个bolt发来的(或者就算知道,发来的数据格式不一样也不是一个好的设计)所以这边设定了一个
Fields,这样在发送数据的时候只发送指定Fields的数据,比如这边user-hashtag-merger不管前面bolt emit的时候
发送了什么,最后收到的只有一个,方便处理。
builder.setBolt(\”redis-committer\”, new RedisCommiterCommiterBolt()) .globalGrouping(\”users-splitter\”,\”users\”) .globalGrouping(\”hashtag-splitter\”, \”hashtags\”) .globalGrouping(\”user-hashtag-merger\”);
看完上述内容,你们对Storm 中Fields有什么用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注资讯频道,感谢大家的支持。
更多关于云服务器,域名注册,虚拟主机的问题,请访问西部数码官网:www.west.cn