This question is similar to How do I resume a MongoDB ChangeStream at the first document and not just changes after I start listening but for the Java driver. This is crucial, afaik, if one needs to make sure that all documents are processed at least once.
For example, let's say that I have a change stream (C) that subscribes to documents and sends an email based on the contents of each document. But if the email sending fails or the server crashes before the email could be sent then the resume token (R) will not have been persisted. When the application is started up again it'll "watch" without a resume token and thus the document will be missed and no email sent.
Is there a supported way to get the resume token of a ChangeStream before the first change document has been received to mitigate the issue described above?
From what I can tell from the MongoDB specification this must be supported by drivers:
Drivers MUST expose a mechanism to retrieve the same resume token that would be used to automatically resume.
But I cannot seem to find a way to do this using the Java API. Is this possible or is there a recommended workaround?
Note that I would very much prefer not to use startAtOperationTime
which is based on a timestamp since time is fragile and clocks may be changed both on the server and client.