You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -197,10 +197,12 @@ public class DemoWorkflowActivity implements WorkflowActivity {
197
197
198
198
<!--go-->
199
199
200
+
### Define workflow activities
201
+
200
202
Define each workflow activity you'd like your workflow to perform. The Activity input can be unmarshalled from the context with `ctx.GetInput`. Activities should be defined as taking a `ctx workflow.ActivityContext` parameter and returning an interface and error.
Define your workflow function with the parameter `ctx *workflow.WorkflowContext` and return any and error. Invoke your defined activities from within your workflow.
Before your application can execute workflows, you must register both the workflow orchestrator and its activities with a workflow worker. This is a crucial step that ensures Dapr knows which functions to call when executing your workflow.
fmt.Printf("workflow started with id: %v\n", instanceID)
287
+
288
+
// Stop workflow worker when done
289
+
iferr:= w.Shutdown(); err != nil {
290
+
log.Fatalf("failed to shutdown worker: %v", err)
291
+
}
292
+
}
293
+
```
294
+
295
+
**Key points about registration:**
296
+
- Use `workflow.NewWorker()` to create a workflow worker
297
+
- Use `w.RegisterWorkflow()` to register workflow functions
298
+
- Use `w.RegisterActivity()` to register activity functions
299
+
- Call `w.Start()` to begin processing workflows
300
+
- Use `workflow.NewClient()` to create a client for managing workflows
301
+
214
302
[See the Go SDK workflow activity example in context.](https://github.com/dapr/go-sdk/tree/main/examples/workflow/README.md)
215
303
216
304
{{% /tab %}}
@@ -383,16 +471,16 @@ public class DemoWorkflowWorker {
383
471
Define your workflow function with the parameter `ctx *workflow.WorkflowContext` and return any and error. Invoke your defined activities from within your workflow.
@@ -864,7 +952,7 @@ public class DemoWorkflow extends Workflow {
864
952
[As in the following example](https://github.com/dapr/go-sdk/tree/main/examples/workflow/README.md), a hello-world application using the Go SDK and Dapr Workflow would include:
865
953
866
954
- A Go package called `client` to receive the Go SDK client capabilities.
867
-
- The `TestWorkflow` method
955
+
- The `BusinessWorkflow` method
868
956
- Creating the workflow with input and output.
869
957
- API calls. In the example below, these calls start and call the workflow activities.
870
958
@@ -889,15 +977,15 @@ var failActivityTries = 0
889
977
func main() {
890
978
r :=workflow.NewRegistry()
891
979
892
-
if err :=r.AddWorkflow(TestWorkflow); err != nil {
980
+
if err :=r.AddWorkflow(BusinessWorkflow); err != nil {
893
981
log.Fatal(err)
894
982
}
895
-
fmt.Println("TestWorkflow registered")
983
+
fmt.Println("BusinessWorkflow registered")
896
984
897
-
if err :=r.AddActivity(TestActivity); err != nil {
985
+
if err :=r.AddActivity(BusinessActivity); err != nil {
898
986
log.Fatal(err)
899
987
}
900
-
fmt.Println("TestActivity registered")
988
+
fmt.Println("BusinessActivity registered")
901
989
902
990
if err :=r.AddActivity(FailActivity); err != nil {
903
991
log.Fatal(err)
@@ -921,7 +1009,7 @@ func main() {
921
1009
// "start". This is useful for increasing the throughput of creating
0 commit comments