Hello All,
In using the Competing Consumers that was released recently in Event Store I have encountered an issue with events been processed multiple times.
The code below (for me at least) demonstrates the issue. If the ‘EventAppeared’ method does anything which takes more than a second or so to return the event will be picked up and processed again.
The sample code has been run against 3.3.0 EventStore server running in a Docker container and also natively in Windows. Removing the line Thread.Sleep in the code below will show each message being processed only once.
This seems to be an issue with events not being marked as ‘In Flight’ to me. Has anyone else encountered these issues?
using System;
using System.Threading;
using EventStore.ClientAPI;
namespace CompetingConsumerESConsole
{
class Program
{
static void Main(string[] args)
{
var eventListener = new EventListener();
eventListener.StartReceiver();
Console.ReadLine();
}
}
public class EventListener
{
public void StartReceiver()
{
var connection = EventStoreConnection.Create(new Uri("tcp://admin:[email protected]:1113/"));
connection.ConnectAsync().Wait();
connection.ConnectToPersistentSubscription("bar", "foo",
EventAppeared, SubscriptionDrop, autoAck: false);
Console.WriteLine("connected succesfully");
}
private void EventAppeared(EventStorePersistentSubscriptionBase eventStorePersistentSubscriptionBase,
ResolvedEvent resolvedEvent)
{
//Remove the line below, events are processed once only as expected
Thread.Sleep(2000);
Console.WriteLine($"Event Appeared with Id {resolvedEvent.OriginalEvent.EventId}");
eventStorePersistentSubscriptionBase.Acknowledge(resolvedEvent);
}
private void SubscriptionDrop(EventStorePersistentSubscriptionBase eventStorePersistentSubscriptionBase,
SubscriptionDropReason subscriptionDropReason, Exception exception)
{
Console.WriteLine($"{subscriptionDropReason} Event Deleted {exception.StackTrace}");
StartReceiver();
}
}
}
``