Skip to main content

Headers

Springwolf provides different ways to document headers. The header is mapped to an AsyncAPI schemaObject.

Auto-detection

Besides the payload, Springwolf detects the Spring @Header annotation within the method signature:

@KafkaListener(topics = "example-topic")
public void receiveExamplePayload(
@Payload ExamplePayloadDto payload, // @Payload is required for multiple parameters
@Header(KafkaHeaders.RECEIVED_KEY) String key,
@Header(KafkaHeaders.OFFSET) Integer offset) {
// process
}

Using @AsyncOperation.Headers

Again, the annotation property headers of @AsyncOperation allows to overwrite the headers, as shown below:

@AsyncPublisher(operation = @AsyncOperation(
channelName = "example-producer-topic",
headers = @AsyncOperation.Headers( // Optional
schemaName = "SpringKafkaDefaultHeaders",
values = {
@AsyncOperation.Headers.Header(
name = DEFAULT_CLASSID_FIELD_NAME,
description = "Spring Type Id Header",
value = "io.github.springwolf.example.dtos.ExamplePayloadDto"
),
// demonstrating https://cloudevents.io
@AsyncOperation.Headers.Header(
name = AsyncHeadersCloudEventConstants.TYPE,
description = AsyncHeadersCloudEventConstants.TYPE_DESC,
value = "ExamplePayloadDto.v1")
// ...
}
)
))
public void sendMessage(ExamplePayloadDto msg) {
// process
}