apache-storm mixed topology with python - ModuleNotFoundError: No module named 'storm'
apache-storm mixed topology with python - ModuleNotFoundError: No module named 'storm'
我正在尝试创建混合风暴拓扑,它使用基于 Java 的喷口和基于 python 的螺栓。
对于基于 python 的螺栓,我写了一个 Java 包装器:
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.run(Utils.java:329) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
关于如何克服这个问题的任何提示?如何安装 python 风暴包?可以通过Anaconda安装吗(我没找到包)?
当您从 IDE 中 运行 时,我不确定多语言支持是否适用于 LocalCluster。参见 。在该回答之后的对话中似乎提到了一个解决方法。
只为未来的人们 - 信息非常准确。我只是错过了我的 sample.py 所在的同一文件夹中的 storm.py。只需将以下文件:https://github.com/apache/storm/blob/v1.2.1/storm-multilang/python/src/main/resources/resources/storm.py 添加到该文件夹即可解决问题!
也可以通过 LocalCluster 运行 此代码。
我正在尝试创建混合风暴拓扑,它使用基于 Java 的喷口和基于 python 的螺栓。
对于基于 python 的螺栓,我写了一个 Java 包装器:
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.run(Utils.java:329) ~[storm-client-2.0.0-SNAPSHOT.jar:2.0.0-SNAPSHOT]
关于如何克服这个问题的任何提示?如何安装 python 风暴包?可以通过Anaconda安装吗(我没找到包)?
当您从 IDE 中 运行 时,我不确定多语言支持是否适用于 LocalCluster。参见
只为未来的人们 - 信息非常准确。我只是错过了我的 sample.py 所在的同一文件夹中的 storm.py。只需将以下文件:https://github.com/apache/storm/blob/v1.2.1/storm-multilang/python/src/main/resources/resources/storm.py 添加到该文件夹即可解决问题! 也可以通过 LocalCluster 运行 此代码。