Skip to content

Feature/kafka client contract#149

Merged
bascunansalvador merged 10 commits into
feature/protobuf-java-payload-generationfrom
feature/kafka-client-contract
Jun 18, 2026
Merged

Feature/kafka client contract#149
bascunansalvador merged 10 commits into
feature/protobuf-java-payload-generationfrom
feature/kafka-client-contract

Conversation

@bascunansalvador

Copy link
Copy Markdown
Collaborator

The previous Spring Kafka generator still carried parts of the old full/simple client model. That made the configuration harder to reason about and left the generated client surface a bit unclear. Some generated artifacts behaved like runtime integration code, while other parts behaved like contract-only source artifacts.

This was risky because Spring Kafka applications can be configured in many different ways. Generating too much runtime wiring too early makes the output harder to use, harder to customize, and more likely to conflict with application-owned Kafka configuration.

For the proposed solution, Spring Kafka generation has been narrowed into a contract-first client surface.

The generator no longer exposes full/simple Spring Kafka modes. Kafka client generation is now configured under the Kafka capability, with Spring Kafka as an explicit nested capability. For example, Maven configuration now follows this shape:

<clients>
    <kafka>
        <packageName>com.example.client</packageName>
        <springKafka>
            <enabled>true</enabled>
            <producer>
                <enabled>true</enabled>
            </producer>
            <consumer>
                <enabled>true</enabled>
            </consumer>
        </springKafka>
    </kafka>
</clients>

The generated Spring Kafka output is now contract-only. Producer-oriented channels generate producer wrappers around an application-provided KafkaTemplate. Consumer-oriented channels generate consumer interfaces. The generator does not create Spring Boot auto-configuration, @KafkaListener classes, listener containers, serializer/deserializer setup, or schema registry configuration.

Producer methods now return the Spring Kafka send result future instead of hiding it. Generated methods return CompletableFuture<SendResult<String, PayloadType>>, which lets callers observe completion, errors, and send metadata.

Consumer interfaces now use abstract methods instead of no-op default methods or empty Kotlin method bodies. This makes missing handler implementations visible at compile time instead of silently doing nothing.

Typed message headers are now included in Spring Kafka generated APIs when headers are enabled and defined in the AsyncAPI document. Producer methods accept the generated header DTO and map non-null header values into Kafka record headers. Consumer interfaces expose the generated header DTO in their method signatures. When clients.kafka.headers.enabled is false, Spring Kafka clients no longer reference header DTOs.

The generation planner was also tightened so it does not create an empty Spring Kafka client task when both producer and consumer generation are disabled. Header generation remains independent, so header DTOs can still be generated when requested.

The old Spring Kafka listener model and unused topic-property fields were removed from the internal generator model because they no longer match the contract-only direction.

The Maven integration scenario was renamed from spring-kafka-simple to spring-kafka-contract so the test naming reflects the current behavior.

The README was updated to document the new nested Kafka/Spring Kafka configuration shape, the contract-only Spring Kafka output, typed header generation, send future return types, and the fact that runtime Kafka wiring still belongs to the consuming application.

Test coverage was updated across the core generator and plugin integration tests.

The coverage includes planner tests for nested Kafka capabilities, disabled headers, disabled producer/consumer output, and empty Spring Kafka tasks. Kotlin and Java Spring Kafka generation tests now cover typed headers, disabled headers, native Avro payloads, native Protobuf payloads, primitive payloads, open payloads, producer send futures, and abstract consumer interfaces. The Maven integration test now verifies the contract-style Spring Kafka output through the public Maven plugin configuration.

This part of the generator will change and get additions.

Introduce shared message header analysis so generated Spring Kafka producers and consumers can use typed header DTOs when AsyncAPI message headers are defined.

The Spring Kafka model preparation now carries header type metadata through the analyzer, payload model, Java/Kotlin factories, and templates. Generated producer and consumer APIs now include typed header parameters for messages with headers, while no-header messages keep the existing simpler signatures.

Producer templates now map non-null typed header values into Kafka record headers, and consumer templates expose the generated header type in handler signatures.

Add tests covering header analysis, Java Spring Kafka generation, and
Kotlin Spring Kafka generation so typed header imports, method
signatures, and producer header mapping remain stable.
@bascunansalvador bascunansalvador merged commit 7ad53ec into feature/protobuf-java-payload-generation Jun 18, 2026
1 check passed
@bascunansalvador bascunansalvador deleted the feature/kafka-client-contract branch June 18, 2026 21:47
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.

1 participant