Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 准备多次执行的方法_Java_Apache Kafka_Apache Zookeeper_Apache Storm - Fatal编程技术网

Java 准备多次执行的方法

Java 准备多次执行的方法,java,apache-kafka,apache-zookeeper,apache-storm,Java,Apache Kafka,Apache Zookeeper,Apache Storm,嗨,我正在使用ApacheStorm创建一个拓扑,其中我的喷口正在从Kakfa主题收集数据并将其发送到一个bolt 我正在对元组进行一些验证,并再次为其他螺栓发出流 现在的问题是,我的第二个bolt正在使用第一个bolt的流,它有一个重载方法prepare(Map Map,TopologyContext TopologyContext,OutputCollector OutputCollector) 每2秒执行一次 拓扑的代码是 topologyBuilder.setBolt("abc",new

嗨,我正在使用ApacheStorm创建一个拓扑,其中我的喷口正在从Kakfa主题收集数据并将其发送到一个bolt

我正在对元组进行一些验证,并再次为其他螺栓发出流

现在的问题是,我的第二个bolt正在使用第一个bolt的流,它有一个重载方法
prepare(Map Map,TopologyContext TopologyContext,OutputCollector OutputCollector)
每2秒执行一次

拓扑的代码是

topologyBuilder.setBolt("abc",new ValidationBolt()).shuffleGrouping(configurations.SPOUT_ID);

topologyBuilder.setBolt("TEST",new TestBolt()).shuffleGrouping("abc",Utils.VALIDATED_STREAM);
第一个螺栓“abc”的代码为

当我搜索时,我发现

The prepare method is called when the bolt is initialised and is 
similar to the open method in spout. It is called only once for the bolt.
It gets the configuration for the bolt and also the context of the bolt. 
The collector is used to emit or output the tuples from this bolt. 
链接到日志的公共要点
您的日志显示您正在使用LocalCluster。这是一个测试/演示工具,不要将其用于生产工作负载。而是建立一个真正的分布式集群

关于正在发生的事情:

在本地集群中运行拓扑时,Storm通过在单个JVM中以线程的形式运行所有组件(Nimbus、Supervisors和Worker)来模拟真实集群。您的日志显示以下行:

20:14:12.451[SLOT_1027]信息o.a.s.ProcessSimulator-开始终止流程2ea97301-24c9-4c1a-bcba-61008693971a

20:14:12.451[SLOT_1027]信息o.a.s.d.w.工人-关闭工人智能事务数据-1-1566571315 72bbf510-c342-4385-9599-0821a2dee94e 1027

20:14:15.518[SLOT_1027]信息o.a.s.d.s.SLOT-运行msInState的状态:33328拓扑:smart-transactional-data-1-1566571315辅助程序:2ea97301-24c9-4c1a-bcba-61008693971a->杀死blob更新msInState:3001拓扑:smart-transactional-data-1-1566571315辅助程序:2ea97301-24c9-4c1a-bcba-61008693971a

20:14:15.540[SLOT_1027]信息o.a.s.d.w.Worker-为smart-transactional-data启动Worker-1-1566571315


LocalCluster正在关闭其中一个模拟工作进程,因为blobstore中的一个Blob(例如拓扑jar、拓扑配置、其他类型的共享文件,请参阅更多信息)已更改。通常,当这种情况在真实集群中发生时,工作JVM将被终止,blob将被更新,工作JVM将重新启动。因为您使用的是LocalCluster,所以它只会杀死工作线程并重新启动它。这就是为什么您会看到多次调用
prepare

工作进程是否崩溃?Storm只会在每个螺栓任务中调用prepare一次,但是如果工作进程崩溃并重新启动,它当然会被再次调用。@Stig日志中没有异常。但是不断地得到一些日志。附加有问题的日志。我试着用StormSubmitter运行它,它按预期工作。谢谢你的解释。有什么方法可以用本地集群实现同样的效果吗?如果你真的想在本地集群中只执行一次,只需在拓扑设置代码中运行它,或者在某个地方初始化一个静态变量。有什么例子吗。我对暴风雪很陌生。谢谢,您当然也可以在bolt中放置一个静态布尔字段,只有当该字段为false时才运行prepare。运行prepare后,将字段设置为true。这将有助于防止LocalCluster多次运行prepare,同时仍然允许分布式模式Storm工作。
The prepare method is called when the bolt is initialised and is 
similar to the open method in spout. It is called only once for the bolt.
It gets the configuration for the bolt and also the context of the bolt. 
The collector is used to emit or output the tuples from this bolt.