2014-02-13 47 views
1

串行解串我在這裏http://patternhatch.com/2013/06/12/messaging-using-clojure-and-zeromq/代碼從Clojure的

follwing的例子我已驗證我可以序列MarketData並建成的protobuf它。除了使用chesire系列化

我決定試試我新學到的protobuf序列化的知識。當我修改該示例中的功能集成到他們的GPB版本,當我運行

(future-call market-data-publisher-gpb) 

它似乎確定。但是,當我運行客戶端

(get-market-data-gpb 100) 

沒有任何反應。我有兩個問題:

1)是否有某種形式的Clojure的圖形或其他調試器? 2)如果有人可以指出我正確的方向,我在我的修改過的例子中做錯了什麼,這也會有所幫助。

我似乎記得在ZMQ用[protobuf的]二進制數據有效載荷需要一組不同的電話嗎?

(ns clj-zmq.core 
    (:import [org.jeromq ZMQ]) 
) 

(use 'flatland.protobuf.core) 

(import com.example.Example$MarketData) 
(def MarketData (protodef Example$MarketData)) 


(def ctx (ZMQ/context 1)) 

(defn market-data-publisher-gpb 
[] 
    (let [s (.socket ctx ZMQ/PUB) 
     market-data-event (fn [] 
          {:symbol (rand-nth ["CAT" "UTX"]) 
          :size (rand-int 1000) 
          :price (format "%.2f" (rand 50.0))})] 
    (.bind s "tcp://127.0.0.1:6666") 
    (while :true 
     (.send s (protobuf-dump(market-data-event)))))) 

; Client 
(defn get-market-data-gpb 
    [num-events] 
    (let [s (.socket ctx ZMQ/SUB)] 
    (.subscribe s "") 
    (.connect s "tcp://127.0.0.1:6666") 
    (dotimes [_ num-events] 
     (println (protobuf-load MarketData (.recv s)))) 
    (.close s))) 

回答

0

Eclipse逆時針和IntelliJ Cursive都支持Clojure調試。

而且,你的地址很糟糕 - 應該是 「TCP://127.0.0.1:6666」。

+0

謝謝我會研究這些。我確實有這個錯誤,我糾正它(並修改了上面的帖子來反映它),該程序仍然只是坐在那裏,什麼都不做。 – user1676605

+0

仍然不確定爲什麼這段代碼不起作用。我將如何獲得protobuf-dump創建的消息大小(以字節爲單位),然後預先確定以字節爲單位的大小? – user1676605

+0

我開始相信jeromq不足以處理二進制消息。 – user1676605