databases
Kafka
Provision and connect to a managed Kafka broker.
Runix provisions an Apache Kafka broker with optional Kafka UI. Use it for event streaming, log aggregation, and decoupling microservices.
Provisioning#
services:
- name: events
type: kafka
- name: producer
type: web-service
repo: https://github.com/alice/order-service
env:
KAFKA_BROKER: "${events.connection_string}"
- name: consumer
type: background-worker
repo: https://github.com/alice/notification-service
env:
KAFKA_BROKER: "${events.connection_string}"Connection String#
events:9092The broker is accessible at `<service-name>:9092` from other services in the same deployment.
Topics#
Kafka topics are created automatically when a producer sends its first message to a topic. You can also create and manage topics through Kafka UI if it is enabled.
Producer / Consumer Examples#
Producer (kafkajs)
const { Kafka } = require("kafkajs");
const kafka = new Kafka({
brokers: [process.env.KAFKA_BROKER],
});
const producer = kafka.producer();
await producer.connect();
await producer.send({
topic: "orders",
messages: [
{ key: "order-1", value: JSON.stringify({ item: "Widget", qty: 3 }) },
],
});Consumer (kafkajs)
const { Kafka } = require("kafkajs");
const kafka = new Kafka({
brokers: [process.env.KAFKA_BROKER],
});
const consumer = kafka.consumer({ groupId: "notifications" });
await consumer.connect();
await consumer.subscribe({ topic: "orders", fromBeginning: true });
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
console.log(message.value.toString());
},
});Kafka UI#
On Pro and Business plans, a web-based Kafka UI is provisioned alongside your broker. It lets you browse topics, view messages, inspect consumer groups, and manage the cluster through a visual interface.
Kafka UI is not available on Hobby or Starter plans. Upgrade to Pro or Business to access it.