我有一个 rabbitMQ 连接,它似乎是在编译时启动的(当我输入lein compile时),然后阻止了我的项目的构建。以下是有关该问题的更多详细信息。假设这是 clojure 文件bla_test.clj
(import (com.rabbitmq.client ConnectionFactory Connection Channel QueueingConsumer))
;; And then we have to translate the equivalent java hello world program using
;; Clojure's excellent interop.
;; It feels very strange writing this sort of ceremony-oriented imperative code
;; in Clojure:
;; Make a connection factory on the local host
(def connection-factory
(doto (ConnectionFactory.)
(.setHost "localhost")))
;; and get it to make you a connection
(def connection (.newConnection connection-factory))
;; get that to make you a channel
(def channel (. connection createChannel))
;;HERE I WOULD LIKE TO USE THE SAME CONNECTION AND THE SAME CHANNEL INSTANCE AS OFTEN AS
;; I LIKE
(dotimes [ i 10 ]
(. channel basicPublish "" "hello" nil (. (format "Hello World! (%d)" i) getBytes)))
上面的 clojure 文件是我使用lein构建的更大的 clojure 程序的一部分。我的问题是,当我用“lein compile”编译时,由于线路的原因,连接完成 (def connection (.newConnection connection-factory))
,然后编译停止!我怎样才能避免这种情况?有没有办法在不建立连接的情况下进行编译?如何在来自外部组件的多个调用中使用相同的通道实例?
任何帮助,将不胜感激。问候,贺拉斯