How to Configure Message Brokers
This guide explains how to connect Lemline to a message broker. Runners exchange workflow steps through the broker, and workflows publish and receive CloudEvents through it.
Supported Message Brokers
Broker |
| Use |
|---|---|---|
Kafka |
| Production, high throughput |
RabbitMQ |
| Production |
PGMQ (PostgreSQL Message Queue) |
| Production without a dedicated broker; runs on a standard PostgreSQL, no extension needed |
SQLite |
| Single host without a broker or a queue server; messages are kept in a local file |
In-memory |
| Single process only, for local tests |
If lemline.messaging.type is not set, Lemline uses the broker whose settings block (lemline.messaging.kafka, rabbitmq or pgmq) is present, and in-memory messaging when there is none. SQLite is never selected this way: set type: sqlite explicitly. At startup, the runner checks that the broker is reachable and stops with an explicit error if it is not.
Kafka Configuration
When both sasl-username and sasl-password are set, Lemline configures the PLAIN login module and defaults sasl-mechanism to PLAIN.
Each channel (commands, events, cloudevents, lifecycleevents) accepts consumer.group-id, consumer.offset-reset (earliest or latest) and consumer.concurrency.
RabbitMQ Configuration
Lemline declares its exchanges and queues itself. Each channel accepts consumer.concurrency, consumer.queue-dlq and, for commands, events and cloudevents, a queue name override.
PGMQ Configuration
SQLite Configuration
All Lemline processes that share the queue must run on the same host and open the same file. A relative path is resolved against the directory each process is started from, so prefer an absolute path. The parent directory must already exist; Lemline creates the file and its tables itself.
A message that a runner holds longer than visibility-timeout is delivered again to another consumer. Raise it above the longest time one workflow step can take, for example a slow HTTP call.
Destination Names
Lemline derives destination names from the namespace of each workflow:
<prefix>islemline.messaging.prefix(defaultlemline).<type>iscommands,eventsorcloudevents.
For example, workflows of the default namespace use lemline-default-commands. Topic names cannot be set per channel. Lifecycle events go to a single shared destination, lemline-lifecycle-events by default (lemline.messaging.<broker>.lifecycleevents.topic or .queue).
A runner only consumes the namespaces listed in lemline.namespaces (default: default).
Dead-Letter Destinations
A message that cannot be processed is moved to a dead-letter destination named after its source with a .dlq suffix, for example lemline-default-commands.dlq. With PGMQ and SQLite, a message goes there after max-retries deliveries.
Consumer Concurrency
Each runner processes up to 64 messages in parallel per channel. Change it per channel, under the broker you use:
The broker-independent lemline.messaging.<channel>.consumer.concurrency only applies to in-memory messaging; with a broker it is overwritten by lemline.messaging.<broker>.<channel>.consumer.concurrency. To process more messages, start more runners: they share the work.
Implementing Event-Driven Workflows
Both examples run on the SQLite setup, whose messaging channel carries the events. With the JAR, substitute java -jar lemline.jar for bin/lemline. Save them as emitting-events.yaml and listening-for-events.yaml. The listener is started by an event, so register both before the worker starts: stop the setup worker with Ctrl+C, then run from the setup directory:
From a second terminal in the setup directory, emit one event:
About 10 seconds later, the event starts a shipping-workflow instance that completes with {"received":[{"orderId":"ORD-1001"}]}: the worker picks up events for event-started workflows every 10 seconds.
Emitting Events
emit tasks publish a CloudEvent on the cloudevents destination of the workflow's namespace:
Listening for Events
listen tasks wait for CloudEvents received on the same destination. A workflow can also be started by an event with schedule.on:
See Listen behavior.
Testing with the In-Memory Broker
Messages only travel inside one process and are lost when it stops, so a separate lemline instance start cannot reach a lemline listen runner through it. Use it for tests that run everything in one process only.
Common Issues and Solutions
The runner stops at startup with a broker error
Check the host and port (
brokersfor Kafka,hostnameandportfor RabbitMQ,hostandportfor PGMQ).Check credentials and network access.
For PGMQ, check that the database migrations have run (
lemline migrate, orlemline migrate statusto list them): they create thepgmqschema and functions in SQL, without the PostgreSQL extension, so managed PostgreSQL services work too.
Messages are not processed
Check that a runner is running (
lemline listen) and serves the workflow's namespace (lemline.namespaces).Check the
.dlqdestinations for messages that failed.With Kafka, check that runners sharing the work use the same
group-id.
Processing is slow
Start more runners.
Increase
lemline.messaging.<broker>.<channel>.consumer.concurrencyif runners have spare CPU.
Best Practices
Set
lemline.messaging.typeexplicitly in production.Monitor the
.dlqdestinations.Use TLS and authentication on the broker connection (
security-protocoland SASL for Kafka,ssl-enabledfor RabbitMQ).Pass passwords as environment variables, for example
LEMLINE_MESSAGING_KAFKA_SASL_PASSWORD.