RQ (Redis Queue) is a simple Clojure package for queueing jobs and processing them in the background with workers. It is backed by Redis and it is designed to have a low barrier to entry, inspired by python-rq.
"simple is better than complex" - The Zen of Python
clj-rq arose from the need to simplify the use of the redis queue feature used in the SaaS version of moclojer, here's a more detailed explanation of the motivation (a thread that generated controversy)
We distribute the library via Clojars.
com.moclojer/rq {:mvn/version "0.x.x"}
[com.moclojer/rq "0.x.x"]
see the versions distributed on clojars
(ns rq.example
(:require [com.moclojer.rq :as rq]
[com.moclojer.rq.queue :as queue]
[com.moclojer.rq.pubsub :as pubsub]))
(def *redis-pool* (rq/create-client "redis://localhost:6379/0"))
;; queue
(queue/push! *redis-pool* "my-queue" {:now (java.time.LocalDateTime/now)
:foo "bar"})
(println :size (queue/llen *redis-pool* "my-queue"))
(prn :popped (queue/pop! *redis-pool* "my-queue"))
;; pub/sub
(def my-workers
[{:channel "my-channel"
:handler (fn [msg]
(prn :msg :my-channel msg))}
{:channel "my-other-channel"
:handler (fn [{:keys [my data hello]}]
(my-function my data hello))}])
(pubsub/subscribe! *redis-pool* my-workers)
(pubsub/publish! *redis-pool* "my-channel" "hello world")
(pubsub/publish! *redis-pool* "my-other-channel" {:my "moclojer team"
:data "app.moclojer.com"
:hello "maybe you'll like this website"})
(rq/close-client *redis-pool*)
The workflow in the given example can be represented as follows:
sequenceDiagram
participant User
participant Client
participant Queue
participant PubSub
participant Logger
User->>Client: create-client URL
Client-->>Logger: log client creation
Client-->>User: return client
User->>Queue: push! message
Queue-->>Logger: log push message
Queue-->>Queue: push message to queue
User->>PubSub: publish! channel, message
PubSub-->>Logger: log publish message
PubSub-->>PubSub: publish message to channel
User->>Queue: pop! queue-name
Queue-->>Logger: log pop operation
Queue-->>User: return popped message
User->>Client: close-client client
Client-->>Logger: log closing client
Client-->>User: confirm client closure
Can you improve this documentation? These fine people already did:
Avelino & J0sueTMEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close