Skip to content

Commit 5b984f8

Browse files
dandavisongithub-actions[bot]jsundai
authored
Nexus copy editing (#3658)
* Java Nexus edits * [AI] Propagate Java edits to Go * CI: Automatic .md and .mdx formatting * Remove incorrect language specifiers * Tweak * Fixups * Fix br tag * admonition * CI: Automatic .md and .mdx formatting --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Jwahir Sundai <[email protected]>
1 parent b5af698 commit 5b984f8

File tree

2 files changed

+89
-98
lines changed

2 files changed

+89
-98
lines changed

docs/develop/go/temporal-nexus.mdx

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,29 @@ This page shows how to do the following:
3535
- [Make Nexus calls across Namespaces with a development Server](#nexus-calls-across-namespaces-dev-server)
3636
- [Make Nexus calls across Namespaces in Temporal Cloud](#nexus-calls-across-namespaces-temporal-cloud)
3737

38-
## Run a development server with Nexus enabled {#run-the-temporal-nexus-development-server}
38+
:::note
3939

40-
The first step in working with Temporal Nexus involves starting a Temporal server with Nexus enabled.
40+
This documentation uses source code derived from the [Go Nexus sample](https://github.com/temporalio/samples-go/tree/main/nexus).
41+
42+
:::
43+
44+
## Run the Temporal Development Server with Nexus enabled {#run-the-temporal-nexus-development-server}
4145

4246
Prerequisites:
4347

4448
- [Install the latest Temporal CLI](https://docs.temporal.io/develop/go/core-application#run-a-development-server) (v1.3.0 or higher recommended)
4549
- [Install the latest Temporal Go SDK](https://docs.temporal.io/develop/go/core-application#install-a-temporal-sdk)
4650
(v1.33.0 or higher recommended)
4751

48-
### Start the Temporal Development Server {#start-the-temporal-development-server}
49-
50-
Start the Temporal Development Server.
52+
The first step in working with Temporal Nexus involves starting a Temporal server with Nexus enabled.
5153

5254
```
5355
temporal server start-dev
5456
```
5557

56-
This command automatically starts the Web UI, creates the default Namespace, and uses an in-memory database.
58+
This command automatically starts the Temporal development server with the Web UI, and creates the `default` Namespace. It uses an in-memory database, so do not use it for real use cases.
5759

58-
The Temporal Server should be available on `localhost:7233` and the Temporal Web UI should be accessible at [http://localhost:8233](http://localhost:8233).
60+
The Temporal Web UI should now be accessible at [http://localhost:8233](http://localhost:8233), and the Temporal Server should now be available for client connections on `localhost:7233`.
5961

6062
## Create caller and handler Namespaces {#create-caller-handler-namespaces}
6163

@@ -66,34 +68,33 @@ temporal operator namespace create --namespace my-target-namespace
6668
temporal operator namespace create --namespace my-caller-namespace
6769
```
6870

71+
`my-target-namespace` will contain the Nexus Operation handler, and we will use a Workflow in `my-caller-namespace` to call that Operation handler.
72+
We use different namespaces to demonstrate cross-Namespace Nexus calls.
73+
6974
## Create a Nexus Endpoint to route requests from caller to handler {#create-nexus-endpoint}
7075

7176
After establishing caller and handler Namespaces, the next step is to create a Nexus Endpoint to route requests.
7277

73-
```go
78+
```
7479
temporal operator nexus endpoint create \
7580
--name my-nexus-endpoint-name \
7681
--target-namespace my-target-namespace \
7782
--target-task-queue my-handler-task-queue
7883
```
7984

80-
## Define the Nexus Service contract {#define-nexus-service-contract}
85+
You can also use the Web UI to create the Namespaces and Nexus endpoint.
8186

82-
Defining a clear contract for the Nexus Service is crucial for smooth communication between services.
83-
84-
[View the source code](https://github.com/temporalio/samples-go/tree/main/nexus) in the context of the rest of the application code.
85-
86-
```
87-
git clone https://github.com/temporalio/samples-go.git
88-
cd samples-go/nexus
89-
```
87+
## Define the Nexus Service contract {#define-nexus-service-contract}
9088

91-
The Nexus Service contract can be in whatever form works best for your environment.
92-
Each [Temporal SDK includes and uses a default Data Converter](https://docs.temporal.io/dataconversion), that encodes payloads in the following order: Null, Byte array, Protobuf JSON, and JSON.
93-
In a polyglot environment, Protobuf and JSON are common choices. This example uses native Go types.
89+
Defining a clear contract for the Nexus Service is crucial for smooth communication.
9490

9591
In this example, there is a service package that describes the Service and Operation names along with input/output types for caller Workflows to use the Nexus Endpoint.
9692

93+
Each [Temporal SDK includes and uses a default Data Converter](https://docs.temporal.io/dataconversion).
94+
The default data converter encodes payloads in the following order: Null, Byte array, Protobuf JSON, and JSON.
95+
In a polyglot environment, that is where more than one language and SDK is being used to develop a Temporal solution, Protobuf and JSON are common choices.
96+
This example uses native Go types.
97+
9798
<!--SNIPSTART samples-go-nexus-service {"selectedLines": ["2-13"]}-->
9899

99100
[nexus/service/api.go](https://github.com/temporalio/samples-go/blob/main/nexus/service/api.go)
@@ -118,13 +119,14 @@ type EchoOutput EchoInput
118119
## Develop a Nexus Service and Operation handlers {#develop-nexus-service-operation-handlers}
119120

120121
Nexus Operation handlers are typically defined in the same Worker as the underlying Temporal primitives they abstract.
121-
Operation handlers can decide if a given Nexus Operation will be synchronous or asynchronous, execute arbitrary code, and invoke underlying Temporal primitives such as a Workflow, Query, Signal, or Update.
122+
Operation handlers can decide if a given Nexus Operation will be synchronous or asynchronous.
123+
They can execute arbitrary code, and invoke underlying Temporal primitives such as a Workflow, Query, Signal, or Update.
122124

123125
The `temporalnexus` package has builders to create Nexus Operations and other helpers for authoring Operation handlers:
124126

125127
- `NewWorkflowRunOperation` \- Run a Workflow as an asynchronous Nexus Operation
126-
- `GetClient` \- Get the Temporal Client that the Worker was initialized with for synchronous RPC handlers backed by
127-
Temporal primitives such as for Signals, and Queries
128+
- `GetClient` \- Get the Temporal Client that the Worker was initialized with for synchronous handlers backed by
129+
Temporal primitives such as Signals and Queries
128130

129131
This tutorial starts with a sync Operation handler example using the `nexus.NewSyncOperation` method, and then shows how to create an async Operation handler that uses `NewWorkflowRunOperation` to start a handler Workflow from a Nexus Operation.
130132

@@ -178,7 +180,7 @@ See alternatives [here](https://pkg.go.dev/go.temporal.io/sdk/temporalnexus).
178180
// ...
179181
var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, HelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) {
180182
return client.StartWorkflowOptions{
181-
// Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts.
183+
// Workflow IDs should typically be business-meaningful IDs and are used to dedupe workflow starts.
182184
// For this example, we're using the request ID allocated by Temporal when the caller workflow schedules
183185
// the operation, this ID is guaranteed to be stable across retries of this operation.
184186
ID: options.RequestID,
@@ -189,7 +191,7 @@ var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperatio
189191

190192
<!--SNIPEND-->
191193

192-
Workflow IDs should typically be business meaningful IDs and are used to dedupe Workflow starts.
194+
Workflow IDs should typically be business-meaningful IDs and are used to dedupe Workflow starts.
193195
For the `HelloOperation`, `input.ID` is passed as part of the Nexus Service contract.
194196

195197
:::tip SUPPORT, STABILITY, and DEPENDENCY INFO
@@ -258,7 +260,7 @@ func main() {
258260

259261
## Develop a caller Workflow that uses the Nexus Service {#develop-caller-workflow-nexus-service}
260262

261-
Import the Service API package, that has the necessary service and operation names and input/output types to execute a Nexus Operation from the caller Workflow:
263+
Import the Service API package that has the necessary service and operation names and input/output types to execute a Nexus Operation from the caller Workflow:
262264

263265
<!--SNIPSTART samples-go-nexus-caller-workflow-->
264266

@@ -425,13 +427,13 @@ func runWorkflow(c client.Client, workflow interface{}, args ...interface{}) {
425427

426428
## Make Nexus calls across Namespaces with a development Server {#nexus-calls-across-namespaces-dev-server}
427429

428-
To run the tutorial, follow the steps below to run the Nexus handler Worker, the Nexus caller Worker, and the starter.
430+
Follow the steps below to run the Nexus handler Worker, the Nexus caller Worker, and the starter.
429431

430432
### Run Workers connected to a local development server
431433

432-
In separate terminal window, run the Nexus handler Worker:
434+
Run the Nexus handler Worker:
433435

434-
```go
436+
```
435437
cd handler
436438
go run ./worker \
437439
-target-host localhost:7233 \
@@ -440,7 +442,7 @@ go run ./worker \
440442

441443
In another terminal window, run the Nexus caller Worker:
442444

443-
```go
445+
```
444446
cd caller
445447
go run ./worker \
446448
-target-host localhost:7233 \
@@ -453,7 +455,7 @@ With the Workers running, the final step in the local development process is to
453455

454456
Run the starter:
455457

456-
```go
458+
```
457459
cd caller
458460
go run ./starter \
459461
-target-host localhost:7233 \
@@ -478,7 +480,7 @@ Only asynchronous operations can be canceled in Nexus, as cancelation is sent us
478480
The Workflow or other resources backing the operation may choose to ignore the cancelation request.
479481
If ignored, the operation may enter a terminal state.
480482

481-
Once the caller Workflow completes, the caller's Nexus Machinery stops attempting to cancel operations that have not yet been canceled, letting them run to completion.
483+
Once the caller Workflow completes, the caller's Nexus Machinery will not make any further attempts to cancel operations that are still running.
482484
It's okay to leave operations running in some use cases.
483485
To ensure cancelations are delivered, wait for all pending operations to finish before exiting the Workflow.
484486

@@ -489,9 +491,9 @@ See the [Nexus cancelation sample](https://github.com/temporalio/samples-go/tree
489491
This section assumes you are already familiar with [how connect a Worker to Temporal Cloud](https://docs.temporal.io/develop/go/core-application#run-a-temporal-cloud-worker).
490492
The same [source code](https://github.com/temporalio/samples-go/tree/main/nexus) is used in this section, but the `tcld` CLI will be used to create Namespaces and the Nexus Endpoint, and mTLS client certificates will be used to securely connect the caller and handler Workers to their respective Temporal Cloud Namespaces.
491493

492-
### Install the latest tcld CLI and generate certificates
494+
### Install the latest `tcld` CLI and generate certificates
493495

494-
To install the latest version of the `tcld` CLI, run the following command:
496+
To install the latest version of the `tcld` CLI, run the following command (on MacOS):
495497

496498
```
497499
brew install temporalio/brew/tcld
@@ -503,10 +505,12 @@ If you don't already have certificates, you can generate them for mTLS Worker au
503505
tcld gen ca --org $YOUR_ORG_NAME --validity-period 1y --ca-cert ca.pem --ca-key ca.key
504506
```
505507

508+
These certificates will be valid for one year.
509+
506510
### Create caller and handler Namespaces
507511

508-
Before deploying to Temporal Cloud, ensure the appropriate Namespaces are created for both the caller and handler.
509-
If you already have these Namespaces, this step is optional.
512+
Before deploying to Temporal Cloud, ensure that the appropriate Namespaces are created for both the caller and handler.
513+
If you already have these Namespaces, you don't need to do this.
510514

511515
```
512516
tcld login
@@ -524,7 +528,7 @@ tcld namespace create \
524528
--retention-days 1
525529
```
526530

527-
Alternatively, you can create Namespace through the UI: [https://cloud.temporal.io/Namespaces](https://cloud.temporal.io/Namespaces).
531+
Alternatively, you can create Namespaces through the UI: [https://cloud.temporal.io/Namespaces](https://cloud.temporal.io/Namespaces).
528532

529533
### Create a Nexus Endpoint to route requests from caller to handler
530534

@@ -542,15 +546,12 @@ tcld nexus endpoint create \
542546
The `--allow-namespace` is used to build an Endpoint allowlist of caller Namespaces that can use the Nexus Endpoint, as described in Runtime Access Control.
543547

544548
Alternatively, you can create a Nexus Endpoint through the UI: [https://cloud.temporal.io/nexus](https://cloud.temporal.io/nexus).
545-
You can also create a Nexus endpoint through the UI in the development server.
546549

547550
### Run Workers Connected to Temporal Cloud with TLS certificates
548551

549-
[View the source code](https://github.com/temporalio/samples-go/tree/main/nexus) in the context of the rest of the application code.
550-
551552
Run the handler Worker:
552553

553-
```go
554+
```
554555
cd handler
555556

556557
go run ./worker \
@@ -562,7 +563,7 @@ go run ./worker \
562563

563564
Run the caller Worker:
564565

565-
```go
566+
```
566567
cd caller
567568

568569
go run ./worker \
@@ -574,9 +575,7 @@ go run ./worker \
574575

575576
### Start a caller Workflow
576577

577-
In order to start the caller Workflow, run the starter.
578-
579-
```go
578+
```
580579
cd caller
581580

582581
go run ./starter \
@@ -599,7 +598,7 @@ This will result in:
599598

600599
Run the handler Worker:
601600

602-
```go
601+
```
603602
cd handler
604603

605604
go run ./worker \
@@ -610,7 +609,7 @@ go run ./worker \
610609

611610
Run the caller Worker:
612611

613-
```go
612+
```
614613
cd caller
615614

616615
go run ./worker \
@@ -621,9 +620,7 @@ go run ./worker \
621620

622621
### Start a caller Workflow
623622

624-
In order to start the caller Workflow, run the starter.
625-
626-
```go
623+
```
627624
cd caller
628625

629626
go run ./starter \
@@ -690,6 +687,6 @@ For **synchronous Nexus Operations** the following are reported in the caller's
690687

691688
## Learn more
692689

693-
- [Evaluate](/evaluate/nexus) why you should use Nexus and watch the [Nexus keynote and demo](https://youtu.be/qqc2vsv1mrU?feature=shared&t=2082).
690+
- Read the high-level description of the [Temporal Nexus feature](/evaluate/nexus) and watch the [Nexus keynote and demo](https://youtu.be/qqc2vsv1mrU?feature=shared&t=2082).
694691
- Learn how Nexus works in the [Nexus deep dive talk](https://www.youtube.com/watch?v=izR9dQ_eIe4) and [Encyclopedia](/nexus).
695692
- Deploy Nexus Endpoints in production with [Temporal Cloud](/cloud/nexus).

0 commit comments

Comments
 (0)