1616import io .temporal .serviceclient .WorkflowServiceStubs ;
1717import java .time .Duration ;
1818import java .util .List ;
19- import java .util .UUID ;
2019import java .util .stream .Collectors ;
2120import org .slf4j .Logger ;
2221import org .slf4j .LoggerFactory ;
@@ -31,11 +30,6 @@ public class StandaloneClientStarter {
3130 // Must match the Nexus endpoint configured on the server (see README).
3231 public static final String ENDPOINT_NAME = "nexus-standalone-operation-endpoint" ;
3332
34- // A per-run suffix appended to workflow-backed operation names so their backing workflow IDs are
35- // unique on each run. Without this, re-running against the same server (no restart) would reuse
36- // deterministic workflow IDs from the previous run and collide.
37- private static final String KNOWN_ID = UUID .randomUUID ().toString ().substring (0 , 8 );
38-
3933 public static void main (String [] args ) throws Exception {
4034 WorkflowClient client = ClientOptions .getWorkflowClient ();
4135 WorkflowServiceStubs stubs = client .getWorkflowServiceStubs ();
@@ -63,15 +57,19 @@ private static void demonstrateExecute(NexusServiceClient<GreetingNexusService>
6357 // call. Used here on the synchronous 'greet' operation.
6458 GreetingOutput executed =
6559 nexusClient .execute (
66- GreetingNexusService ::greet , basicOptions (), new GreetingInput ("execute" ));
60+ GreetingNexusService ::greet ,
61+ basicOptions ("execute-nexus" ),
62+ new GreetingInput ("execute" ));
6763 logger .info ("execute() returned: {}" , executed .getMessage ());
6864
6965 // execute(...) is exactly start(...).getResult(): start(...) returns a handle immediately and
7066 // getResult() blocks on that handle until the operation completes. Use this form when you also
7167 // need the handle itself — e.g. its operation ID, or to cancel/terminate/describe it.
7268 NexusOperationHandle <GreetingOutput > handle =
7369 nexusClient .start (
74- GreetingNexusService ::greet , basicOptions (), new GreetingInput ("execute-via-handle" ));
70+ GreetingNexusService ::greet ,
71+ basicOptions ("execute-via-handle-nexus" ),
72+ new GreetingInput ("execute-via-handle" ));
7573 GreetingOutput viaHandle = handle .getResult ();
7674 logger .info (
7775 "start() id={} then getResult() returned: {}" ,
@@ -89,8 +87,8 @@ private static void demonstrateStartAndCancel(
8987 NexusOperationHandle <GreetingOutput > handle =
9088 nexusClient .start (
9189 GreetingNexusService ::startGreeting ,
92- basicOptions (),
93- new GreetingInput ("to-cancel-" + KNOWN_ID ));
90+ basicOptions ("start-and-cancel-nexus" ),
91+ new GreetingInput ("start-and-cancel" ));
9492 logger .info ("Started 'to-cancel' id={}, requesting cancellation" , handle .getNexusOperationId ());
9593 handle .cancel ("standalone-nexus sample: cancel demo" );
9694 // getResult() blocks until the operation reaches a terminal state. A cancelled operation
@@ -119,10 +117,12 @@ private static void demonstrateStartAndCancel(
119117 // ─────────────────────────────────────────────────────────────────────────────────────────────
120118 private static void demonstrateStartAndTerminate (
121119 NexusServiceClient <GreetingNexusService > nexusClient , WorkflowClient client ) {
122- String name = "to-terminate-" + KNOWN_ID ;
120+ String name = "to-terminate" ;
123121 NexusOperationHandle <GreetingOutput > handle =
124122 nexusClient .start (
125- GreetingNexusService ::startGreeting , basicOptions (), new GreetingInput (name ));
123+ GreetingNexusService ::startGreeting ,
124+ basicOptions (name + "-nexus" ),
125+ new GreetingInput (name ));
126126 logger .info ("Started 'to-terminate' id={}, terminating" , handle .getNexusOperationId ());
127127 handle .terminate ("standalone-nexus sample: terminate demo" );
128128 // As with cancel, getResult() blocks until the operation record closes; a terminated operation
@@ -173,11 +173,11 @@ private static NexusClientOptions clientOptions(String namespace) {
173173 }
174174
175175 /** Builds the per-call options used to start a Nexus operation. */
176- private static StartNexusOperationOptions basicOptions () {
176+ private static StartNexusOperationOptions basicOptions (String name ) {
177177 return StartNexusOperationOptions .newBuilder ()
178178 // Required: a namespace-unique operation ID. The SDK never generates one for you, so you
179- // must supply your own (a UUID here) .
180- .setId (UUID . randomUUID (). toString () )
179+ // must supply your own.
180+ .setId (name )
181181 // Total time the caller is willing to wait for the operation to complete, including any
182182 // server-side retries. Defaults to none (bounded only by server limits) if not set.
183183 .setScheduleToCloseTimeout (Duration .ofMinutes (5 ))
0 commit comments