We are trying to build some logic to track whether all high-volume published events have been successfully delivered to subscribers, and catch those that were not delivered for some reason to republish later on.
The idea is quite simple here: every time when we publish platform even, we will create a record in our Log object with json-serialized event data, event name and other info like that to be able to republish it if needed (probably manually at first stage). Then in each event subscriber trigger we will remove corresponding log record (or update status) for each received platform event.
The problem here is: how to match uniquely event received in subscriber trigger to record in Log table?
The standard approach like
create CorrelationId__c field in each event and generate some uuid before publishing
does not work for us, since we've already reached a patch flow for our managed package, i.e. SF does not allow to create new fields at this stage at all. That's why we are relying on our existent Log object and kind of 're-purposing' some of its existent fields for platform event.
So far we've found a method in 48.0 API which actually returns platform event uuid right after publishing from Apex based on Database.SaveResults:
Database.SaveResult publishResult = EventBus.publish( eventToPublish ) ; String uuid = EventBus.getOperationId(publishResult);
The challenge here is how to get this uuid on receiving side, i.e. in subscriber trigger, purely from platform event or using system classes (again keeping in mind that we cannot create new field).
Or maybe there is some other way how we can generate our own UUID and recreate it on receiving side to use as a correlation id, but without passing it via event payload directly?
Any help would be appreciated.