【问题标题】:Clojure Storm FluxClojure 风暴通量
【发布时间】:2016-05-23 11:57:46
【问题描述】:

我最近开始使用Apache Storm。我将 Storm 与 Clojure Storm DSLLeiningen 一起使用。

有一个很酷的风暴拓扑管理工具:Storm Flux

我的问题是:当我使用 clojure 在 Storm 中编码时,如何使用 Flux?

【问题讨论】:

  • 我不确定,但我猜你需要将你的 clojure 代码编译成类文件(对于每个 spout、bolt),这样你就可以在flux中使用这些类文件。
  • 感谢@MatthiasJ.Sax,我尝试了这个解决方案,但我错过了一些东西。在我的 ns 中,我使用 :gen-class,例如我的 defspout 宏。但是编译后的文件并没有拿IRichSpout对象来生成类:(你明白了吗?
  • 或者你有一个小例子?
  • 你需要继承使用reify的接口。见stackoverflow.com/questions/8614734/…
  • @MatthiasJ.Sax 你觉得这个解决方案怎么样?我不能使用 reify,因为在运行时间之前我需要一个类

标签: clojure apache-storm apache-storm-flux


【解决方案1】:

我找到了解决办法:

(ns your.namespace.boltname
  (:use
    [org.apache.storm clojure config])
  (:gen-class :implements [org.apache.storm.topology.IRichBolt]))

(defbolt my-bolt
         ["data"]
         [tuple collector]
         (emit-bolt! collector [(f (.getString tuple 0))] :anchor tuple)
         (ack! collector tuple))

(defn -execute [this tuple]
 (.execute my-bolt tuple))

(defn -prepare [this conf context collector]
 (.prepare my-bolt conf context collector))

(defn -cleanup [this]
 (.cleanup my-bolt))

(defn -declareOutputFields [this output]
 (.declareOutputFields my-bolt output))

(defn -getComponentConfiguration [this]
 (.getComponentConfiguration my-bolt))

别忘了将:aot :all 添加到your project.clj

在你的变化中topology.yaml 类似:

...
bolts:
  - id: "myBolt"
    className: "your.namespace.boltname"
    parallelism: 1
...

就是这样:)

【讨论】:

  • @MatthiasJ.Sax 你觉得这个解决方案怎么样?我不能使用 reify,因为在运行时间之前我需要一个类
猜你喜欢
  • 1970-01-01
  • 2015-01-22
  • 1970-01-01
  • 1970-01-01
  • 2016-12-28
  • 2023-04-04
  • 1970-01-01
  • 2016-01-08
  • 1970-01-01
相关资源
最近更新 更多