简体   繁体   中英

spring kafkatemplate correlation id

Currently I am using spring kafkatemplate to send byte message to kafka topic. At consumer side, we deserialize this byte message to appropriate message type. Now we have requirement where we also need to send correlationid along with the message to Kafka topic. Can i send correlation-id along with the byte message on kafka topic and retrive it seperatly at consumer side?

According to Kafka Docs, CorrelationId is a user-supplied integer. It will be passed back in the response by the server, unmodified. It is useful for matching request and response between the client and server.

If I talk about java api, then on consumer side you can get only(topic_name,partition,offset,value) related to the message.

You can send correlationId as a part of message, but you have to parse the message to get it on consumer side.

The upcoming v0.11 of Kafka adds support for custom message headers. They'd be the prime candidate to put the correlation id into.

Until then, I'm afraid you have to put the correlation id into the message value. Your serializer and deserializer should encode/decode it together with your actual payload into/from a byte array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM