-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathHelloService.cs
More file actions
30 lines (26 loc) · 1.46 KB
/
HelloService.cs
File metadata and controls
30 lines (26 loc) · 1.46 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
namespace TemporalioSamples.NexusSimple.Handler;
using NexusRpc.Handlers;
using Temporalio.Nexus;
[NexusServiceHandler(typeof(IHelloService))]
public class HelloService
{
[NexusOperationHandler]
public IOperationHandler<IHelloService.EchoInput, IHelloService.EchoOutput> Echo() =>
// This Nexus service operation is a simple sync handler
OperationHandler.Sync<IHelloService.EchoInput, IHelloService.EchoOutput>(
(ctx, input) => new(input.Message));
[NexusOperationHandler]
public IOperationHandler<IHelloService.HelloInput, IHelloService.HelloOutput> SayHello() =>
// This Nexus service operation is backed by a workflow run
WorkflowRunOperationHandler.FromHandleFactory(
(WorkflowRunOperationContext context, IHelloService.HelloInput input) =>
context.StartWorkflowAsync(
(HelloHandlerWorkflow wf) => wf.RunAsync(input),
// Workflow IDs should typically be business meaningful IDs and are used to
// dedupe workflow starts. For this example, use a business ID derived from
// the greeting input so repeated operations for the same name and language
// resolve to the same workflow.
new() { Id = GetHelloWorkflowId(input) }));
private static string GetHelloWorkflowId(IHelloService.HelloInput input) =>
$"hello-{input.Language}-{input.Name.Trim().Replace(' ', '-')}";
}