根据这个主题:
Kafka Spring Integration: Headers not coming for kafka consumer -
这对Kafka没有标头支持
但是documentation说:
spring.cloud.stream.kafka.binder.headers
将由活页夹传输的自定义标头列表。默认值:空。
我无法使用spring-cloud-stream-binder-kafka:1.2.0.RELEASE
发送日志:
MESSAGE (e23885fd-ffd9-42dc-ebe3-5a78467fee1f) SENT :
GenericMessage [payload=...,
headers={
content-type=application/json,
correlationId=51dd90b1-76e6-4b8d-b667-da25f214f383,
id=e23885fd-ffd9-42dc-ebe3-5a78467fee1f,
contentType=application/json,
timestamp=1497535771673
}]
收到日志:
MESSAGE (448175f5-2b21-9a44-26b9-85f093b33f6b) RECEIVED BY HANDLER 1:
GenericMessage [payload=...,
headers={
kafka_offset=36,
id=448175f5-2b21-9a44-26b9-85f093b33f6b,
kafka_receivedPartitionId=0,
contentType=application/json;charset=UTF-8,
kafka_receivedTopic=new_patient, timestamp=1497535771715
}]
MESSAGE (448175f5-2b21-9a44-26b9-85f093b33f6b) RECEIVED BY HANDLER 2 :
GenericMessage [payload=...,
headers={
kafka_offset=36,
id=448175f5-2b21-9a44-26b9-85f093b33f6b,
kafka_receivedPartitionId=0,
contentType=application/json;charset=UTF-8,
kafka_receivedTopic=new_patient, timestamp=1497535771715
}]
我希望在接收方看到相同的消息 id 并获得 correlationId 。
application.properties:
spring.cloud.stream.kafka.binder.headers=correlationId
spring.cloud.stream.bindings.newTest.destination=new_test
spring.cloud.stream.bindings.newTestCreated.destination=new_test
spring.cloud.stream.default.consumer.headerMode=embeddedHeaders
spring.cloud.stream.default.producer.headerMode=embeddedHeaders
发送消息:
@Publisher(channel = "testChannel")
public Object newTest(Object param) {
...
return myObject;
}
答案 0 :(得分:2)
headerMode
设置为raw时,禁用输入上的标头解析。仅对本身不支持邮件头并需要标头嵌入的邮件中间件有效。当入站数据来自Spring Cloud Stream应用程序外部时很有用。
默认值:embeddedHeaders
但这已经是Spring Cloud Stream的故事,而不是Spring Kafka本身。