Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.33 KB

README.md

File metadata and controls

59 lines (43 loc) · 1.33 KB

English | 简体中文

workflow-grpc

Minimal usage example for client/workflow using grpc protocol

Quick start

Installing and running dtm

Refer to dtm installation and running

Startup example

go run main.go

Output

The order of execution can be seen in the log of workflow-grpc as follows.

  • TransOut
  • TransIn

The entire workflow transaction was executed successfully

Steps

A complete example includes following steps:

Init Workflow

	s := busi.GrpcNewServer()
	workflow.InitGrpc(busi.DtmGrpcServer, busi.BusiGrpc, s)

Add Workflow Interceptor

Workflow will automaticly intercept gRPC call, and record the progresses.

	conn1, err := grpc.Dial(busi.BusiGrpc, nossl, grpc.WithUnaryInterceptor(workflow.Interceptor))
	// check err
	busiCli = busi.NewBusiClient(conn1)

Register a Workflow

	wfName := "workflow-grpc"
	err = workflow.Register(wfName, func(wf *workflow.Workflow, data []byte) error {
	// ...
		_, err = busiCli.TransOut(wf.Context, &req)
	// grpc call should use clients with workflow's interceptor, and workflow's Context
	}

Execute a Workflow

	err = workflow.Execute(wfName, shortuuid.New(), data)

For more examples, see dtm-examples