Liking cljdoc? Tell your friends :D

tiny-queue

A Clojure library that implements message queue with Datomic.

Build Status

Installation

Leiningen coordinates:

[io.spinney/tiny-queue "1.0.10"]

Usage

The library provides wrap-background-job function, which can be used to start the message queue. This function requires your configuration in the form:

 {:object-db-conn datomic-db-connection
  :tiny-queue-db-conn datomic-db-connection
  :q d/q
  :db d/db
  :transact d/transact-async
  :tiny-queue-processors {}}

Where d is one of datomic.api, datomic.client.api. The most important part of the configuration is tiny-queue-processors. It should be a map with db idents as keys and functions as values.

Examples

To start message queue You should do following steps:

  1. Create config:
(require '[datomic.api :as d])
(def conn (d/connect "your-datomic-db-uri"))
(def config 
  {:object-db-conn conn
   :tiny-queue-db-conn conn
   :q d/q
   :db d/db
   :transact d/transact-async
   :tiny-queue-processors {}})
  1. Transact tiny-queue schema:
(tq/create-schema config)
  1. Define your first custom job (first argument is a keyword - :db/ident, second argument is a doc string):
(tq/define-new-job config :qcommand/first-job "My first job!")
  1. Define first job processor (processor should return Datomic transaction):
(defn first-job-processor [tiny-queue-db-snapshot object-db-snapshot job uuid]
  (println "Processing first job" uuid)
  {:object-db-transaction []
   :tiny-queue-db-transaction []})
  1. Define proper tiny-queue-processors:
(def tiny-queue-processors {:qcommand/first-job first-job-processor})
  1. Start tiny-queue using wrap-background-job:
(require '[tiny-queue.core :as tq])
(def final-config (assoc config :tiny-queue-processors tiny-queue-processors))
(def background-processor (atom nil))
(reset! background-processor (future (tq/wrap-background-job final-config 0)))
  1. Add new job to the tiny-queue:
(tq/create-new-job final-config {:command :qcommand/first-job
                                 :data "first-job-data"})

License

Copyright © 2022 Spinney

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close