Kest

Search

Search the documentation

Microservices

Redis

Use Redis pub/sub as the transport.

Redis is a fast in-memory server, and its publish/subscribe feature can carry messages. If you already run Redis for caching or sessions, this transport needs nothing new.

app.connectMicroservice(RedisOptions("redis-host", 6379))                 // a service: handlers answer messages
import(ClientsModule.register { client("CACHE", RedisOptions("redis-host", 6379)) })   // in the caller's module  // a caller
val total: Int? = client.send("sum", listOf(1, 2, 3))
  • Requests use a reply channel per request; events are published to the pattern's channel.
  • The subscriber reconnects with a growing pause (0.2 s to 3 s) and subscribes again after a Redis restart (tested).
  • Pub/sub does not store messages. If a service is down or disconnected when a message is published, it never receives it. For work that must not be lost, use a queue (also on Redis, but durable) or RabbitMQ/Kafka.
  • Every subscriber to a pattern gets the message: with several instances of one service each handles events. (NATS queue groups and Kafka consumer groups share the work instead.)

When to choose it

Simple setups, development, notifications where a lost message is acceptable. Not for must-not-lose work.

Your handlers are the same on every transport: see Overview. Compare all of them in Transports compared.

Read more