Reputation: 13807
I'm trying to understand what correlation ids are in the AsyncAPI spec https://www.asyncapi.com/docs/specifications/v2.0.0#correlationIdObject
There is a full example dedicated to this, but I still have no idea what's the purpose of this property https://github.com/asyncapi/spec/blob/3470a6386736cf6002846d8eb7535308b79c75e8/examples/correlation-id.yml
I'm interested in:
Upvotes: 1
Views: 2515
Reputation: 3011
I don't know AsyncAPI, but in general software engineering you may need to call a service asynchronously, but carry on with other work until you get a callback from that long running service. Say in order management someone is buying something online. The system completes the steps to buy the object and you get to the point you need to tell the shipping department to ship whatever it is. You can't just say the order is over because we don't know if the shipping department has actually shipped anything or the buyer received it. So the order process sits in a suspended mode, the state of the order stored in some sort of database, often in JASON or XML format. When the shipping department ships it, their system can reply to the original system running the order process that they shipped, but how do they know what was shipped and what process to wake up and continue? Often they will use a correlation ID that is more distinctive than an order number, something more like a GUID. The order management will get the message back, look up the order by correlation id, and see the status change for that order and update the status to 'shipped'. Similarly it can update when the item is marked as delivered and the order process can be marked complete, or call other system to initiate billing, or whatever.
Upvotes: 0
Reputation: 798
correlationid
purpose is to specify where in the message you can find the correlation identifier. Sometimes this information is part of the header, sometimes can be in message payload. So the correlationid
prop is to unify the way such information is presented to the API description, it is a place where you specify where exactly identifier is located.
Why would you need it? at all. The main reason for me is always tracing. Correlation Identifier is also known as tracing-id or request-id. Please do call it differently. Basically, this is the id of the event that helps you trace the event in the system, through logs and tracing tools like Jeager and others. So you can trace the flow of the event in the system from point A to Z, to for example identify why it didn't get to Z, where did it stack.
It is also useful in request/reply pattern in event driven architecture. Where producer of the event wants to make sure the event it got in reply is a response from a consumer to this specific event.
Upvotes: 3