Kafka Spring Integration: Headers not coming for kafka consumer

后端 未结 1 1237
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 17:26

I am using Kafka Spring Integration for publishing and consuming messages using kafka. I see Payload is properly passed from producer to consumer, but the header information

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-13 17:54

    Just because by default Framework uses the immutable GenericMessage.

    Any manipulation to the existing message (e.g. MessageBuilder.withPayload) will produce a new GenericMessage instance.

    From other side Kafka doesn't support any headers abstraction like JMS or AMQP. That's why KafkaProducerMessageHandler just do this when it publishes a message to Kafka:

    this.kafkaProducerContext.send(topic, partitionId, messageKey, message.getPayload());
    

    As you see it doesn't send headers at all. So, other side (consumer) just deals with only message from the topic as a payload and some system options as headers like topic, partition, messageKey.

    In two words: we don't transfer headers over Kafka because it doesn't support them.

    0 讨论(0)
提交回复
热议问题