• Stars
    star
    404
  • Rank 106,897 (Top 3 %)
  • Language
    Go
  • License
    Other
  • Created about 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Temporal Go SDK samples

Temporal Go SDK samples

FOSSA Status

This repository contains several sample Workflow applications that demonstrate the various capabilities of the Temporal Server via the Temporal Go SDK.

How to use

  • Run this in the browser with Gitpod: Gitpod ready-to-code
  • Or run Temporal Server locally with VSCode Remote Containers . Open in Remote - Containers
  • Lastly, you can run Temporal Server locally on your own (follow the Quick install guide), then clone this repository

The helloworld sample is a good place to start.

Samples directory

Each sample demonstrates one feature of the SDK, together with tests.

  • Basic hello world: Simple example of a Workflow Definition and an Activity Definition.

  • Basic mTLS hello world: Simple example of a Workflow Definition and an Activity Definition using mTLS like Temporal Cloud.

API demonstrations

  • Async activity completion: Example of an Expense reporting Workflow that communicates with a server API. Additional documentation: How to complete an Activity Execution asynchronously in Go

  • Retry Activity Execution: This samples executes an unreliable Activity. The Activity is executed with a custom Retry Policy. If the Activity Execution fails, the Server will schedule a retry based on the Retry Policy. This Activity also includes a Heartbeat, which enables it to resume from the Activity Execution's last reported progress when it retries.

  • Child Workflow: Demonstrates how to use execute a Child Workflow from a Parent Workflow Execution. A Child Workflow Execution only returns to the Parent Workflow Execution after completing its last Run.

  • Child Workflow with ContinueAsNew: Demonstrates that the call to Continue-As-New, by a Child Workflow Execution, is not visible to the a parent. The Parent Workflow Execution receives a notification only when a Child Workflow Execution completes, fails or times out. This is a useful feature when there is a need to process a large set of data. The child can iterate over the data set calling Continue-As-New periodically without polluting the parents' history.

  • Cancellation: Demonstrates how to cancel a Workflow Execution by calling CancelWorkflow, an how to defer an Activity Execution that "cleans up" after the Workflow Execution has been cancelled.

  • Coroutines: Do not use native go routines in Workflows. Instead use Temporal coroutines (workflow.Go()) to maintain a deterministic Workflow. Can be seen in the Goroutine , DSL , Recovery , PSO Workflow examples.

  • Cron Workflow: Demonstrates a recurring Workflow Execution that occurs according to a cron schedule. This samples showcases the HasLastCompletionResult and GetLastCompletionResult APIs which are used to pass information between executions. Additional documentation: What is a Temporal Cron Job?.

  • Schedule Workflow: Demonstrates a recurring Workflow Execution that occurs according to a schedule. documentation: Schedule.

  • Encryption: How to use encryption for Workflow/Activity data with the DataConverter API. Also includes an example of stacking encoders (in this case encryption and compression)

  • Codec Server: Demonstrates using a codec server to decode payloads for display in tctl and Temporal Web. This setup can be used for any kind of codec, common examples are compression or encryption.

  • Query Example: Demonstrates how to Query the state of a single Workflow Execution using the QueryWorkflow and SetQueryHandler APIs. Additional documentation: How to Query a Workflow Execution in Go.

  • Selectors: Do not use the native Go select statement. Instead use Go SDK Selectors (selector.Select(ctx)) to maintain a deterministic Workflow. Can be seen in the Pick First , Mutex , DSL, and Timer examples.

  • Sessions: Demonstrates how to bind a set of Activity Executions to a specific Worker after the first Activity executes. This feature is showcased in the File Processing example. Addition documentation: How to use Sessions in Go.

  • Signals: Can be seen in the Recovery and Mutex examples. Additional documentation: eCommerce application tutorial , How to send and handle Signals in Go .

  • Memo: Demonstrates how to use Memo that can be used to store any kind of data.

  • Search Attributes: Demonstrates how to use custom Search Attributes that can be used to find Workflow Executions using predicates (must use with Elasticsearch).

  • Timer Futures: The sample starts a long running order processing operation and starts a Timer (workflow.NewTimer()). If the processing time is too long, a notification email is "sent" to the user regarding the delay (the execution does not cancel). If the operation finishes before the Timer fires, then the Timer is cancelled.

  • Tracing and Context Propagation: Demonstrates the client initialization with a context propagator, which propagates specific information in the context.Context object across the Workflow Execution. The context.Context object is populated with information prior to calling StartWorkflow. This example demonstrates that the information is available in the Workflow Execution and Activity Executions. Additional documentation: How to use tracing in Go.

  • Updatable Timer: Demonstrates timer cancellation and use of a Selector to wait on a Future and a Channel simultaneously.

  • Greetings: Demonstrates how to pass dependencies to activities defined as struct methods.

  • Greetings Local: Demonstrates how to pass dependencies to local activities defined as struct methods.

  • Interceptors: Demonstrates how to use interceptors to intercept calls, in this case for adding context to the logger.

Dynamic Workflow logic examples

These samples demonstrate some common control flow patterns using Temporal's Go SDK API.

  • Dynamic Execution: Demonstrates how to execute Workflows and Activities using a name rather than a strongly typed function.

  • Branching Activities: Executes multiple Activities in parallel. The number of branches is controlled by a parameter that is passed in at the start of the Workflow Execution.

  • Exclusive Choice: Demonstrates how to execute Activities based on a dynamic input.

  • Multi-Choice: Demonstrates how to execute multiple Activities in parallel based on a dynamic input.

  • Mutex Workflow: Demonstrates the ability to lock/unlock a particular resource within a particular Temporal Namespace. In this examples the other Workflow Executions within the same Namespace wait until a locked resource is unlocked. This shows how to avoid race conditions or parallel mutually exclusive operations on the same resource.

  • Goroutine Workflow: This sample executes multiple sequences of activities in parallel using the workflow.Go() API.

  • Pick First: This sample executes Activities in parallel branches, picks the result of the branch that completes first, and then cancels other Activities that have not finished.

  • Split/Merge Future: Demonstrates how to use futures to await for completion of multiple activities invoked in parallel. This samples to processes chunks of a large work item in parallel, and then merges the intermediate results to generate the final result.

  • Split/Merge Selector: Demonstrates how to use Selector to process activity results as soon as they become available. This samples to processes chunks of a large work item in parallel, and then merges the intermediate results to generate the final result.

  • Synchronous Proxy Workflow pattern: This sample demonstrates a synchronous interaction with a "main" Workflow Execution from a "proxy" Workflow Execution. The proxy Workflow Execution sends a Signal to the "main" Workflow Execution, then blocks, waiting for a Signal in response.

  • Saga pattern: This sample demonstrates how to implement a saga pattern using golang defer feature.

  • Await for signal processing: Demonstrates how to process out of order signals processing using Await and AwaitWithTimeout.

  • Sticky task queue for activities: Demonstrates how to create a sticky task queue to run certain activities on the same host.

Scenario based examples

  • DSL Workflow: Demonstrates how to implement a DSL-based Workflow. This sample contains 2 yaml files that each define a custom "workflow" which instructs the Temporal Workflow. This is useful if you want to build in a "low code" layer.

  • Expense Request: This demonstrates how to process an expense request. This sample showcases how to complete an Activity Execution asynchronously.

  • File Processing: Demonstrates how to download and process a file using set of Activities that run on the same host. Activities are executed to download a file from the web, store it locally on the host, and then "process it". This samples showcases how to handle a scenario where all subsequent Activities need to execute on the same host as the first Activity in the sequence. In Go, this is achieved by using the Session APIs.

  • Particle Swarm Optimization: Demonstrates how to perform a long iterative math optimization process using particle swarm optimization (PSO). This sample showcases the use of parallel executions, ContinueAsNew for long histories, a Query API, and the use of a custom DataConverter for serialization.

  • Polling Services: Recommended implementation of an activity that needs to periodically poll an external resource waiting its successful completion

  • Prometheus Metrics: Demonstrates how to instrument Temporal with Prometheus and Uber's Tally library.

  • Request/Response with Response Activities: Demonstrates how to accept requests via signals and use callback activities to push responses.

  • Request/Response with Response Queries: Demonstrates how to accept requests via signals and use queries to poll for responses.

Pending examples

Mostly examples we haven't yet ported from https://github.com/temporalio/samples-java/

  • Async activity calling: Example to be completed
  • Async lambda: Example to be completed
  • Periodic Workflow: Workflow that executes some logic periodically. Example to be completed
  • Exception propagation and wrapping: Example to be completed
  • Polymorphic activity: Example to be completed
  • Side Effect: Example to be completed - Docs

Fixtures

These are edge case examples useful for Temporal internal development and bug reporting. See their readme for more details.

More Repositories

1

temporal

Temporal service
Go
11,040
star
2

temporalite-archived

An experimental distribution of Temporal that runs as a single process
Go
608
star
3

sdk-typescript

Temporal TypeScript SDK
TypeScript
510
star
4

sdk-python

Temporal Python SDK
Python
446
star
5

sdk-go

Temporal Go SDK
Go
437
star
6

sdk-dotnet

Temporal .NET SDK
C#
373
star
7

samples-typescript

TypeScript
297
star
8

docker-compose

Temporal docker-compose files
Shell
296
star
9

sdk-php

Temporal PHP SDK
PHP
274
star
10

helm-charts

Temporal Helm charts
Mustache
273
star
11

sdk-core

Core Temporal SDK that can be used as a base for language specific Temporal SDKs
Rust
262
star
12

cli

Command-line interface for running Temporal Server and interacting with Workflows, Activities, Namespaces, and other parts of Temporal
Go
246
star
13

sdk-java

Temporal Java SDK
Java
196
star
14

ui

Temporal UI
TypeScript
178
star
15

samples-java

Temporal Java SDK samples
Java
152
star
16

awesome-temporal

A curated list of awesome Temporal libraries and resources.
142
star
17

maru

Benchmarks for Temporal workflows
Go
126
star
18

samples-python

Samples for working with the Temporal Python SDK
Python
117
star
19

samples-php

Temporal PHP SDK samples
PHP
92
star
20

documentation

Temporal documentation
Python
84
star
21

dashboards

Temporal Dashboards
77
star
22

api

Temporal gRPC API and proto files
Makefile
77
star
23

web

Temporal Web UI v1
JavaScript
70
star
24

ui-server

Golang Server for https://github.com/temporalio/ui
Go
66
star
25

proposals

Temporal proposals
66
star
26

experiment-dotnet

Temporal SDK for .NET
C#
65
star
27

snipsync

JavaScript
65
star
28

background-checks

Sample application using Temporal
Go
64
star
29

sdk-ruby

Temporal Ruby SDK
Ruby
64
star
30

temporal-ecommerce

Go
57
star
31

samples-dotnet

Samples for working with the Temporal .NET SDK
C#
52
star
32

money-transfer-project-template-go

Go
47
star
33

tctl

Temporal CLI
Go
43
star
34

samples-server

Go
41
star
35

temporal-polyglot

PHP
35
star
36

tcld

The temporal cloud cli.
Go
32
star
37

docker-builds

Temporal service Docker images build
Shell
27
star
38

api-go

Temporal gRPC API and proto files compiled for Go
Go
27
star
39

temporal-render-simple

temporal-render-simple
Shell
25
star
40

edu-101-go-code

Code used in exercises and demonstrations for the "Temporal 101 with Go" course
CSS
24
star
41

roadrunner-temporal

Temporal PHP-SDK Host Process plugin for Roadrunner
Go
22
star
42

spring-boot-demo

Sample application demonstrating Temporal JavaSDK Spring Boot integration
Java
22
star
43

temporaldotio

Website for temporal.io. Built with Next.js + Preact + Tailwind, hosted on Vercel
JavaScript
20
star
44

vscode-debugger-extension

Visual Studio Code debugger plugin
TypeScript
18
star
45

ringpop-go

Go
17
star
46

temporal-pendulum

Demo showing off Temporal Polyglot features (Java, Go, TypeScript, PHP)
Java
16
star
47

benchmark-workers

Pre-written workflows and activities useful for benchmarking Temporal
Go
14
star
48

features

Behavior and history compatibility testing for Temporal SDKs
Go
13
star
49

subscription-workflow-project-template-go

Go
13
star
50

subscription-workflow-project-template-php

Subscription Workflow Project Template for PHP
PHP
12
star
51

omes

A load generator for Temporal
C#
12
star
52

sagas-temporal-trip-booking

Java
12
star
53

temporal-aws-sdk-go

Temporal activities and workflow stubs that wrap AWS Go SDK
Go
12
star
54

graphql

GraphQL API for Temporal Server
HTML
11
star
55

money-transfer-project-java

Java
11
star
56

subscription-workflow-project-template-typescript

This project template illustrates the design pattern for subscription style business logic.
TypeScript
11
star
57

sdk-scala

Scala SDK for Temporal
10
star
58

terraform-provider-temporalcloud

Terraform provider for Temporal Cloud
Go
10
star
59

replay2024-demo

Demo code and infra
JavaScript
9
star
60

github-repo-notion-sync

Sync an organization's GitHub repo list to a Notion DB
TypeScript
9
star
61

benchmark-matrix

Automated benchmarks for Temporal
TypeScript
8
star
62

api-cloud

Temporal cloud gRPC API and proto files
Makefile
8
star
63

hello-world-project-template-go

Go
7
star
64

temporal-compensating-transactions

A four implementations of the Compensating Transaction pattern in Temporal in go, python, java and typescript
Java
6
star
65

edu-102-go-code

Code used in exercises and demonstrations for the "Temporal 102 with Go" course
Go
6
star
66

xk6-temporal

k6 Extension for testing/benchmarking Temporal
Go
6
star
67

hello-world-project-template-java

Java
6
star
68

money-transfer-project-template-ts

TypeScript
6
star
69

temporal-jumpstart-java

Some repos Start. This one Jump Starts.
Java
5
star
70

subscription-workflow-project-template-java

Subscription workflow project template for Java
Java
5
star
71

edu-101-java-code

Code Exercises for Temporal 101 in java
CSS
4
star
72

edu-101-typescript-code

Code used in exercises and demonstrations for the Temporal 101 (TypeScript) course
CSS
4
star
73

temporal-aws-sdk-generator

AWS SDK Bindings Generator
Go
4
star
74

documentation-samples-python

Python
4
star
75

data-pipeline-project-python

Python
4
star
76

temporal-animations

A toolkit for creating animations explaining Temporal
Python
4
star
77

reference-app-orders-go

Order processing reference application
Go
4
star
78

documentation-samples-go

Go
3
star
79

homebrew-brew

The official Homebrew tap for temporalio
Ruby
3
star
80

docusaurus-plugin-snipsync

Snipsync plugin for docusaurus - insert snippets into markdown files
TypeScript
3
star
81

temporal-demo-infra

Svelte
3
star
82

money-transfer-project-template-python

Python
3
star
83

graphql-proxy

GraphQL API for Temporal Server
Java
3
star
84

background-check-typescript

TypeScript
3
star
85

team

The Temporal team
3
star
86

sdk-php-interceptors-opentelemetry

Opentelemetry interceptors package for PHP SDK
PHP
3
star
87

email-subscription-project-python

Python
3
star
88

temporal-learning

HTML
3
star
89

temporal-development-patterns-whitepapers

Temporal Development Patterns Whitepapers
Java
2
star
90

idea-settings

2
star
91

cloud-samples-go

Temporal Cloud Samples - Go
Go
2
star
92

demo-go

Go
2
star
93

cheatsheets

Cheatsheets for the Temporal CLI
2
star
94

setup-temporal

TypeScript
2
star
95

worker-versioning-replay-demo

TypeScript
2
star
96

ringpop-common

JavaScript
2
star
97

temporal-cafe-typescript

TypeScript
2
star
98

temporal-pause-resume-compensate

Java
2
star
99

temporal-vscode

temporal-vscode
1
star
100

replay-demo-2023

Replay Demo 2023: Workflow Update, Schedules and Worker Versioning
Go
1
star