GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - temporalio/samples-go: Samples for working with the Temporal Go SDK

BranchesTags
Open more actions menu

Latest commit

 

History

443 Commits
443 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
await-signals
await-signals
 
 
batch-sliding-window
batch-sliding-window
 
 
branch
branch
 
 
cancellation
cancellation
 
 
child-workflow-continue-as-new
child-workflow-continue-as-new
 
 
child-workflow
child-workflow
 
 
choice-exclusive
choice-exclusive
 
 
choice-multi
choice-multi
 
 
codec-server
codec-server
 
 
cron
cron
 
 
ctxpropagation
ctxpropagation
 
 
datadog
datadog
 
 
dsl
dsl
 
 
dynamic-workflows
dynamic-workflows
 
 
dynamic
dynamic
 
 
dynamicconfig
dynamicconfig
 
 
dynamicmtls
dynamicmtls
 
 
eager-workflow-start
eager-workflow-start
 
 
early-return
early-return
 
 
encryption
encryption
 
 
expense
expense
 
 
external-env-conf
external-env-conf
 
 
external-storage
external-storage
 
 
fileprocessing
fileprocessing
 
 
gcp/cloudrun
gcp/cloudrun
 
 
googleadk
googleadk
 
 
goroutine
goroutine
 
 
greetings
greetings
 
 
greetingslocal
greetingslocal
 
 
grpc-proxy
grpc-proxy
 
 
helloworld-apiKey
helloworld-apiKey
 
 
helloworld
helloworld
 
 
helloworldmtls
helloworldmtls
 
 
lambda-worker
lambda-worker
 
 
logger-interceptor
logger-interceptor
 
 
memo
memo
 
 
metrics
metrics
 
 
multi-history-replay
multi-history-replay
 
 
mutex
mutex
 
 
nexus-cancelation
nexus-cancelation
 
 
nexus-context-propagation
nexus-context-propagation
 
 
nexus-messaging-temporal-operation
nexus-messaging-temporal-operation
 
 
nexus-messaging
nexus-messaging
 
 
nexus-multiple-arguments
nexus-multiple-arguments
 
 
nexus-serialization-context
nexus-serialization-context
 
 
nexus-standalone-activity
nexus-standalone-activity
 
 
nexus-standalone-operations
nexus-standalone-operations
 
 
nexus
nexus
 
 
opentelemetry-v2
opentelemetry-v2
 
 
opentelemetry
opentelemetry
 
 
pickfirst
pickfirst
 
 
polling
polling
 
 
pso
pso
 
 
query
query
 
 
recovery
recovery
 
 
reqrespactivity
reqrespactivity
 
 
reqrespquery
reqrespquery
 
 
reqrespupdate
reqrespupdate
 
 
retryactivity
retryactivity
 
 
safe_message_handler
safe_message_handler
 
 
saga
saga
 
 
schedule
schedule
 
 
searchattributes
searchattributes
 
 
serverjwtauth
serverjwtauth
 
 
session-failure
session-failure
 
 
shoppingcart
shoppingcart
 
 
sleep-for-days
sleep-for-days
 
 
slogadapter
slogadapter
 
 
snappycompress
snappycompress
 
 
splitmerge-future
splitmerge-future
 
 
splitmerge-selector
splitmerge-selector
 
 
standalone-activity/helloworld
standalone-activity/helloworld
 
 
start-delay
start-delay
 
 
synchronous-proxy
synchronous-proxy
 
 
temporal-fixtures
temporal-fixtures
 
 
timer
timer
 
 
typed-searchattributes
typed-searchattributes
 
 
updatabletimer
updatabletimer
 
 
update
update
 
 
worker-specific-task-queues
worker-specific-task-queues
 
 
worker-versioning
worker-versioning
 
 
workflow-security-interceptor
workflow-security-interceptor
 
 
workflowstreams
workflowstreams
 
 
zapadapter
zapadapter
 
 
.env
.env
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
workflowcheck.config.yaml
workflowcheck.config.yaml
 
 

Repository files navigation

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.

  • Temporal Server repo: temporalio/temporal
  • Temporal Go SDK repo: temporalio/sdk-go
  • Go SDK docs: docs.temporal.io/dev-guide/go

How to use

  • Or run Temporal Server locally with VSCode Remote Containers . Open in Remote - Containers
  • Lastly, you can run Temporal Server locally on your own (follow these instructions), 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.

  • Dynamic mTLS hello world: Simple example showing how to refresh mTLS credentials. This allows for credentials to be refreshed without restarting the worker.

  • Basic apiKey hello world: Simple example of a Workflow Definition and an Activity Definition using API Key to authenticate with Temporal Cloud.

  • Basic external environment configuration: Simple example showing how to configure a client with an external configuration file, like TOML, decoupling connection settings from application code.

  • Standalone Activities: Demonstrates how standalone activities work, where activities can be called from the client directly and not wrapped in an activity.

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 sample 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 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, and 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 sample showcases the HasLastCompletionResult and GetLastCompletionResult APIs which are used to pass information between executions. Note that we recommend using Schedules instead of Cron Jobs. 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 Temporal CLI and Temporal Web. This setup can be used for any kind of codec, common examples are compression or encryption.

  • External Storage: Offload large payloads to S3-compatible object storage plus a codec server built on the SDK's payload HTTP handler so the Web UI and CLI can decode and download the externally-stored payloads.

  • 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 Signals , How to handle Signals .

  • 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.

  • 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.

  • OpenTelemetry: Demonstrates how to instrument the Workflows and Activities with OpenTelemetry.

  • OpenTelemetry v2: Demonstrates replay-safe OpenTelemetry instrumentation with the v2 plugin. The automatic instrumentation sample enables Temporal SDK operation spans and metrics. The custom Workflow-to-Activity and Client-to-Update samples create application spans.

  • 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.

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

  • Workflow Security Interceptor: Demonstrates how to use interceptors to intercept child workflow calls, in this case for validating their type.

  • Update: Demonstrates how to create a workflow that reacts to workflow update requests.

  • Eager Workflow Start: Demonstrates how to start a workflow in eager mode, an experimental latency optimization.

  • Workflow Streams: Demonstrates a durable publish/subscribe log hosted inside a workflow using the workflowstreams contrib package: external code publishes to named topics via signals, subscribers long-poll via updates, and a query exposes the current offset. Includes five scenarios — basic publish/subscribe, a reconnecting subscriber, an external publisher, a truncating ticker, and LLM token streaming.

  • Google ADK agent: Demonstrates running Google ADK (adk-go) agents durably using the googleadk integration: the agent loop runs in a Workflow, the model call runs as an Activity, and a tool is exposed as a durable Activity via ActivityAsTool. Includes scenario subdirectories for a multi-agent system, human-in-the-loop tool approval (durable wait on a signal), a continue-as-new chat, and model-usage metrics.

Dynamic Workflow logic examples

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

  • Dynamic Workflows: Demonstrates how to execute Workflows and Activities dynamically, using a single "Dynamic Workflow"

  • 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 completion of multiple activities invoked in parallel. This sample 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 sample 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.

  • Worker-specific Task Queues: Use a unique task queue per Worker to have certain Activities only run on that specific Worker. For instance for a file processing Workflow, where one Activity downloads a file and subsequent Activities need to operate on that file. (If multiple Workers were on the same queue, subsequent Activities may get run on different machines that don't have the downloaded file.)

Scenario based examples

  • Safe Message Handler: This demonstrates how to safely handle concurrent update and signal requests.

  • 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 sample 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 for 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.

  • Request/Response with Response Updates: Demonstrates how to accept requests and respond via updates.

  • Early-Return: Demonstrates how to receive a response mid-workflow, while the workflow continues to run to completion.

  • Worker Versioning: Demonstrates how to use worker versioning to manage workflow code changes.

Nexus examples

  • Nexus: Demonstrates how to use the Nexus APIs to facilitate cross namespace calls.

  • Nexus Serialization Context: Demonstrates how to select encryption keys and compression by endpoint for synchronous and workflow-backed asynchronous Nexus operations.

  • Nexus Cancelation: Demonstrates how to cancel a Nexus Operation from a caller Workflow.

  • Nexus Context Propagation: Demonstrates how to propagate context through client calls, Workflows, and Nexus headers.

  • Nexus Messaging: Demonstrates how to send signal, update and query messages through Nexus. This contains two samples, one sending messages to an existing Workflow and a second that creates a Workflow through Nexus and sends messages to it.

  • Nexus Messaging Temporal Operation: Demonstrates how to send signal, update and query messages through Nexus. This version uses a generic Nexus handler API in temporalnexus so one operation can return either a sync result or start a Workflow-backed async run from a single Start callback.

  • Nexus Multiple Arguments: Demonstrates how to map a Nexus Operation to a Workflow that takes multiple arguments.

  • Standalone Nexus Operations: Demonstrates how to execute Nexus Operations directly from a Temporal Client, without a caller Workflow.

  • Nexus Standalone Activity: Demonstrates how to back a Nexus Operation with a Standalone Activity.

Serverless

  • Lambda Worker: Demonstrates how to run a Temporal Worker as an AWS Lambda function using the lambdaworker contrib package, with OpenTelemetry instrumentation via AWS Distro for OpenTelemetry (ADOT). Includes IAM role setup and deployment scripts.

Fixtures

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

About

Samples for working with the Temporal Go SDK

docs.temporal.io/docs/go

Topics

durable-executiongolang-examples

Resources

Readme
License
Activity
Custom properties

Stars

758 stars

Watchers

21 watching

Forks

248 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.