2016-05-23 39 views
2

最近我開始使用Apache Storm。我使用Storm Clojure Storm DSLLeiningenClojure Storm Flux

風暴拓撲管理有一個很酷的工具:Storm Flux

我的問題是:當我用clojure編碼時如何使用flux?

+0

我不知道,但我猜你需要編譯的Clojure代碼到類文件(每個噴口,螺栓),所以你可以在流量中使用這些類文件。 –

+0

謝謝@ MatthiasJ.Sax,我嘗試這個解決方案,但我錯過了一些東西。在我的ns中,我使用:gen-class,例如我有我的defspout宏。但編譯後的文件沒有將IRichSpout對象生成爲:(你知道嗎? –

+0

或者你可能有一個小例子嗎? –

回答

0

我找到了一個解決方案:

(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 :allyour project.clj

而在你的流量topology.yaml是這樣的:

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

這是所有:)

+0

@ MatthiasJ.Sax你對這個解決方案有什麼看法?我不能使用reify,因爲在運行時間之前我需要一個類 –