Available

amalgame-kafka

Apache Kafka via librdkafka. Producer + Consumer + groups.

amc package add kafka GitHub ↗ ← Back to the ecosystem

Overview

The package links to librdkafka, the reference Kafka C client, which must be installed on the machine. It works with brokers reachable without TLS or SASL: Apache Kafka, Redpanda, Confluent Platform.

Features

  • ✓Producer: Send (key, value, partition) and Flush
  • ✓Group consumer, manual offset commit (CommitSync)
  • ✓One topic per subscription
  • ✓Needs librdkafka-dev to build, librdkafka1 to run (Debian, Ubuntu)

Planned for v2: TLS and SASL, several topics per subscription, transactions, record headers.

Example

Minimal usage example — copy-paste runnable after install.

amc package add kafka

import Amalgame.Messaging.Kafka

public class Program {
    public static void Main(string[] args) {
        let p = Kafka.ProducerNew("broker1:9092,broker2:9092")
        Kafka.Send(p, "user-events", "user-42", "login", 0 - 1)
        Kafka.Flush(p, 5000)
        Kafka.ProducerClose(p)

        let c = Kafka.ConsumerNew("broker1:9092,broker2:9092", "my-group")
        Kafka.Subscribe(c, "user-events")
        if (Kafka.Poll(c, 5000)) {
            Console.WriteLine(Kafka.LastTopic(c) + "/" + Kafka.LastKey(c) + " = " + Kafka.LastValue(c))
            Kafka.CommitSync(c)
        }
        Kafka.ConsumerClose(c)
    }
}

At a glance

Related packages