This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new db6fd24  Add launch configurations for different workers i examples 
(#252)
db6fd24 is described below

commit db6fd24bc8153c8d91f038a1e9f778234595735f
Author: Kristian Andersen <[email protected]>
AuthorDate: Fri Feb 7 11:21:36 2025 +0100

    Add launch configurations for different workers i examples (#252)
---
 samples/Consuming/Program.cs                     | 23 ++++++++++++++++-------
 samples/Consuming/Properties/launchSettings.json | 18 +++++++++++++++++-
 samples/Producing/Program.cs                     | 19 +++++++++++++------
 samples/Producing/Properties/launchSettings.json | 10 +++++++++-
 samples/Producing/SendChannelWorker.cs           |  2 +-
 samples/Producing/SendWorker.cs                  |  2 +-
 6 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/samples/Consuming/Program.cs b/samples/Consuming/Program.cs
index bfd9238..fd52707 100644
--- a/samples/Consuming/Program.cs
+++ b/samples/Consuming/Program.cs
@@ -15,10 +15,19 @@
 using Consuming;
 using Extensions;
 
-await Host
-    .CreateApplicationBuilder(args)
-    //.AddHostedService<ReceiveWorker>()  // Using 'Receive'
-    //.AddHostedService<MessagesWorker>() // Using 'Messages'
-    .AddHostedService<ProcessWorker>()  // Using 'Process' (recommended)
-    .Build()
-    .RunAsync();
+var builder = Host.CreateApplicationBuilder(args);
+
+switch (args)
+{
+    case ["ReceiveWorker"]:
+        builder.AddHostedService<ReceiveWorker>();  // Using 'Receive'
+        break;
+    case ["MessagesWorker"]:
+        builder.AddHostedService<MessagesWorker>(); // Using 'Messages'
+        break;
+    default:
+        builder.AddHostedService<ProcessWorker>();  // Using 'Process' 
(recommended)
+        break;
+}
+
+await builder.Build().RunAsync();
diff --git a/samples/Consuming/Properties/launchSettings.json 
b/samples/Consuming/Properties/launchSettings.json
index 2906cde..d4bc6df 100644
--- a/samples/Consuming/Properties/launchSettings.json
+++ b/samples/Consuming/Properties/launchSettings.json
@@ -1,6 +1,22 @@
 {
   "profiles": {
-    "Processing": {
+    "MessagesWorker": {
+      "commandName": "Project",
+      "commandLineArgs": "MessagesWorker",
+      "dotnetRunMessages": true,
+      "environmentVariables": {
+        "DOTNET_ENVIRONMENT": "Development"
+      }
+    },
+    "ReceiveWorker": {
+      "commandName": "Project",
+      "commandLineArgs": "ReceiveWorker",
+      "dotnetRunMessages": true,
+      "environmentVariables": {
+        "DOTNET_ENVIRONMENT": "Development"
+      }
+    },
+    "ProcessWorker": {
       "commandName": "Project",
       "dotnetRunMessages": true,
       "environmentVariables": {
diff --git a/samples/Producing/Program.cs b/samples/Producing/Program.cs
index a3f20c8..ebeeda8 100644
--- a/samples/Producing/Program.cs
+++ b/samples/Producing/Program.cs
@@ -15,9 +15,16 @@
 using Extensions;
 using Producing;
 
-await Host
-    .CreateApplicationBuilder(args)
-    //.AddHostedService<SendChannelWorker>()
-    .AddHostedService<SendWorker>()
-    .Build()
-    .RunAsync();
+var builder = Host.CreateApplicationBuilder(args);
+
+switch (args)
+{
+    case ["SendChannelWorker"]:
+        builder.AddHostedService<SendChannelWorker>();
+        break;
+    default:
+        builder.AddHostedService<SendWorker>();
+        break;
+}
+
+await builder.Build().RunAsync();
diff --git a/samples/Producing/Properties/launchSettings.json 
b/samples/Producing/Properties/launchSettings.json
index 2906cde..d8f6c34 100644
--- a/samples/Producing/Properties/launchSettings.json
+++ b/samples/Producing/Properties/launchSettings.json
@@ -1,6 +1,14 @@
 {
   "profiles": {
-    "Processing": {
+    "SendChannelWorker": {
+      "commandName": "Project",
+      "commandLineArgs": "SendChannelWorker",
+      "dotnetRunMessages": true,
+      "environmentVariables": {
+        "DOTNET_ENVIRONMENT": "Development"
+      }
+    },
+    "SendWorker": {
       "commandName": "Project",
       "dotnetRunMessages": true,
       "environmentVariables": {
diff --git a/samples/Producing/SendChannelWorker.cs 
b/samples/Producing/SendChannelWorker.cs
index bebf992..487e9b7 100644
--- a/samples/Producing/SendChannelWorker.cs
+++ b/samples/Producing/SendChannelWorker.cs
@@ -39,7 +39,7 @@ public class SendChannelWorker : BackgroundService
 
         var delay = TimeSpan.FromSeconds(5);
 
-        _logger.LogInformation($"Will start sending messages every 
{delay.TotalSeconds} seconds");
+        _logger.LogInformation($"Will start sending messages every 
{delay.TotalSeconds} seconds with 'SendChannel'");
 
         while (!stoppingToken.IsCancellationRequested)
         {
diff --git a/samples/Producing/SendWorker.cs b/samples/Producing/SendWorker.cs
index 65d3b4a..a17ef92 100644
--- a/samples/Producing/SendWorker.cs
+++ b/samples/Producing/SendWorker.cs
@@ -37,7 +37,7 @@ public sealed class SendWorker : BackgroundService
 
         var delay = TimeSpan.FromSeconds(5);
 
-        _logger.LogInformation($"Will start sending messages every 
{delay.TotalSeconds} seconds");
+        _logger.LogInformation($"Will start sending messages every 
{delay.TotalSeconds} seconds with 'Send'");
 
         while (!stoppingToken.IsCancellationRequested)
         {

Reply via email to