Sample c example solClient_msg_getCorrelationTag

Damn, damn and more damn! @Abhishek you’ve caught me out. I didn’t read the correlationTag docs properly and my answer above is wrong as you’ve spotted. I conflated the two but they’re not the same. Apologies for the confusion.

Right, let’s start again. Forget everything I’ve said.

correlationTag/correlationTagPtr is used for publishing guaranteed messages, and allows the application to correlate a “sent” published message with an asynchronous acknowledgement that comes in via the event callback. You can see this being used in the adPubAck.c sample that is shipped with the API.

correlationIDs are used for any style of messaging (direct or persistent) where you expect an asynchronous response from another application. It allows you to understand which request caused this incoming response.

So, to summarise:

  • You are using direct (non-persistent) request/response: → use correlationID;
  • You are publishing a guaranteed message: → use correlationTag
  • You are publishing a request/response message using persistent messaging: → use correlationTag to check your guaranteed request has been received by the broker, use correlationID to work out which request caused this incoming response.

Some psuedo code for the guaranteed request/response case:

  1. Create request;
  2. Create correlationID. Add request to your request tracking data structure with the correlationID;
  3. Create the correlationTag. Create the request message, add the correlationID and the correlationTag;
  4. Add the correlationTag to your guaranteed ack tracking data structure;
  5. Send request message;
  6. Some time later, you get a session event indicating an acknowledgement of the sent message. Check the correlationTag against your ack tracking structure and release the request message buffer (not the request istelf).
  7. Some time after that, you get the response from the responding application. Check the correlationID against the request tracking structure to find out which request caused this response. Do your business logic. Once that’s all finished, release the response message, free that part of the request tracking structure and release the request data.

Hope that makes sense.