EzDevInfo.com

carmine

Clojure Redis client & message queue Taoensso.com

Strange behavior in carmine (clojure-redis client)

Consider this snippet in carmine

(wcar* (car/set "counter" 1)            ;; expect to be number counter=1
       (let [id (car/get "counter")]    ;; expect to have id=1
         (println id)))                 ;; [nil [[SET counter 1] [GET counter]]]

What I am doing wrong here? Is there a way to use let inside wcar* macro?


Source: (StackOverflow)

How should carmine's wcar macro be used?

I'm confused by how calls with carmine should be done. I found the wcar macro described in carmine's docs:

(defmacro wcar [& body] `(car/with-conn pool spec-server1 ~@body))

Do I really have to call wcar every time I want to talk to redis in addition to the redis command? Or can I just call it once at the beginning? If so how?

This is what some code with tavisrudd's redis library looked like (from my toy url shortener project's testsuite):

(deftest test_shorten_doesnt_exist_create_new_next 
  (redis/with-server test-server
    (redis/set "url_counter" 51)
    (shorten test-url)
    (is (= "1g" (redis/get (str "urls|" test-url))))
    (is (= test-url (redis/get "shorts|1g")))))

And now I can only get it working with carmine by writing it like this:

(deftest test_shorten_doesnt_exist_create_new_next
  (wcar (car/set "url_counter" 51))
    (shorten test-url)
    (is (= "1g" (wcar (car/get (str "urls|" test-url)))))
    (is (= test-url (wcar (car/get "shorts|1g")))))

So what's the right way of using it and what underlying concept am I not getting?


Source: (StackOverflow)

Advertisements

can't keep carmine mq worker open

I'm trying to implement a carmine worker in a constantly running process.

When launching the following app with lein run myclass.foo, it just starts the worker and stops it right away.

(def my-worker
  (car-mq/worker queue-server "my-queue"
   {:handler (fn [{:keys [message attempt]}]
               (println "Received" message)
               {:status :success})
    :auto-start false}))


(defn -main []
  (car-mq/start my-worker))

My goal is something like that

  • Launch the foo listener
  • foo listener runs in foreground and prints everything that gets posted to the queue
  • Ctrl-c / quit will close the listener

Source: (StackOverflow)

Integrate Spring-based Java application and Clojure library

We have a Spring 4.0-based web application running in Tomcat 8 (alternatively we have a start-up script for Undertow). Spring MVC is handling requests. I am looking for a way to defer some of request handling code to Clojure library, with minimal changes to legacy Java code.

For instance, requests with URLs ending with .java would be handled by legacy Java, and requests ending with .clj would be handled by Clojure. For now, i see three options:

  1. Include Clojure library jar in Java project's dependencies and use clojure.java.api to invoke Clojure code from Java.
  2. Use some sort of RPC/RMI or message queues, e.g. Redis and Carmine's message queue processing capabilities. This way, Clojure would live in a separate JVM.
  3. Use some sort of reverse proxy to perform URL routing.

Are above approaches actually feasible? What else would you suggest?

Thanks!


Source: (StackOverflow)