How do correlation identifiers work?

Hi, I’ve been looking at the documentation at Correlation Identifier (confluent.io) and while I think I get it, the second code snippet doesn’t make sense to me. It says:

ProducerRecord<String, String> responseEvent = new ProducerRecord<>("response-event-key", "response-event-value"); 
requestEvent.headers().add("requestID", requestEvent.headers().lastHeader("requestID").value());
requestEvent.send(producerRecord);

Here it’s creating a responseEvent but never using it, which seems wrong to me, however I want to be sure I’m not missing some fundamental piece of understanding as I would have thought it should read:

ProducerRecord<String, String> responseEvent = new ProducerRecord<>("response-event-key", "response-event-value"); 
responseEvent.headers().add("requestID", requestEvent.headers().lastHeader("requestID").value());
responseEvent.send(producerRecord);

Can someone clarify for me please?

1 Like

Yeah, I think that’s a typo indeed. The first line (of the second code snippet) creates a responseEvent, and the next two lines should then operate on that responseEvent (= it should be like the second code snippet you shared in your post).

Probably a copy-paste error while writing up the pattern description. We’ll get that fixed. Thanks for reporting. @mmalc !

1 Like

Pull request up at Use responseEvent to configure response by miguno · Pull Request #254 · confluentinc/event-streaming-patterns · GitHub (just for reference)

Cool, I figured that was the case. Just wanted to be sure.
Thanks for responding so quickly.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.