TransactionProcessing / Shared

0 stars 0 forks source link

Upgrade to new technique for persistent subscriptions #270

Open StuartFerguson opened 4 months ago

StuartFerguson commented 4 months ago

Code is as follows for subscribing to a stream

await using var subscription = client.SubscribeToStream(
    "test-stream",
    "subscription-group", 
    cancellationToken: ct);
await foreach (var message in subscription.Messages) {
    switch (message) {
        case PersistentSubscriptionMessage.SubscriptionConfirmation(var subscriptionId):
            Console.WriteLine($"Subscription {subscriptionId} to stream started");
            break;
        case PersistentSubscriptionMessage.Event(var resolvedEvent, _):
            await HandleEvent(resolvedEvent);
            await subscription.Ack(resolvedEvent);
            break;
    }
}

More information here: Event Store Documentation