shibuya-kafka-adapter: Kafka adapter for the Shibuya queue processing framework

[ concurrency, library, mit, streaming ] [ Propose Tags ] [ Report a vulnerability ]

A Shibuya adapter that integrates with Apache Kafka via kafka-effectful and hw-kafka-client. Provides polling, offset commit semantics, partition awareness, and graceful shutdown.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.4.0.0, 0.5.0.0, 0.5.0.1, 0.6.0.0, 0.7.0.0, 0.8.0.1
Change log CHANGELOG.md
Dependencies base (>=4.21.0.0 && <4.22), bytestring (>=0.12 && <0.13), containers (>=0.7 && <0.8), effectful-core (>=2.6.1.0 && <2.7), hs-opentelemetry-api (>=1.0 && <1.1), hs-opentelemetry-semantic-conventions (>=1.40 && <1.41), hw-kafka-client (>=5.3 && <6), hw-kafka-streamly (>=0.2 && <0.3), kafka-effectful (>=0.3.0.0 && <0.4), shibuya-core (>=0.8.0.1 && <0.9), stm (>=2.5 && <2.6), streamly (>=0.11 && <0.12), streamly-core (>=0.3 && <0.4), text (>=2.1 && <2.2), time (>=1.14 && <1.15), unordered-containers (>=0.2 && <0.3) [details]
Tested with ghc ==9.12.2
License MIT
Copyright 2026 Nadeem Bitar
Author Nadeem Bitar
Maintainer nadeem@gmail.com
Uploaded by shinzui at 2026-07-05T15:48:15Z
Category Concurrency, Streaming
Home page https://github.com/shinzui/shibuya-kafka-adapter
Bug tracker https://github.com/shinzui/shibuya-kafka-adapter/issues
Source repo head: git clone https://github.com/shinzui/shibuya-kafka-adapter.git
Distributions
Downloads 39 total (19 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for shibuya-kafka-adapter-0.8.0.1

[back to package description]

shibuya-kafka-adapter

Kafka adapter for the Shibuya queue-processing framework.

Integrates with Apache Kafka via kafka-effectful for the consumer effect (polling, offset store, partition pause) and hw-kafka-streamly for error classification (skipNonFatal), on top of hw-kafka-client. Provides polling, offset commit semantics, partition awareness, and graceful shutdown.

Runtime Contract

Run this adapter with serial message processing only. librdkafka stores the highest offset per partition and does not track gaps, so concurrent finalization can commit past an earlier message that failed, halted, or requested retry. The adapter cannot inspect the processor concurrency policy at construction time; avoiding Async and Ahead processing is a caller contract until a gap-tracking commit layer exists.

Offset reset policy belongs to the Subscription passed to runKafkaConsumer, for example topics [TopicName "orders"] <> offsetReset Earliest. KafkaAdapterConfig.topics is metadata used for adapter naming and a construction-time warning if it differs from the live subscription.

AckRetry seeks the partition back to the failed message and does not store that message's offset. AckDeadLetter stores the offset so the consumer group moves on, prints [shibuya-kafka-adapter] WARNING: dead-lettered message DROPPED to stderr, and makes the message unrecoverable from the group's committed position. This adapter does not include a DLQ producer.

Kafka does not expose a per-message delivery-attempt counter through this consumer API, so Envelope.attempt is always Nothing. Handlers that need bounded retries must use their own store or return AckHalt to stop the stream.

AckHalt pauses the originating partition and stops the processor. Polling then stops; after max.poll.interval.ms (librdkafka default: 300000 ms, or 5 minutes) the broker may evict this consumer and rebalance the partition to another group member. A single-member group stalls until restart.

On shutdown, the adapter commits offsets stored so far and signals the source stream to stop. Let the surrounding runKafkaConsumer scope end normally after stopping the app so the consumer close path can flush offsets stored during the drain window.

For rebalance visibility, create state with newKafkaAdapterState, install Kafka.Consumer.setCallback (Kafka.Consumer.rebalanceCallback (kafkaRebalanceHandler state)) before consumer creation, and pass the same state to kafkaAdapterWith. The helper logs rebalance events and clears retry barriers for revoked partitions; in-flight fencing for cooperative rebalances is out of scope.

Packages

  • shibuya-kafka-adapter — the adapter library (Shibuya.Adapter.Kafka, .Config, .Convert).
  • shibuya-kafka-adapter-bench — micro-benchmarks for the conversion hot path (ConsumerRecordEnvelope, W3C header extraction, timestamps).
  • shibuya-kafka-adapter-jitsurei — runnable examples: BasicConsumer, MultiTopic, MultiPartition, OffsetManagement.

Tracing

Tracing is handled by shibuya-core's supervised runner. Shibuya.Adapter.Kafka.Convert.consumerRecordToEnvelope populates Envelope.attributes with messaging.system=kafka and the Kafka-specific typed attributes messaging.kafka.destination.partition (Int64) and messaging.kafka.message.offset (Int64). The framework merges those onto its single Consumer-kind per-message span alongside messaging.destination.name, messaging.operation.type=process, and messaging.message.id.

The old opt-in Shibuya.Adapter.Kafka.Tracing module was removed in 0.5.0.0; callers should run the Kafka adapter through Shibuya's normal runApp or runWithMetrics path instead of wrapping the stream.

Building

The repo ships a Nix flake and direnv config for a reproducible toolchain.

direnv allow        # or: nix develop
cabal build all
cabal test shibuya-kafka-adapter

Benchmarks and examples:

cabal bench shibuya-kafka-adapter-bench
cabal run BasicConsumer

Layout

shibuya-kafka-adapter/            library sources and tests
shibuya-kafka-adapter-bench/      tasty-bench micro-benchmarks
shibuya-kafka-adapter-jitsurei/   runnable usage examples
docs/plans/                       execution plans
mori.dhall                        project manifest (mori registry)

License

MIT. See package cabal files for details.