不变侦听器的 XA 上下文

XA context for immutant listener

我正在尝试使用 immutant 来管理跨 HornetQ 和 mysql 的事务。据我了解文档,要做到这一点,我必须使用 XA 事务,因为我 运行 是一个独立的应用程序,而不是在应用程序服务器中。

但是,当我尝试设置 :xa 时?对于我的应用程序的上下文,我在绑定设置侦听器时遇到异常。

(ns example
  (:require [immutant.messaging :as msg]))

(def capture (atom nil))
(let [ctx (msg/context :host "localhost" :xa? true)
      queue (msg/queue "example" :context ctx)]
  (reset! capture nil)
  (msg/listen queue (fn [m] (reset! capture m)))
  (msg/publish queue {:my :msg}))

这会从 (msg/listen) 调用中抛出 "java.lang.IllegalStateException: You can't create a child context from an XA context."。我做错了什么?

我想你已经发现了一个 bug, but in your case, I think there's a workaround: you only need that :xa? true option if your queue is remote. You can still create an XA transaction binding your HornetQ actions to MySQL in your listener handler using the immutant.transactions/transaction macro. See the docs 的例子。