Event Processing Applications may want to implement Event Collaboration, where Events are used to transport requests and responses. When applications collaborate via events, they need a way to correlate event response data for specific requests.
When an application requests information and receives a response, how can the application know which request corresponds to that particular response?
An Event Processor generates an event, which acts as the request. A globally unique identifier is added to the request event before it is sent. This allows the responding Event Processor to include the identifier in the response event, so that the requesting processor can correlate the request and response.
In Kafka, we can add a globally unique identifier to Kafka record headers when producing a request event. The following example uses the Kafka Java producer client.
ProducerRecord<String, String> requestEvent = new ProducerRecord<>("request-event-key", "request-event-value"); requestEvent.headers().add("requestID", UUID.randomUUID().toString()); requestEvent.send(producerRecord);
In the responding event processor, we first extract the correlation identifier from the request event (here, the identifier is called
requestID) and then add that identifier to the response event.
ProducerRecord<String, String> responseEvent = new ProducerRecord<>("response-event-key", "response-event-value"); responseEvent.headers().add("requestID", requestEvent.headers().lastHeader("requestID").value()); responseEvent.send(producerRecord);
a002, etc.), and the server will respond asynchronously, tagging its responses with the matching ID.
We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.