From 8febaa50db5447cedf4f661b657d6dd48162ebff Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Wed, 30 Oct 2024 06:27:39 -0500 Subject: [PATCH] Updated example to use DI registration Signed-off-by: Whit Waldo --- .../StreamingSubscriptionExample/Program.cs | 14 +++++++++----- .../StreamingSubscriptionExample.csproj | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/Client/PublishSubscribe/StreamingSubscriptionExample/Program.cs b/examples/Client/PublishSubscribe/StreamingSubscriptionExample/Program.cs index 2eac0c91..ac00d879 100644 --- a/examples/Client/PublishSubscribe/StreamingSubscriptionExample/Program.cs +++ b/examples/Client/PublishSubscribe/StreamingSubscriptionExample/Program.cs @@ -1,8 +1,10 @@ using System.Text; using Dapr.Messaging.PublishSubscribe; +using Dapr.Messaging.PublishSubscribe.Extensions; -var daprMessagingClientBuilder = new DaprPublishSubscribeClientBuilder(null); -var daprMessagingClient = daprMessagingClientBuilder.Build(); +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddDaprPubSubClient(); +var app = builder.Build(); //Process each message returned from the subscription Task HandleMessageAsync(TopicMessage message, CancellationToken cancellationToken = default) @@ -19,9 +21,11 @@ Task HandleMessageAsync(TopicMessage message, CancellationT } } -//Create a dynamic streaming subscription and subscribe with a timeout of 20 seconds and 10 seconds for message handling -var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(20)); -var subscription = await daprMessagingClient.SubscribeAsync("pubsub", "myTopic", +var messagingClient = app.Services.GetRequiredService(); + +//Create a dynamic streaming subscription and subscribe with a timeout of 30 seconds and 10 seconds for message handling +var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)); +var subscription = await messagingClient.SubscribeAsync("pubsub", "myTopic", new DaprSubscriptionOptions(new MessageHandlingPolicy(TimeSpan.FromSeconds(10), TopicResponseAction.Retry)), HandleMessageAsync, cancellationTokenSource.Token); diff --git a/examples/Client/PublishSubscribe/StreamingSubscriptionExample/StreamingSubscriptionExample.csproj b/examples/Client/PublishSubscribe/StreamingSubscriptionExample/StreamingSubscriptionExample.csproj index c73345b4..4ad620d0 100644 --- a/examples/Client/PublishSubscribe/StreamingSubscriptionExample/StreamingSubscriptionExample.csproj +++ b/examples/Client/PublishSubscribe/StreamingSubscriptionExample/StreamingSubscriptionExample.csproj @@ -1,4 +1,4 @@ - + Exe