Skip to content

feat: Added an implementation of Kafka Binding#114

Merged
dazuma merged 18 commits intocloudevents:mainfrom
dazuma:pr/kafka
Feb 10, 2026
Merged

feat: Added an implementation of Kafka Binding#114
dazuma merged 18 commits intocloudevents:mainfrom
dazuma:pr/kafka

Conversation

@dazuma
Copy link
Member

@dazuma dazuma commented Feb 9, 2026

Done in collaboration with Claude Code.
Closes #80.

dazuma and others added 12 commits February 9, 2026 11:56
…ration

Scaffold the KafkaBinding class with initialize, self.default singleton,
DEFAULT_KEY_MAPPER/DEFAULT_REVERSE_KEY_MAPPER constants, and formatter
registration methods mirroring HttpBinding. Add require to cloud_events.rb
and constructor unit tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Quick header-only check to determine if a Kafka message is likely a
CloudEvent (checks for ce_specversion header or application/cloudevents
content-type).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Decode CloudEvents from Kafka messages in binary content mode. Supports
text/JSON data decoding, extension attributes, tombstones (nil value),
configurable reverse_key_mapper for partition key mapping, and proper
error handling for bad specversion and non-CE messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Decode CloudEvents from Kafka messages in structured content mode.
Supports JSON format, charset variants, opaque fallback for unrecognized
formats, and reverse_key_mapper application to structured events.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Encode CloudEvents to Kafka messages in binary content mode. Supports
text/JSON data encoding, extension attributes, tombstones (nil value for
no data), and configurable key_mapper for partition key derivation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Encode CloudEvents to Kafka messages in structured content mode using
named format encoders. Supports opaque event passthrough and key_mapper
in structured mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Verify encode-then-decode round trips for binary mode, structured mode,
and with partitionkey extension attribute.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Replace pending Kafka steps with real implementations that decode Kafka
messages using KafkaBinding.default. All 7 conformance scenarios (HTTP
and Kafka) now pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Use parenthesized raise calls, move constant above private modifier,
extract populate_data_attributes to reduce method length, and fix
SymbolProc offense in tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Kafka protocol binding to the CloudEvents Ruby SDK, enabling encoding/decoding CloudEvents to/from Kafka message hashes (binary and structured modes), and wires it into the library plus conformance steps/tests.

Changes:

  • Introduces CloudEvents::KafkaBinding with binary/structured encoding & decoding, tombstone handling, and configurable key mapping.
  • Adds a comprehensive Minitest suite covering Kafka binding behavior and round-trips.
  • Updates Cucumber step definitions and project docs to reflect Kafka binding support, and requires the binding from cloud_events.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/cloud_events/kafka_binding.rb New Kafka binding implementation (encode/decode, formatter registry, key mapping).
lib/cloud_events.rb Requires the new Kafka binding so it’s available via require "cloud_events".
test/test_kafka_binding.rb New unit tests validating Kafka binding behavior across modes and edge cases.
features/step_definitions/steps.rb Enables Kafka binding in conformance steps (no longer pending).
CLAUDE.md Documents Kafka binding capabilities and usage patterns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

dazuma and others added 5 commits February 9, 2026 14:55
Replace raw string comparison with ContentType parsing so that
mixed-case content-type values (e.g. Application/CloudEvents+JSON)
are correctly detected as CloudEvents.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Add BatchNotSupportedError to the error hierarchy and raise it from
KafkaBinding#decode_event when given an application/cloudevents-batch
content type, since the Kafka protocol binding does not support batch
content mode per the spec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
The binary decode path already raised SpecVersionError for non-1.x spec
versions, but structured mode would accept and return a V0 event. Now
decode_structured_content checks the decoded event's spec_version and
raises SpecVersionError if it does not start with "1".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Raise SpecVersionError when encode_event receives an event with a
specversion that does not start with "1", ensuring V0.3 events cannot
be encoded via the Kafka binding.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Signed-off-by: Daniel Azuma <dazuma@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Daniel Azuma <dazuma@gmail.com>
@dazuma dazuma merged commit c2bd394 into cloudevents:main Feb 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add kafka binding

1 participant