Skip to content

fix(cloudevent): honor target-protocol for Kafka ce_ prefix - #1464

Closed
arimu1 wants to merge 1 commit into
spring-cloud:mainfrom
arimu1:fix/1461-kafka-ce-prefix
Closed

arimu1 wants to merge 1 commit into
spring-cloud:mainfrom
arimu1:fix/1461-kafka-ce-prefix

Conversation

@arimu1

@arimu1 arimu1 commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Restores MessageUtils.TARGET_PROTOCOL and resolves the target-protocol header (case-insensitive) before inferring protocol from kafka_* / amqp headers in CloudEventMessageUtils.extractTargetProtocol.
  • Merges input and result headers in CloudEventsFunctionInvocationHelper.postProcessResult when choosing the output Cloud Event attribute prefix.
  • Adds a unit test covering AMQP-sourced messages with target-protocol: kafka (cross-binder scenario from ce_ prefix is no longer applied automatically for Cloud Events sent to Kafka #1461).

Fixes gh-1461

Context

Since gh-1294 / spring-cloud/spring-cloud-stream#2222, Spring Cloud Stream no longer sets target-protocol on messages, and prefix detection falls back to binder-specific headers on the input message. For AMQP → Kafka flows (e.g. function-sample-cloudevent-stream), that yields cloudEvents: on Kafka instead of ce_.

This change restores the function-side support for target-protocol. Spring Cloud Stream should restore setting that header on function input (see commented lines in FunctionConfiguration.FunctionWrapper#setHeadersIfNeeded and the reactive targetProtocolEnhancer) so end-to-end behavior matches the sample README again.

Test plan

  • ./mvnw -pl spring-cloud-function-context -am test
  • ./mvnw -f spring-cloud-function-samples/function-sample-cloudevent-stream/pom.xml test (module not in parent reactor; requires Rabbit/Kafka on localhost; DemoApplicationTests#test is currently commented out)
  • After stream companion change: enable DemoApplicationTests#test and verify Kafka headers use ce_ prefix

Restore reading the target-protocol header when choosing Cloud Event
attribute prefixes so cross-binder flows (e.g. AMQP to Kafka) can use ce_
without requiring kafka_* headers on the message.

Fixes spring-cloudgh-1461

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
@DidierLoiseau

Copy link
Copy Markdown

I’m confused, this fix would require users to set the target-protocol explicitly to work properly, right? Or is it your intent to also revert the changes from spring-cloud/spring-cloud-stream#2222?

@olegz olegz closed this in aceab4e Sep 15, 2026
@olegz olegz added this to the 5.1.0-M1 milestone Sep 15, 2026
@DidierLoiseau

Copy link
Copy Markdown

@olegz this does not solve #1461, it’s only a workaround that allows setting target-protocol when you don’t set any other kafka_ header.

Could you thus reopen #1461?

p.s. for some reason, I’m no longer able to run the test in function-sample-cloudevent-stream today:

  • the spring-cloud-function-deployer 5.1.0-SNAPSHOT dependency no longer exists
  • even with 5.0.0-M2 of the former + updating spring-cloud-stream dependencies to 5.1.0-SNAPSHOT, it fails with class [B cannot be cast to class io.spring.cloudevent.Person

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.

ce_ prefix is no longer applied automatically for Cloud Events sent to Kafka

3 participants