Skip to content

Getting Started

akshat edited this page Oct 20, 2023 · 11 revisions

System Requirements

Adding Goose as a dependency

Clojars Project

;;; Clojure CLI/deps.edn
com.nilenso/goose {:mvn/version "0.4.0"}

;;; Leiningen/Boot
[com.nilenso/goose "0.4.0"]

Enqueuing a job

(ns my-app
  (:require
    [goose.brokers.redis.broker :as redis]
    [goose.client :as c]))

(defn my-fn
  [arg1 arg2]
  (println "my-fn called with" arg1 arg2))

(let [redis-producer (redis/new-producer redis/default-opts)
      ;; Along with Redis, Goose supports RabbitMQ as well.
      client-opts (assoc c/default-opts :broker redis-producer)]
  ;; Supply a fully-qualified function symbol for enqueuing.
  ;; Args to perform-async are variadic.
  (c/perform-async client-opts `my-fn "foo" :bar)
  (c/perform-in-sec client-opts 900 `my-fn "foo" :bar))

Dequeuing a job

(ns my-worker
  (:require
    [goose.brokers.redis.broker :as redis]
    [goose.worker :as w]))

;;; 'my-app' namespace should be resolvable by worker.
(let [redis-consumer (redis/new-consumer redis/default-opts)
      ;; Along with Redis, Goose supports RabbitMQ as well.
      worker-opts (assoc w/default-opts :broker redis-consumer)
      worker (w/start worker-opts)]
  ;; When shutting down worker...
  (w/stop worker))  ; Performs graceful shutsdown.

Advanced Steps

Refer to relevant wikis for Broker Config, Worker Config, Scheduling a Job, Error Handling & Retries, Middleware linked on the home page.

Goose Jobs can be managed using API as well.


Previous: Basic Setup        Next: Message Brokers