Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

car-mq/enqueue throws Cannot invoke "java.util.concurrent.Future.get()" #255

Closed
theronic opened this issue Nov 18, 2021 · 4 comments
Closed

Comments

@theronic
Copy link

Running Clojure v1.10.3 and Redis v6.2.2, Carmine throws a NullPointerException when attempting to enqueue a message onto a message queue:

(require '[taoensso.carmine.message-queue :as car-mq])

(car-mq/worker {:pool {} :spec {}}
           "myqueue"
           {:handler (fn [{:keys [message attempt]}]
                       (log/info "Received" message)
                       {:status :success})})
;; workre starts successfully.

(car-mq/enqueue "myqueue" "hi there")
=> Execution error (NullPointerException) at taoensso.carmine.protocol/pull-requests (protocol.clj:288).
Cannot invoke "java.util.concurrent.Future.get()" because "fut" is null
@theronic
Copy link
Author

theronic commented Nov 18, 2021

Seems to be caused by @req-queue_ in protocol.clj, which lives in *context*:

(defn- pull-requests "Implementation detail" [req-queue_]
  (loop []
    (let [rq @req-queue_] ;; here
      (if (compare-and-set! req-queue_ rq [])
        rq
        (recur)))))

req_queue_ is destructured out of *context*, which ought to be an (atom []), dynamically bound by with-context:

(defmacro with-context "Implementation detail"
  [conn & body]
  `(binding [*context* (->Context ~conn (atom []))
             *parser*  nil]
     ~@body))

Not sure why req-queue_ is not set.

@ptaoussanis
Copy link
Member

@theronic Hi Petrus,

enqueue calls need to be made within the context of a Carmine connection, please see the README example.

Hope that helps!

@theronic
Copy link
Author

Ah, just figured out need to wrap in (wcar* ...) (other commands warn about this).
Thanks, @ptaoussanis :).

@ptaoussanis
Copy link
Member

No problem. The motivation for requiring an explicit context is that this choice allows pipelining of message queue commands just like any other Redis commands. This can be useful for performance and convenience / code readability.

In general, you can alway assume that a wcar is necessary for all Carmine Redis commands unless a docstring specifically says otherwise. It's rare (the exception) that a Carmine Redis command will do an automatic wcar since this reduces the flexibility mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants