More of a question than issue: Subscriber handles the same message multiple times
digitaldias opened this issue · 1 comments
digitaldias commented
I have a piece of code that takes an "event" and stores that event to CosmosDb.
I've verified that there is only a Singleton instance of my EventManagementService (constructor only runs once), and also that the publisher of the event only transmits the event once.
Here is the subscriber piece of code:
public void Initialize()
{
_hub.Subscribe<NoobEvent>(SaveMessageToEventStore);
}
private async void SaveMessageToEventStore(NbtEvent updateEvent)
{
_hub.UnSubscribe<NoobEvent>();
_logger.Information($"Transmitting event to eventstore: {updateEvent.EventName} {updateEvent.EventType}");
//TODO: (Pedro) Validate the updateEvent
await _exceptionHandler.RunAsync(() => _eventStore.Write(updateEvent));
_hub.Subscribe<NoobEvent>(SaveMessageToEventStore);
}
If I do not unsubscribe while executing the "SaveMessageToEventstore()", then I see that it executes twice. Questions to this:
- Why does the subscriber invoke twice? I only have a single publisher, and a single handler
- By Unsubscribing at the beginning of the handler, does this run the risk of loosing any potentially queued messages, or will it resume where left off?
- Is there a way to mark a published message as "completed" that I am missing?
In advance, thanks.
upta commented
This definitely smells like a bug, I'll have to dig into it a bit and see what I can find