-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (41 loc) · 1.57 KB
/
Program.cs
File metadata and controls
47 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Temporalio.Activities;
using Temporalio.Client;
using Temporalio.Common.EnvConfig;
using Temporalio.Worker;
using Temporalio.Workflows;
using TemporalioSamples.ActivityWorker;
// Create a client to localhost on default namespace
var connectOptions = ClientEnvConfig.LoadClientConnectOptions();
connectOptions.TargetHost ??= "localhost:7233";
var client = await TemporalClient.ConnectAsync(connectOptions);
// Create worker
using var worker = new TemporalWorker(
client,
new TemporalWorkerOptions(taskQueue: "activity-worker-sample").
AddActivity(SayHelloActivities.SayHello));
// Run worker until our code finishes
await worker.ExecuteAsync(async () =>
{
// Run the workflow from Go. Since this is just a sample we will run the worker and the workflow
// client here in the same process, but usually these are done separately.
var result = await client.ExecuteWorkflowAsync(
(ISayHelloWorkflow wf) => wf.RunAsync("Temporal"),
new() { Id = "activity-worker-sample-workflow-id", TaskQueue = "activity-worker-sample" });
Console.WriteLine("Workflow result: {0}", result);
});
namespace TemporalioSamples.ActivityWorker
{
public static class SayHelloActivities
{
// Our activity implementation
[Activity("say-hello-activity")]
public static string SayHello(string name) => $"Hello, {name}!";
}
// Workflow definition of the workflow implementation in Go
[Workflow("say-hello-workflow")]
public interface ISayHelloWorkflow
{
[WorkflowRun]
Task<string> RunAsync(string name);
}
}