I am currently in process of building a CDC application in my environment that captures changes and then places them on an Azure service bus for later processing.
The way I have the application configured currently is that every time it connects to Salesforce via CDC, it reads the last recorded ReplayId from a database. This way it can always pickup where it left off in case of failure. As new events are captured, it records the ReplayId as being processed, so that it can be used next time the app connects.
However, the problem I am running into is, what happens if the app is down for a few days, and the ReplayId is no longer valid (the event is not available)? This is an unlikely scenario, but something I am trying to resolve incase it does occur.
From all of my testing, when I subscribe to my channel with an "invalid" ReplayId, I dont get any messages or warnings. Instead, it appears that I am successfully connected, but changes stop being captured. If I manually update the ReplayId to something I know is valid, the application starts receiving messages as expected.
What can I do to get around this? I tried subscribing to various metadata channels, but I didnt see any messages there warning me that my event is no longer available... My only thought is that I need to make an initial subscription to the channel with the ReplayId of -2 (get everything), and use this to get the oldest ReplayId available to compare with my stored value. If my stored value is lower than the Id I get back, I will know that my stored Id is out of date.
Are there any better solutions to this problem? If anyone has any ideas, I would greatly appreciate it. Thanks!