我正在尝试创建一个混合的storm拓扑,它使用基于java的spout和基于python的bolt。
对于基于python的bolt,我编写了一个java Package 器:
class PythonBolt extends ShellBolt implements IRichBolt {
public PythonBolt() {
super("python", "C:\\somepath\\sample.py");
}
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
}
@Override
public Map<String, Object> getComponentConfiguration() {
return null;
}
}
我的sample.py就是这样的:
进口风暴
class SplitSentenceBolt(storm.BasicBolt):
def process(self, tup):
print("Python rocks!")
words = tup.values[0].split(" ")
print(tup.values[0])
SplitSentenceBolt().run()
然后我将所有这些放在一起,并尝试通过以下代码段运行:
public class SampleBolt {
public static void main(String[] args) throws Exception {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("Hello", new RawDataLevelSpout(), 12);
builder.setBolt("World", new PythonBolt(), 12);
Config config = new Config();
config.setDebug(true);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("Hello-World-BaiJian", config, builder.createTopology());
Utils.sleep(100000);
cluster.killTopology("Hello-World-BaiJian");
cluster.shutdown();
}
}
但是,我得到了以下例外:
import storm
ModuleNotFoundError: No module named 'storm'
at org.apache.storm.utils.ShellProcess.launch(ShellProcess.java:94) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
at org.apache.storm.task.ShellBolt.prepare(ShellBolt.java:154) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
at org.apache.storm.executor.bolt.BoltExecutor.init(BoltExecutor.java:84) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
at org.apache.storm.executor.bolt.BoltExecutor.call(BoltExecutor.java:93) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
at org.apache.storm.executor.bolt.BoltExecutor.call(BoltExecutor.java:45) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
at org.apache.storm.utils.Utils$2.run(Utils.java:329) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
关于如何克服这个问题有什么提示吗?如何安装python风暴包?是否可以通过anaconda安装它(我找不到包)?
2条答案
按热度按时间jljoyd4f1#
当您从ide运行localcluster时,我不确定multilang支持是否适用于它。看到了吗https://stackoverflow.com/a/32085316/8845188. 这个答案后面的对话中似乎提到了一个解决办法。
ht4b089n2#
只为未来的人-信息非常准确。我只是错过了sample.py所在文件夹中的storm.py。只需添加以下文件:https://github.com/apache/storm/blob/v1.2.1/storm-multilang/python/src/main/resources/resources/storm.py 到那个文件夹解决了问题!也可以通过localcluster运行此代码。