Getting Started example errors

38 views
Skip to first unread message

Ian Rumford

unread,
Jul 1, 2015, 9:19:23 AM7/1/15
to clojur...@googlegroups.com
Hi Michael,

Just having a go with machine head and started following Getting Started  

But the very first example fails for me for two reasons:

1. the 2nd arg to subscribe needs to be map of topics and qoses
2. disconnecting is not allowed in a callback

(defn -main
  [& args]
  (let [id   (mh/generate-id)
        conn (mh/connect "tcp://127.0.0.1:1883" id)]
    (mh/subscribe conn ["hello"] (fn [^String topic _ ^bytes payload]
                                   (println (String. payload "UTF-8"))
                                   (mh/disconnect conn)
                                   (System/exit 0)))
    (mh/publish conn "hello" "Hello, world")))

I had to make a couple of changes:

(defn -main
  [& args]
  (let [id   (mh/generate-id)
        conn (mh/connect "tcp://172.17.0.1:1883" id)
        topics-and-qos {"hello" 0}]
    (mh/subscribe conn topics-and-qos (fn [^String topic _ ^bytes payload]
                                        (println (String. payload "UTF-8"))
                                        (System/exit 0)))
    (mh/publish conn "hello" "Hello, world")
    (mh/disconnect conn)))

It seems that some of the subsequent examples may have similar issues so I've not tried them yet.

BTW using beta9 + Clojure 1.7
Reply all
Reply to author
Forward
0 new messages