forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (45 loc) · 1.63 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
package main
import (
"log"
"os"
"github.com/temporalio/samples-go/ctxpropagation"
nexuscontextpropagation "github.com/temporalio/samples-go/nexus-context-propagation"
"github.com/temporalio/samples-go/nexus/caller"
"github.com/temporalio/samples-go/nexus/options"
"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"
)
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)
}
// Set up context propagators from workflow and non-workflow contexts.
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, caller.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(),
},
},
})
w.RegisterWorkflow(caller.HelloCallerWorkflow)
err = w.Run(worker.InterruptCh())
if err != nil {
log.Fatalln("Unable to start worker", err)
}
}