【问题标题】:Code serializing deserializing from Clojure从 Clojure 序列化反序列化的代码
【发布时间】:2014-02-13 23:39:19
【问题描述】:

我正在关注http://patternhatch.com/2013/06/12/messaging-using-clojure-and-zeromq/这里的示例

我已经验证我可以序列化 MarketData 并为它构建了 protobuf。

我决定尝试我新学到的 protobuf 序列化知识,而不是使用 chesire 序列化。当我将该示例中的函数修改为它们的 gpb 版本时,当我运行

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

好像没问题。但是,当我运行客户端时

(get-market-data-gpb 100)

什么都没有发生。我有两个问题:

1) Clojure 是否有某种图形或其他调试器? 2)如果有人可以指出我在修改后的示例中做错了什么,那也将有所帮助。

我似乎记得通过带有 [protobuf] 二进制数据有效负载的 ZMQ 需要一组不同的调用?

(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)))

【问题讨论】:

    标签: clojure protocol-buffers zeromq


    【解决方案1】:

    Eclipse 逆时针和 IntelliJ Cursive 都支持 Clojure 调试。

    另外,您的地址看起来很糟糕 - 应该是“tcp://127.0.0.1:6666”。

    【讨论】:

    • 谢谢,我会调查这些。我确实有那个错误,我纠正了它(并修改了上面的帖子以反映它)程序仍然只是坐在那里,什么也不做。
    • 仍然不确定为什么此代码不起作用。我如何获取 protobuf-dump 创建的消息大小(以字节为单位),然后添加到该大小(以字节为单位)?
    • 我开始相信 jeromq 不够强大,无法处理二进制消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2020-06-03
    相关资源
    最近更新 更多