forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (55 loc) · 1.91 KB
/
main.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"log"
"os"
"github.com/nexus-rpc/sdk-go/nexus"
"github.com/temporalio/samples-go/ctxpropagation"
nexuscontextpropagation "github.com/temporalio/samples-go/nexus-context-propagation"
"github.com/temporalio/samples-go/nexus-context-propagation/handler"
"github.com/temporalio/samples-go/nexus/options"
"github.com/temporalio/samples-go/nexus/service"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/converter"
"go.temporal.io/sdk/interceptor"
"go.temporal.io/sdk/worker"
"go.temporal.io/sdk/workflow"
)
const (
taskQueue = "my-handler-task-queue"
)
func main() {
// The client and worker are heavyweight objects that should be created once per process.
clientOptions, err := options.ParseClientOptionFlags(os.Args[1:])
if err != nil {
log.Fatalf("Invalid arguments: %v", err)
}
clientOptions.ContextPropagators = []workflow.ContextPropagator{ctxpropagation.NewContextPropagator()}
c, err := client.Dial(clientOptions)
if err != nil {
log.Fatalln("Unable to create client", err)
}
defer c.Close()
w := worker.New(c, taskQueue, worker.Options{
Interceptors: []interceptor.WorkerInterceptor{
&nexuscontextpropagation.WorkerInterceptor{
// Use the provided data converter to encode the Nexus headers. Use a custom data
// converter to encrypt the header values.
// IMPORTANT: Nexus headers values are plain strings and are not visited by the
// grpc-proxy (see related sample), special care should be taken when used to pass
// sensitive information.
DataConverter: converter.GetDefaultDataConverter(),
},
},
})
service := nexus.NewService(service.HelloServiceName)
err = service.Register(handler.HelloOperation)
if err != nil {
log.Fatalln("Unable to register operations", err)
}
w.RegisterNexusService(service)
w.RegisterWorkflow(handler.HelloHandlerWorkflow)
err = w.Run(worker.InterruptCh())
if err != nil {
log.Fatalln("Unable to start worker", err)
}
}