Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/msolli/proletarian/llms.txt

Use this file to discover all available pages before exploring further.

The Serializer protocol controls how job payloads travel between your application and the database. Proletarian stores job payloads in a TEXT column; the Serializer is responsible for converting any Clojure value to a string on write (encode) and converting that string back to the original value on read (decode). The default implementation uses Transit JSON via proletarian.transit/create-serializer. Namespace: proletarian.protocols

Protocol Definition

(defprotocol Serializer
  "The Serializer encodes and decodes the job data payload as it is written to
   and read from the database tables."
  (encode [_ data]
    "Encode the data as a string before writing.")
  (decode [_ data-string]
    "Decode the data-as-string after reading."))

Methods

encode
function
Called by proletarian.job/enqueue! before writing the payload to the database.
  • Arguments: _ (the serializer instance), data (any Clojure value)
  • Returns: a String representation of data
decode
function
Called by the worker when reading a job from the database, before passing the payload to handler-fn.
  • Arguments: _ (the serializer instance), data-string (a String as stored in the database)
  • Returns: the original Clojure value

Default Serializer

The default serializer is the Transit JSON serializer created by proletarian.transit/create-serializer. It handles all standard Clojure data types plus java.time.Instant out of the box. See the Transit serializer reference for details.

Implementing a Custom Serializer

Implement Serializer using reify and supply the instance via the :proletarian/serializer option in both enqueue! and create-queue-worker.

Example: JSON serializer with jsonista

(require '[jsonista.core :as json]
         '[proletarian.protocols :as p])

(defn create-json-serializer []
  (reify p/Serializer
    (encode [_ data] (json/write-value-as-string data))
    (decode [_ s] (json/read-value s json/keyword-keys-object-mapper))))

Registering the custom serializer

Pass the same instance to both enqueue! and create-queue-worker:
(require '[proletarian.job :as job]
         '[proletarian.worker :as worker])

(def my-serializer (create-json-serializer))

;; Enqueueing
(job/enqueue! conn :myapp/process-order {:order-id 123}
              :proletarian/serializer my-serializer)

;; Processing
(def queue-worker
  (worker/create-queue-worker datasource handle-job
    {:proletarian/serializer my-serializer}))

Example: EDN serializer

(require '[clojure.edn :as edn]
         '[proletarian.protocols :as p])

(defn create-edn-serializer []
  (reify p/Serializer
    (encode [_ data] (pr-str data))
    (decode [_ s] (edn/read-string s))))

Same Serializer on Both Sides

The serializer must be identical (in terms of encode/decode logic) on both the enqueue side and the worker side. Proletarian does not persist serializer metadata alongside each job row — there is no automatic detection of which serializer was used when a job was enqueued.
Changing the serializer for an existing queue while jobs are still pending will cause decode failures on those outstanding jobs. Any jobs written with the old serializer will not be readable by a worker using a different serializer, and the job processing will throw an exception. Migrate outstanding jobs or drain the queue before switching serializers.

Build docs developers (and LLMs) love