如何使用python螺栓在风暴爬虫?

bpsygsoo  于 2021-06-24  发布在  Storm
关注(0)|答案(2)|浏览(353)

我有一些用python编写的图像分类器。web上提供了许多示例,这些示例描述了在storm bolt中使用python的方法,storm bolt使用stdin/stdout。我想将我的python图像分类器与storm crawler拓扑集成。有没有可能?
谢谢

2ul0zpep

2ul0zpep1#

确实有可能,几年前就做过这样的工作,将带有tensorflow的图像分类器集成到stormcrawler拓扑中。我记不住细节了,我为客户编写了代码,但它是基于multilang协议的,不幸的是,我记不住细节了。

iyr7buue

iyr7buue2#

是的,你可以。如果您使用的是flux,这是一个关于如何在拓扑中使用python螺栓的示例定义:

- id: "pythonbolt"
    className: "org.apache.storm.flux.wrappers.bolts.FluxShellBolt"
    constructorArgs:
      - ["python", "/absolute/path/to/your/python_file.py"]
      # declare your outputs here:
      - ["output0", "output1", "output2"]
    parallelism: 1

注意:确保向python bolt发出简单的数据类型(比如string、integer等)。不是java数据类型,否则会抛出错误!首次下载storm.py表单
在这里
这是一个python螺栓示例:

import storm

class SampleBolt(storm.BasicBolt):
    # Initialize this instance
    def initialize(self, conf, context):
        self._conf = conf
        self._context = context

    def process(self, tup):
        # Some processes here, and then emit your outputs.
        storm.emit([output0, output1, output2])

# Start the bolt when it's invoked

SampleBolt().run()

相关问题