Skip to content

Commit 47a43e2

Browse files
committed
Reviewing
1 parent f6f20ab commit 47a43e2

File tree

11 files changed

+54
-32
lines changed

11 files changed

+54
-32
lines changed

core/src/main/java/io/temporal/samples/nexus_messaging/README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,41 @@ There are **two caller patterns** that share the same handler workflow (`Greetin
2020

2121
### Running
2222

23-
Start a Temporal server and create namespaces/endpoint:
23+
Start a Temporal server:
2424

2525
```bash
2626
temporal server start-dev
27+
```
28+
Create the namespaces and Nexus endpoint:
2729

28-
temporal operator namespace create --namespace nexus-sync-operations-handler-namespace
29-
temporal operator namespace create --namespace nexus-sync-operations-caller-namespace
30+
```bash
31+
temporal operator namespace create --namespace nexus-messaging-handler-namespace
32+
temporal operator namespace create --namespace nexus-messaging-caller-namespace
3033

3134
temporal operator nexus endpoint create \
32-
--name nexus-sync-operations-nexus-endpoint \
33-
--target-namespace nexus-sync-operations-handler-namespace \
34-
--target-task-queue nexus-sync-operations-handler-task-queue
35+
--name nexus-messaging-nexus-endpoint \
36+
--target-namespace nexus-messaging-handler-namespace \
37+
--target-task-queue nexus-messaging-handler-task-queue
3538
```
3639

3740
In one terminal, start the handler worker (shared by both patterns):
3841

3942
```bash
40-
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_sync_operations.handler.HandlerWorker
43+
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_messaging.handler.HandlerWorker
4144
```
4245

4346
#### Entity pattern
4447

45-
In a second terminal, run the caller worker:
48+
In the second terminal, run the caller worker:
4649

4750
```bash
48-
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_sync_operations.caller.CallerWorker
51+
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_messaging.caller.CallerWorker
4952
```
5053

51-
In a third terminal, start the caller workflow:
54+
In the third terminal, start the caller workflow:
5255

5356
```bash
54-
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_sync_operations.caller.CallerStarter
57+
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_messaging.caller.CallerStarter
5558
```
5659

5760
Expected output:
@@ -67,19 +70,19 @@ workflow approved
6770
In a second terminal, run the remote caller worker:
6871

6972
```bash
70-
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_sync_operations.caller_remote.CallerRemoteWorker
73+
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_messaging.caller_remote.CallerRemoteWorker
7174
```
7275

7376
In a third terminal, start the remote caller workflow:
7477

7578
```bash
76-
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_sync_operations.caller_remote.CallerRemoteStarter
79+
./gradlew -q :core:execute -PmainClass=io.temporal.samples.nexus_messaging.caller_remote.CallerRemoteStarter
7780
```
7881

7982
Expected output:
8083

8184
```
82-
started remote greeting workflow: nexus-sync-operations-remote-greeting-workflow
85+
started remote greeting workflow: nexus-messaging-remote-greeting-workflow
8386
supported languages: [CHINESE, ENGLISH]
8487
language changed: ENGLISH -> ARABIC
8588
workflow approved

core/src/main/java/io/temporal/samples/nexus_messaging/caller/CallerStarter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void main(String[] args) {
2020
client.newWorkflowStub(
2121
CallerWorkflow.class,
2222
WorkflowOptions.newBuilder()
23-
.setWorkflowId("nexus-sync-operations-caller-" + UUID.randomUUID())
23+
.setWorkflowId("nexus-messaging-caller-" + UUID.randomUUID())
2424
.setTaskQueue(CallerWorker.TASK_QUEUE)
2525
.build());
2626

core/src/main/java/io/temporal/samples/nexus_messaging/caller/CallerWorker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
public class CallerWorker {
1515
private static final Logger logger = LoggerFactory.getLogger(CallerWorker.class);
1616

17-
public static final String NAMESPACE = "nexus-sync-operations-caller-namespace";
18-
public static final String TASK_QUEUE = "nexus-sync-operations-caller-task-queue";
19-
static final String NEXUS_ENDPOINT = "nexus-sync-operations-nexus-endpoint";
17+
public static final String NAMESPACE = "nexus-messaging-caller-namespace";
18+
public static final String TASK_QUEUE = "nexus-messaging-caller-task-queue";
19+
static final String NEXUS_ENDPOINT = "nexus-messaging-nexus-endpoint";
2020

2121
public static void main(String[] args) throws InterruptedException {
2222
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
@@ -29,6 +29,7 @@ public static void main(String[] args) throws InterruptedException {
2929
worker.registerWorkflowImplementationTypes(
3030
WorkflowImplementationOptions.newBuilder()
3131
.setNexusServiceOptions(
32+
// The key must match the @Service-annotated interface name.
3233
Collections.singletonMap(
3334
"NexusGreetingService",
3435
NexusServiceOptions.newBuilder().setEndpoint(NEXUS_ENDPOINT).build()))

core/src/main/java/io/temporal/samples/nexus_messaging/caller/CallerWorkflowImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.temporal.samples.nexus_messaging.caller;
22

33
import io.temporal.failure.ApplicationFailure;
4+
import io.temporal.samples.nexus_messaging.caller_remote.CallerRemoteWorkflowImpl;
45
import io.temporal.samples.nexus_messaging.service.Language;
56
import io.temporal.samples.nexus_messaging.service.NexusGreetingService;
67
import io.temporal.workflow.NexusOperationOptions;
@@ -9,9 +10,13 @@
910
import java.time.Duration;
1011
import java.util.ArrayList;
1112
import java.util.List;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1215

1316
public class CallerWorkflowImpl implements CallerWorkflow {
1417

18+
private static final Logger logger = LoggerFactory.getLogger(CallerRemoteWorkflowImpl.class);
19+
1520
// The endpoint is configured at the worker level in CallerWorker; only operation options are
1621
// set here.
1722
NexusGreetingService greetingService =
@@ -36,6 +41,7 @@ public List<String> run() {
3641
// 👉 Call a Nexus operation backed by an update against the entity workflow.
3742
Language previousLanguage =
3843
greetingService.setLanguage(new NexusGreetingService.SetLanguageInput(Language.ARABIC));
44+
logger.info("Language changed from {} to {}", previousLanguage, Language.ARABIC);
3945

4046
// 👉 Call a Nexus operation backed by a query to confirm the language change.
4147
Language currentLanguage =

core/src/main/java/io/temporal/samples/nexus_messaging/caller_remote/CallerRemoteStarter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void main(String[] args) {
2020
client.newWorkflowStub(
2121
CallerRemoteWorkflow.class,
2222
WorkflowOptions.newBuilder()
23-
.setWorkflowId("nexus-sync-operations-remote-caller-" + UUID.randomUUID())
23+
.setWorkflowId("nexus-messaging-remote-caller-" + UUID.randomUUID())
2424
.setTaskQueue(CallerRemoteWorker.TASK_QUEUE)
2525
.build());
2626

core/src/main/java/io/temporal/samples/nexus_messaging/caller_remote/CallerRemoteWorker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
public class CallerRemoteWorker {
1515
private static final Logger logger = LoggerFactory.getLogger(CallerRemoteWorker.class);
1616

17-
public static final String NAMESPACE = "nexus-sync-operations-caller-namespace";
18-
public static final String TASK_QUEUE = "nexus-sync-operations-caller-remote-task-queue";
19-
static final String NEXUS_ENDPOINT = "nexus-sync-operations-nexus-endpoint";
17+
public static final String NAMESPACE = "nexus-messaging-caller-namespace";
18+
public static final String TASK_QUEUE = "nexus-messaging-caller-remote-task-queue";
19+
static final String NEXUS_ENDPOINT = "nexus-messaging-nexus-endpoint";
2020

2121
public static void main(String[] args) throws InterruptedException {
2222
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
@@ -29,6 +29,7 @@ public static void main(String[] args) throws InterruptedException {
2929
worker.registerWorkflowImplementationTypes(
3030
WorkflowImplementationOptions.newBuilder()
3131
.setNexusServiceOptions(
32+
// The key must match the @Service-annotated interface name.
3233
Collections.singletonMap(
3334
"NexusRemoteGreetingService",
3435
NexusServiceOptions.newBuilder().setEndpoint(NEXUS_ENDPOINT).build()))

core/src/main/java/io/temporal/samples/nexus_messaging/caller_remote/CallerRemoteWorkflowImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class CallerRemoteWorkflowImpl implements CallerRemoteWorkflow {
1717

1818
private static final Logger logger = LoggerFactory.getLogger(CallerRemoteWorkflowImpl.class);
1919

20-
private static final String REMOTE_WORKFLOW_ID = "nexus-sync-operations-remote-greeting-workflow";
20+
private static final String REMOTE_WORKFLOW_ID = "nexus-messaging-remote-greeting-workflow";
2121

2222
NexusRemoteGreetingService greetingRemoteService =
2323
Workflow.newNexusServiceStub(
@@ -33,7 +33,9 @@ public class CallerRemoteWorkflowImpl implements CallerRemoteWorkflow {
3333
public List<String> run() {
3434
List<String> log = new ArrayList<>();
3535

36-
// Start a new GreetingWorkflow on the handler side via Nexus.
36+
// 👉 Async Nexus operation — starts a workflow on the handler and returns a handle.
37+
// Unlike the sync operations below (getLanguages, setLanguage, etc.), this does not block
38+
// until the workflow completes. It is backed by WorkflowRunOperation on the handler side.
3739
NexusOperationHandle<String> handle =
3840
Workflow.startNexusOperation(
3941
greetingRemoteService::runFromRemote,
@@ -43,6 +45,8 @@ public List<String> run() {
4345
log.add("started remote greeting workflow: " + REMOTE_WORKFLOW_ID);
4446

4547
// Query the remote workflow for supported languages.
48+
// Output types (e.g. GetLanguagesOutput) are defined on NexusGreetingService and shared by
49+
// both service interfaces.
4650
NexusGreetingService.GetLanguagesOutput languagesOutput =
4751
greetingRemoteService.getLanguages(
4852
new NexusRemoteGreetingService.GetLanguagesInput(false, REMOTE_WORKFLOW_ID));
@@ -52,7 +56,7 @@ public List<String> run() {
5256
Language previousLanguage =
5357
greetingRemoteService.setLanguage(
5458
new NexusRemoteGreetingService.SetLanguageInput(Language.ARABIC, REMOTE_WORKFLOW_ID));
55-
logger.info("Language changed from {}", previousLanguage);
59+
logger.info("Language changed from {} to {}", previousLanguage, Language.ARABIC);
5660

5761
// Confirm the change by querying.
5862
Language currentLanguage =

core/src/main/java/io/temporal/samples/nexus_messaging/handler/GreetingWorkflowImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class GreetingWorkflowImpl implements GreetingWorkflow {
2222
private final Map<Language, String> greetings = new EnumMap<>(Language.class);
2323
private Language language = Language.ENGLISH;
2424

25-
private static final Logger logger = LoggerFactory.getLogger(HandlerWorker.class);
25+
private static final Logger logger = LoggerFactory.getLogger(GreetingWorkflowImpl.class);
2626

2727
// Used to serialize concurrent setLanguageUsingActivity calls so that only one activity runs at
2828
// a time per update handler execution.

core/src/main/java/io/temporal/samples/nexus_messaging/handler/HandlerWorker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
public class HandlerWorker {
1414
private static final Logger logger = LoggerFactory.getLogger(HandlerWorker.class);
1515

16-
public static final String NAMESPACE = "nexus-sync-operations-handler-namespace";
17-
public static final String TASK_QUEUE = "nexus-sync-operations-handler-task-queue";
18-
static final String WORKFLOW_ID = "nexus-sync-operations-greeting-workflow";
16+
public static final String NAMESPACE = "nexus-messaging-handler-namespace";
17+
public static final String TASK_QUEUE = "nexus-messaging-handler-task-queue";
18+
static final String WORKFLOW_ID = "nexus-messaging-greeting-workflow";
1919

2020
public static void main(String[] args) throws InterruptedException {
2121
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();

core/src/main/java/io/temporal/samples/nexus_messaging/handler/NexusGreetingServiceImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ public OperationHandler<NexusGreetingService.GetLanguageInput, Language> getLang
5353
});
5454
}
5555

56-
// 👉 Backed by an update against the long-running entity workflow. Although updates can run for
57-
// an arbitrarily long time, when exposed via a sync Nexus operation the update should complete
58-
// quickly (sync operations must finish in under 10s).
56+
// 👉 Backed by an update against the long-running entity workflow. Routes to
57+
// setLanguageUsingActivity (not setLanguage) so that new languages not already in the greetings
58+
// map can be fetched via an activity. Although updates can run for an arbitrarily long time, when
59+
// exposed via a sync Nexus operation the update should complete quickly (sync operations must
60+
// finish in under 10s).
5961
@OperationImpl
6062
public OperationHandler<NexusGreetingService.SetLanguageInput, Language> setLanguage() {
6163
return OperationHandler.sync(

0 commit comments

Comments
 (0)