From 348b514aabdaa259575858b28a0b9bde5f217ec6 Mon Sep 17 00:00:00 2001 From: Thomas Hardy Date: Fri, 26 Sep 2025 02:45:54 -0400 Subject: [PATCH] Update samples to use env config --- core/build.gradle | 3 ++ .../temporal/samples/apikey/ApiKeyWorker.java | 19 ++++++++++-- .../io/temporal/samples/apikey/Starter.java | 19 ++++++++++-- .../temporal/samples/asyncchild/Starter.java | 31 ++++++++++++++----- .../samples/asyncuntypedchild/Starter.java | 15 +++++++-- .../samples/autoheartbeat/Starter.java | 15 +++++++-- .../HeartbeatingActivityBatchStarter.java | 16 ++++++++-- .../HeartbeatingActivityBatchWorker.java | 15 +++++++-- .../batch/iterator/IteratorBatchStarter.java | 16 ++++++++-- .../batch/iterator/IteratorBatchWorker.java | 15 +++++++-- .../SlidingWindowBatchStarter.java | 16 ++++++++-- .../SlidingWindowBatchWorker.java | 15 +++++++-- .../bookingsaga/TripBookingClient.java | 17 ++++++++-- .../bookingsaga/TripBookingWorker.java | 17 ++++++++-- .../bookingsyncsaga/TripBookingClient.java | 17 ++++++++-- .../bookingsyncsaga/TripBookingWorker.java | 15 +++++++-- .../common/QueryWorkflowExecution.java | 15 +++++++-- .../countinterceptor/InterceptorStarter.java | 13 +++++++- .../customannotation/CustomAnnotation.java | 15 +++++++-- .../CustomChangeVersionStarter.java | 15 +++++++-- .../java/io/temporal/samples/dsl/Starter.java | 19 ++++++++---- .../earlyreturn/EarlyReturnClient.java | 15 +++++++-- .../samples/encodefailures/Starter.java | 13 +++++++- .../EncryptedPayloadsActivity.java | 13 +++++++- .../RunMyWorkflows.java | 15 +++++++-- .../fileprocessing/FileProcessingStarter.java | 17 ++++++++-- .../fileprocessing/FileProcessingWorker.java | 17 ++++++++-- .../samples/getresultsasync/Worker.java | 23 ++++++++++++-- .../samples/hello/HelloAccumulator.java | 19 +++++++----- .../temporal/samples/hello/HelloActivity.java | 15 +++++++-- .../hello/HelloActivityExclusiveChoice.java | 15 +++++++-- .../samples/hello/HelloActivityRetry.java | 18 +++++++---- .../io/temporal/samples/hello/HelloAsync.java | 19 ++++++++---- .../hello/HelloAsyncActivityCompletion.java | 20 +++++++----- .../samples/hello/HelloAsyncLambda.java | 19 ++++++++---- .../io/temporal/samples/hello/HelloAwait.java | 19 ++++++++---- .../samples/hello/HelloCancellationScope.java | 19 ++++++++---- .../HelloCancellationScopeWithTimer.java | 15 +++++++-- .../io/temporal/samples/hello/HelloChild.java | 19 ++++++++---- .../io/temporal/samples/hello/HelloCron.java | 19 ++++++++---- .../samples/hello/HelloDelayedStart.java | 19 ++++++++---- .../hello/HelloDetachedCancellationScope.java | 15 +++++++-- .../temporal/samples/hello/HelloDynamic.java | 20 +++++++----- .../hello/HelloEagerWorkflowStart.java | 19 ++++++++---- .../samples/hello/HelloException.java | 18 +++++++---- .../samples/hello/HelloLocalActivity.java | 17 ++++++++-- .../samples/hello/HelloParallelActivity.java | 19 ++++++++---- .../temporal/samples/hello/HelloPeriodic.java | 19 ++++++++---- .../hello/HelloPolymorphicActivity.java | 19 ++++++++---- .../io/temporal/samples/hello/HelloQuery.java | 19 ++++++++---- .../io/temporal/samples/hello/HelloSaga.java | 19 ++++++++---- .../samples/hello/HelloSchedules.java | 19 ++++++++---- .../samples/hello/HelloSearchAttributes.java | 19 ++++++++---- .../samples/hello/HelloSideEffect.java | 20 +++++++----- .../temporal/samples/hello/HelloSignal.java | 19 ++++++++---- .../HelloSignalWithStartAndWorkflowInit.java | 15 +++++++-- .../samples/hello/HelloSignalWithTimer.java | 15 +++++++-- .../hello/HelloTypedSearchAttributes.java | 19 ++++++++---- .../temporal/samples/hello/HelloUpdate.java | 19 ++++++++---- .../samples/hello/HelloWorkflowTimer.java | 17 ++++++++-- .../awsencryptionsdk/EncryptedPayloads.java | 13 +++++++- .../samples/listworkflows/Starter.java | 20 ++++++++++-- .../samples/metrics/MetricsStarter.java | 18 +++++++++-- .../samples/metrics/MetricsWorker.java | 18 +++++++++-- .../moneybatch/AccountActivityWorker.java | 15 +++++++-- .../moneybatch/AccountTransferWorker.java | 15 +++++++-- .../samples/moneybatch/TransferRequester.java | 16 ++++++++-- .../moneytransfer/AccountActivityWorker.java | 17 ++++++++-- .../moneytransfer/AccountTransferWorker.java | 17 ++++++++-- .../moneytransfer/TransferRequester.java | 16 ++++++++-- .../samples/packetdelivery/Starter.java | 15 +++++++-- .../payloadconverter/cloudevents/Starter.java | 13 +++++++- .../payloadconverter/crypto/Starter.java | 13 +++++++- .../samples/peractivityoptions/Starter.java | 18 +++++++++-- .../frequent/FrequentPollingStarter.java | 20 ++++++++++-- .../infrequent/InfrequentPollingStarter.java | 20 ++++++++++-- ...nfrequentPollingWithRetryAfterStarter.java | 20 ++++++++++-- .../PeriodicPollingStarter.java | 20 ++++++++++-- .../FailureRequester.java | 15 +++++++-- .../MyWorkflowWorker.java | 15 +++++++-- .../QueryRequester.java | 15 +++++++-- .../RetryRequester.java | 15 +++++++-- .../ClusterManagerWorkflowStarter.java | 15 +++++++-- .../ClusterManagerWorkflowWorker.java | 15 +++++++-- .../samples/sleepfordays/Starter.java | 17 +++++++++- .../temporal/samples/sleepfordays/Worker.java | 18 +++++++++-- .../samples/terminateworkflow/Starter.java | 27 +++++++++++----- .../io/temporal/samples/tracing/Starter.java | 18 +++++++++-- .../samples/tracing/TracingWorker.java | 16 ++++++++-- .../DynamicSleepWorkflowStarter.java | 15 +++++++-- .../DynamicSleepWorkflowWorker.java | 15 +++++++-- .../updatabletimer/WakeUpTimeUpdater.java | 15 +++++++-- .../samples/workerversioning/Starter.java | 16 ++++++++-- .../samples/workerversioning/WorkerV1.java | 15 +++++++-- .../samples/workerversioning/WorkerV1_1.java | 15 +++++++-- .../samples/workerversioning/WorkerV2.java | 15 +++++++-- springboot/build.gradle | 3 ++ 97 files changed, 1315 insertions(+), 316 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 42ad4be2b..72ced375b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -4,6 +4,9 @@ dependencies { implementation "io.temporal:temporal-opentracing:$javaSDKVersion" testImplementation("io.temporal:temporal-testing:$javaSDKVersion") + // Environment configuration + implementation "io.temporal:temporal-envconfig" + // Needed for SDK related functionality implementation(platform("com.fasterxml.jackson:jackson-bom:2.17.2")) implementation "com.fasterxml.jackson.core:jackson-databind" diff --git a/core/src/main/java/io/temporal/samples/apikey/ApiKeyWorker.java b/core/src/main/java/io/temporal/samples/apikey/ApiKeyWorker.java index 7425b88d6..2c4a326d4 100644 --- a/core/src/main/java/io/temporal/samples/apikey/ApiKeyWorker.java +++ b/core/src/main/java/io/temporal/samples/apikey/ApiKeyWorker.java @@ -2,15 +2,25 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.serviceclient.WorkflowServiceStubsOptions; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class ApiKeyWorker { static final String TASK_QUEUE = "MyTaskQueue"; public static void main(String[] args) throws Exception { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + // For temporal cloud this would be ${cloud-region}.{cloud}.api.temporal.io:7233 // Example us-east-1.aws.api.temporal.io:7233 String targetEndpoint = System.getenv("TEMPORAL_ENDPOINT"); @@ -24,10 +34,10 @@ public static void main(String[] args) throws Exception { "TEMPORAL_ENDPOINT, TEMPORAL_NAMESPACE, and TEMPORAL_API_KEY environment variables must be set"); } - // Create API Key enabled client + // Create API Key enabled client with environment config as base WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs( - WorkflowServiceStubsOptions.newBuilder() + WorkflowServiceStubsOptions.newBuilder(profile.toWorkflowServiceStubsOptions()) .setTarget(targetEndpoint) .setEnableHttps(true) .addApiKey(() -> apiKey) @@ -36,7 +46,10 @@ public static void main(String[] args) throws Exception { // Now setup and start workflow worker WorkflowClient client = WorkflowClient.newInstance( - service, WorkflowClientOptions.newBuilder().setNamespace(namespace).build()); + service, + WorkflowClientOptions.newBuilder(profile.toWorkflowClientOptions()) + .setNamespace(namespace) + .build()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/apikey/Starter.java b/core/src/main/java/io/temporal/samples/apikey/Starter.java index 60afe7c21..ac0fbce8c 100644 --- a/core/src/main/java/io/temporal/samples/apikey/Starter.java +++ b/core/src/main/java/io/temporal/samples/apikey/Starter.java @@ -3,10 +3,12 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.serviceclient.WorkflowServiceStubsOptions; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class Starter { @@ -14,6 +16,14 @@ public class Starter { static final String WORKFLOW_ID = "HelloAPIKeyWorkflow"; public static void main(String[] args) throws Exception { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + // For temporal cloud this would be ${cloud-region}.{cloud}.api.temporal.io:7233 // Example us-east-1.aws.api.temporal.io:7233 String targetEndpoint = System.getenv("TEMPORAL_ENDPOINT"); @@ -27,10 +37,10 @@ public static void main(String[] args) throws Exception { "TEMPORAL_ENDPOINT, TEMPORAL_NAMESPACE, and TEMPORAL_API_KEY environment variables must be set"); } - // Create API Key enabled client + // Create API Key enabled client with environment config as base WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs( - WorkflowServiceStubsOptions.newBuilder() + WorkflowServiceStubsOptions.newBuilder(profile.toWorkflowServiceStubsOptions()) .setTarget(targetEndpoint) .setEnableHttps(true) .addApiKey(() -> apiKey) @@ -38,7 +48,10 @@ public static void main(String[] args) throws Exception { WorkflowClient client = WorkflowClient.newInstance( - service, WorkflowClientOptions.newBuilder().setNamespace(namespace).build()); + service, + WorkflowClientOptions.newBuilder(profile.toWorkflowClientOptions()) + .setNamespace(namespace) + .build()); WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/asyncchild/Starter.java b/core/src/main/java/io/temporal/samples/asyncchild/Starter.java index b02f0dc4c..339bd94fd 100644 --- a/core/src/main/java/io/temporal/samples/asyncchild/Starter.java +++ b/core/src/main/java/io/temporal/samples/asyncchild/Starter.java @@ -6,20 +6,32 @@ import io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.util.concurrent.TimeUnit; public class Starter { public static final String TASK_QUEUE = "asyncChildTaskQueue"; - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); - private static final WorkerFactory factory = WorkerFactory.newInstance(client); public static void main(String[] args) { - createWorker(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + WorkerFactory factory = WorkerFactory.newInstance(client); + + createWorker(factory); WorkflowOptions parentWorkflowOptions = WorkflowOptions.newBuilder() @@ -33,25 +45,28 @@ public static void main(String[] args) { WorkflowExecution childWorkflowExecution = parentWorkflowStub.executeParent(); // Get the child workflow execution status (after parent completed) - System.out.println("Child execution status: " + getStatusAsString(childWorkflowExecution)); + System.out.println( + "Child execution status: " + getStatusAsString(childWorkflowExecution, client, service)); // Wait for child workflow to complete sleep(4); // Check the status of the child workflow again - System.out.println("Child execution status: " + getStatusAsString(childWorkflowExecution)); + System.out.println( + "Child execution status: " + getStatusAsString(childWorkflowExecution, client, service)); System.exit(0); } - private static void createWorker() { + private static void createWorker(WorkerFactory factory) { Worker worker = factory.newWorker(TASK_QUEUE); worker.registerWorkflowImplementationTypes(ParentWorkflowImpl.class, ChildWorkflowImpl.class); factory.start(); } - private static String getStatusAsString(WorkflowExecution execution) { + private static String getStatusAsString( + WorkflowExecution execution, WorkflowClient client, WorkflowServiceStubs service) { DescribeWorkflowExecutionRequest describeWorkflowExecutionRequest = DescribeWorkflowExecutionRequest.newBuilder() .setNamespace(client.getOptions().getNamespace()) diff --git a/core/src/main/java/io/temporal/samples/asyncuntypedchild/Starter.java b/core/src/main/java/io/temporal/samples/asyncuntypedchild/Starter.java index 6cf9da20f..885a0c05c 100644 --- a/core/src/main/java/io/temporal/samples/asyncuntypedchild/Starter.java +++ b/core/src/main/java/io/temporal/samples/asyncuntypedchild/Starter.java @@ -2,9 +2,11 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; /** * Sample Temporal Workflow Definition that demonstrates the execution of a Child Workflow. Child @@ -24,12 +26,21 @@ public class Starter { public static void main(String[] args) { // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); /* * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/autoheartbeat/Starter.java b/core/src/main/java/io/temporal/samples/autoheartbeat/Starter.java index 67bb97ec3..ae438cc41 100644 --- a/core/src/main/java/io/temporal/samples/autoheartbeat/Starter.java +++ b/core/src/main/java/io/temporal/samples/autoheartbeat/Starter.java @@ -22,6 +22,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.CanceledFailure; import io.temporal.samples.autoheartbeat.activities.AutoActivitiesImpl; import io.temporal.samples.autoheartbeat.interceptor.AutoHeartbeatWorkerInterceptor; @@ -31,14 +32,24 @@ import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerFactoryOptions; +import java.io.IOException; public class Starter { static final String TASK_QUEUE = "AutoheartbeatTaskQueue"; static final String WORKFLOW_ID = "AutoHeartbeatWorkflow"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Configure our auto heartbeat workflow interceptor which will apply // AutoHeartbeaterUtil to each activity workflow schedules which has a heartbeat diff --git a/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchStarter.java b/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchStarter.java index 89bb5652c..90dcb7c10 100644 --- a/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchStarter.java +++ b/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchStarter.java @@ -5,14 +5,26 @@ import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; /** Starts a single execution of HeartbeatingActivityBatchWorkflow. */ public class HeartbeatingActivityBatchStarter { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient workflowClient = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient workflowClient = + WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build(); HeartbeatingActivityBatchWorkflow batchWorkflow = workflowClient.newWorkflowStub(HeartbeatingActivityBatchWorkflow.class, options); diff --git a/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchWorker.java b/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchWorker.java index 9d2d7b4e1..cd63bacf5 100644 --- a/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchWorker.java +++ b/core/src/main/java/io/temporal/samples/batch/heartbeatingactivity/HeartbeatingActivityBatchWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.batch.heartbeatingactivity; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; /** * A worker process that hosts implementations of HeartbeatingActivityBatchWorkflow and @@ -14,8 +16,17 @@ public final class HeartbeatingActivityBatchWorker { static final String TASK_QUEUE = "HeartbeatingActivityBatch"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchStarter.java b/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchStarter.java index c89fc590c..fa43c467f 100644 --- a/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchStarter.java +++ b/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchStarter.java @@ -5,14 +5,26 @@ import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; /** Starts a single execution of IteratorBatchWorkflow. */ public class IteratorBatchStarter { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient workflowClient = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient workflowClient = + WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build(); IteratorBatchWorkflow batchWorkflow = workflowClient.newWorkflowStub(IteratorBatchWorkflow.class, options); diff --git a/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchWorker.java b/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchWorker.java index 88b8eacb7..adc023d7b 100644 --- a/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchWorker.java +++ b/core/src/main/java/io/temporal/samples/batch/iterator/IteratorBatchWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.batch.iterator; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; /** * A worker process that hosts implementations of IteratorBatchWorkflow and RecordProcessorWorkflow @@ -14,8 +16,17 @@ public final class IteratorBatchWorker { static final String TASK_QUEUE = "IteratorBatch"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchStarter.java b/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchStarter.java index f4d689f4a..e3a6b062d 100644 --- a/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchStarter.java +++ b/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchStarter.java @@ -4,14 +4,26 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class SlidingWindowBatchStarter { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient workflowClient = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient workflowClient = + WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build(); BatchWorkflow batchWorkflow = workflowClient.newWorkflowStub(BatchWorkflow.class, options); WorkflowClient.start(batchWorkflow::processBatch, 10, 25, 3); diff --git a/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchWorker.java b/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchWorker.java index 32dd8e09c..20caa5ead 100644 --- a/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchWorker.java +++ b/core/src/main/java/io/temporal/samples/batch/slidingwindow/SlidingWindowBatchWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.batch.slidingwindow; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; /** Hosts sliding window batch sample workflow and activity implementations. */ public final class SlidingWindowBatchWorker { @@ -11,8 +13,17 @@ public final class SlidingWindowBatchWorker { static final String TASK_QUEUE = "SlidingWindow"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingClient.java b/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingClient.java index b791065da..cb7d1e594 100644 --- a/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingClient.java +++ b/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingClient.java @@ -3,17 +3,28 @@ import com.google.common.base.Throwables; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class TripBookingClient { static final String TASK_QUEUE = "TripBooking"; public static void main(String[] args) { - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).setWorkflowId("Booking1").build(); diff --git a/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorker.java b/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorker.java index b538e0942..6c0fb87b2 100644 --- a/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorker.java +++ b/core/src/main/java/io/temporal/samples/bookingsaga/TripBookingWorker.java @@ -1,18 +1,29 @@ package io.temporal.samples.bookingsaga; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class TripBookingWorker { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingClient.java b/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingClient.java index cebbc93b8..74aa32b86 100644 --- a/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingClient.java +++ b/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingClient.java @@ -3,17 +3,28 @@ import com.google.common.base.Throwables; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class TripBookingClient { static final String TASK_QUEUE = "TripBookingSync"; public static void main(String[] args) { - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).setWorkflowId("Booking1").build(); diff --git a/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingWorker.java b/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingWorker.java index 151bd62ae..c70dc9481 100644 --- a/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingWorker.java +++ b/core/src/main/java/io/temporal/samples/bookingsyncsaga/TripBookingWorker.java @@ -1,18 +1,29 @@ package io.temporal.samples.bookingsyncsaga; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class TripBookingWorker { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java b/core/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java index 9be315a8a..9f9cbe797 100644 --- a/core/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java +++ b/core/src/main/java/io/temporal/samples/common/QueryWorkflowExecution.java @@ -3,7 +3,9 @@ import io.temporal.api.common.v1.WorkflowExecution; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import java.util.Optional; /** @@ -27,9 +29,18 @@ public static void main(String[] args) { String runId = args.length == 3 ? args[2] : ""; // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowExecution workflowExecution = WorkflowExecution.newBuilder().setWorkflowId(workflowId).setRunId(runId).build(); diff --git a/core/src/main/java/io/temporal/samples/countinterceptor/InterceptorStarter.java b/core/src/main/java/io/temporal/samples/countinterceptor/InterceptorStarter.java index bf8ddd793..30c73c14f 100644 --- a/core/src/main/java/io/temporal/samples/countinterceptor/InterceptorStarter.java +++ b/core/src/main/java/io/temporal/samples/countinterceptor/InterceptorStarter.java @@ -5,6 +5,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.common.interceptors.WorkflowClientInterceptor; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.countinterceptor.activities.MyActivitiesImpl; import io.temporal.samples.countinterceptor.workflow.MyChildWorkflowImpl; import io.temporal.samples.countinterceptor.workflow.MyWorkflow; @@ -13,6 +14,7 @@ import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerFactoryOptions; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +31,16 @@ public static void main(String[] args) { final ClientCounter clientCounter = new ClientCounter(); final WorkflowClientInterceptor clientInterceptor = new SimpleClientInterceptor(clientCounter); - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); WorkflowClient client = WorkflowClient.newInstance( service, WorkflowClientOptions.newBuilder().setInterceptors(clientInterceptor).build()); diff --git a/core/src/main/java/io/temporal/samples/customannotation/CustomAnnotation.java b/core/src/main/java/io/temporal/samples/customannotation/CustomAnnotation.java index 9f9fc667d..db6df4229 100644 --- a/core/src/main/java/io/temporal/samples/customannotation/CustomAnnotation.java +++ b/core/src/main/java/io/temporal/samples/customannotation/CustomAnnotation.java @@ -24,6 +24,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -31,6 +32,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; public class CustomAnnotation { @@ -132,12 +134,21 @@ public synchronized String composeGreeting(String greeting, String name) { public static void main(String[] args) { // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); /* * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/customchangeversion/CustomChangeVersionStarter.java b/core/src/main/java/io/temporal/samples/customchangeversion/CustomChangeVersionStarter.java index 82921b8dc..3bd8497b7 100644 --- a/core/src/main/java/io/temporal/samples/customchangeversion/CustomChangeVersionStarter.java +++ b/core/src/main/java/io/temporal/samples/customchangeversion/CustomChangeVersionStarter.java @@ -8,22 +8,33 @@ import io.temporal.client.WorkflowServiceException; import io.temporal.common.SearchAttributeKey; import io.temporal.common.SearchAttributes; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.OperatorServiceStubs; import io.temporal.serviceclient.OperatorServiceStubsOptions; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.util.Collections; public class CustomChangeVersionStarter { private static SearchAttributeKey CUSTOM_CHANGE_VERSION = SearchAttributeKey.forKeyword("CustomChangeVersion"); - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); private static final String taskQueue = "customChangeVersionTaskQueue"; private static final String workflowId = "CustomChangeVersionWorkflow"; public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory workerFactory = WorkerFactory.newInstance(client); Worker worker = workerFactory.newWorker(taskQueue); diff --git a/core/src/main/java/io/temporal/samples/dsl/Starter.java b/core/src/main/java/io/temporal/samples/dsl/Starter.java index e0336d659..257531048 100644 --- a/core/src/main/java/io/temporal/samples/dsl/Starter.java +++ b/core/src/main/java/io/temporal/samples/dsl/Starter.java @@ -3,22 +3,29 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.dsl.model.Flow; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class Starter { - public static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - public static final WorkflowClient client = WorkflowClient.newInstance(service); - public static final WorkerFactory factory = WorkerFactory.newInstance(client); - public static void main(String[] args) { Flow flow = getFlowFromResource(); - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker("dsl-task-queue"); worker.registerWorkflowImplementationTypes(DslWorkflowImpl.class); diff --git a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java index 623efa310..3abd20a7c 100644 --- a/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java +++ b/core/src/main/java/io/temporal/samples/earlyreturn/EarlyReturnClient.java @@ -2,7 +2,9 @@ import io.temporal.api.enums.v1.WorkflowIdConflictPolicy; import io.temporal.client.*; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class EarlyReturnClient { private static final String TASK_QUEUE = "EarlyReturnTaskQueue"; @@ -15,8 +17,17 @@ public static void main(String[] args) { // Set up the WorkflowClient public static WorkflowClient setupWorkflowClient() { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - return WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + return WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); } // Run workflow using 'updateWithStart' diff --git a/core/src/main/java/io/temporal/samples/encodefailures/Starter.java b/core/src/main/java/io/temporal/samples/encodefailures/Starter.java index 9e4e17fe0..f08766881 100644 --- a/core/src/main/java/io/temporal/samples/encodefailures/Starter.java +++ b/core/src/main/java/io/temporal/samples/encodefailures/Starter.java @@ -8,10 +8,12 @@ import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.CodecDataConverter; import io.temporal.common.converter.DefaultDataConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkflowImplementationOptions; +import java.io.IOException; import java.util.Collections; public class Starter { @@ -19,7 +21,16 @@ public class Starter { private static final String WORKFLOW_ID = "CustomerValidationWorkflow"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // CodecDataConverter defines our data converter and codec // sets encodeFailureAttributes to true diff --git a/core/src/main/java/io/temporal/samples/encryptedpayloads/EncryptedPayloadsActivity.java b/core/src/main/java/io/temporal/samples/encryptedpayloads/EncryptedPayloadsActivity.java index 00636fb29..83f10d95c 100644 --- a/core/src/main/java/io/temporal/samples/encryptedpayloads/EncryptedPayloadsActivity.java +++ b/core/src/main/java/io/temporal/samples/encryptedpayloads/EncryptedPayloadsActivity.java @@ -8,12 +8,14 @@ import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.CodecDataConverter; import io.temporal.common.converter.DefaultDataConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.util.Collections; @@ -68,7 +70,16 @@ public String composeGreeting(String greeting, String name) { public static void main(String[] args) { // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows WorkflowClient client = WorkflowClient.newInstance( diff --git a/core/src/main/java/io/temporal/samples/excludefrominterceptor/RunMyWorkflows.java b/core/src/main/java/io/temporal/samples/excludefrominterceptor/RunMyWorkflows.java index b4bd1e825..4efe7d1f6 100644 --- a/core/src/main/java/io/temporal/samples/excludefrominterceptor/RunMyWorkflows.java +++ b/core/src/main/java/io/temporal/samples/excludefrominterceptor/RunMyWorkflows.java @@ -3,6 +3,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.excludefrominterceptor.activities.ForInterceptorActivitiesImpl; import io.temporal.samples.excludefrominterceptor.activities.MyActivitiesImpl; import io.temporal.samples.excludefrominterceptor.interceptor.MyWorkerInterceptor; @@ -11,13 +12,23 @@ import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerFactoryOptions; +import java.io.IOException; import java.util.Arrays; import java.util.concurrent.CompletableFuture; public class RunMyWorkflows { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactoryOptions wfo = WorkerFactoryOptions.newBuilder() diff --git a/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java b/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java index f2c1ee95a..5020bf519 100644 --- a/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java +++ b/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingStarter.java @@ -4,17 +4,28 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import java.net.URL; /** Starts a file processing sample workflow. */ public class FileProcessingStarter { public static void main(String[] args) throws Exception { - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); FileProcessingWorkflow workflow = client.newWorkflowStub( FileProcessingWorkflow.class, diff --git a/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorker.java b/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorker.java index b154a2c23..711ca7343 100644 --- a/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorker.java +++ b/core/src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.fileprocessing; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.lang.management.ManagementFactory; /** @@ -21,10 +23,19 @@ public static void main(String[] args) { String hostSpecifiTaskQueue = ManagementFactory.getRuntimeMXBean().getName(); - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/getresultsasync/Worker.java b/core/src/main/java/io/temporal/samples/getresultsasync/Worker.java index d9bb276be..4a91026f8 100644 --- a/core/src/main/java/io/temporal/samples/getresultsasync/Worker.java +++ b/core/src/main/java/io/temporal/samples/getresultsasync/Worker.java @@ -1,13 +1,30 @@ package io.temporal.samples.getresultsasync; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class Worker { - public static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - public static final WorkflowClient client = WorkflowClient.newInstance(service); - public static final WorkerFactory factory = WorkerFactory.newInstance(client); + public static final WorkflowServiceStubs service; + public static final WorkflowClient client; + public static final WorkerFactory factory; + + static { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + service = WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + factory = WorkerFactory.newInstance(client); + } + public static final String TASK_QUEUE_NAME = "asyncstartqueue"; public static void main(String[] args) { diff --git a/core/src/main/java/io/temporal/samples/hello/HelloAccumulator.java b/core/src/main/java/io/temporal/samples/hello/HelloAccumulator.java index 38ea8f097..2f8d67457 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloAccumulator.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloAccumulator.java @@ -11,6 +11,7 @@ import io.temporal.client.WorkflowNotFoundException; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -18,6 +19,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.io.Serializable; import java.time.Duration; import java.util.ArrayDeque; @@ -293,14 +295,17 @@ public void exit() { */ public static void main(String[] args) throws Exception { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query - * Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); client.getWorkflowServiceStubs().healthCheck(); /* diff --git a/core/src/main/java/io/temporal/samples/hello/HelloActivity.java b/core/src/main/java/io/temporal/samples/hello/HelloActivity.java index 3c890d3ab..9b202e0c2 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloActivity.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloActivity.java @@ -5,12 +5,14 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,13 +107,22 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); /* * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloActivityExclusiveChoice.java b/core/src/main/java/io/temporal/samples/hello/HelloActivityExclusiveChoice.java index 1da873e2c..3f2309993 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloActivityExclusiveChoice.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloActivityExclusiveChoice.java @@ -4,12 +4,14 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -165,12 +167,21 @@ public static void main(String[] args) { * Define the workflow service. It is a gRPC stubs wrapper which talks to the docker instance of * our locally running Temporal service. */ - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); /* * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java b/core/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java index f7f01b3a3..4f78cfa2f 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloActivityRetry.java @@ -5,12 +5,14 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.common.RetryOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** Sample Temporal workflow that demonstrates workflow activity retries. */ @@ -140,13 +142,17 @@ public synchronized String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloAsync.java b/core/src/main/java/io/temporal/samples/hello/HelloAsync.java index 7b068f7bf..25e8c3c5f 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloAsync.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloAsync.java @@ -4,6 +4,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -12,6 +13,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** Sample Temporal Workflow Definition that demonstrates an asynchronous Activity Execution. */ @@ -110,13 +112,18 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java b/core/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java index 87f9cbee7..f52072738 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloAsyncActivityCompletion.java @@ -4,12 +4,14 @@ import io.temporal.client.ActivityCompletionClient; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -143,14 +145,18 @@ private void composeGreetingAsync(byte[] taskToken, String greeting, String name */ public static void main(String[] args) throws ExecutionException, InterruptedException { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow - * Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java b/core/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java index 4da2b6ee1..6b68d85cb 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloAsyncLambda.java @@ -4,6 +4,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -12,6 +13,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** Sample Temporal Workflow Definition that demonstrates an asynchronous Activity Executions. */ @@ -128,13 +130,18 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloAwait.java b/core/src/main/java/io/temporal/samples/hello/HelloAwait.java index 069f5bb65..588b9e3fc 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloAwait.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloAwait.java @@ -3,6 +3,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.ApplicationFailure; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; @@ -11,6 +12,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** @@ -80,13 +82,18 @@ public void waitForName(String name) { */ public static void main(String[] args) throws Exception { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Await, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloCancellationScope.java b/core/src/main/java/io/temporal/samples/hello/HelloCancellationScope.java index 59cc0c7c8..c98a6fac5 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloCancellationScope.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloCancellationScope.java @@ -8,6 +8,7 @@ import io.temporal.client.ActivityCompletionException; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.ActivityFailure; import io.temporal.failure.CanceledFailure; import io.temporal.serviceclient.WorkflowServiceStubs; @@ -20,6 +21,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -231,13 +233,18 @@ private void sleep(int seconds) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloCancellationScopeWithTimer.java b/core/src/main/java/io/temporal/samples/hello/HelloCancellationScopeWithTimer.java index 6efb24b0a..5961b6833 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloCancellationScopeWithTimer.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloCancellationScopeWithTimer.java @@ -4,12 +4,14 @@ import io.temporal.client.ActivityCompletionException; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.ActivityFailure; import io.temporal.failure.CanceledFailure; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.*; +import java.io.IOException; import java.time.Duration; import java.util.concurrent.TimeUnit; @@ -153,12 +155,21 @@ private void sleep(int seconds) { public static void main(String[] args) { // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); /* * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloChild.java b/core/src/main/java/io/temporal/samples/hello/HelloChild.java index f631f5cbe..4c4c37276 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloChild.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloChild.java @@ -2,6 +2,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -10,6 +11,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; /** * Sample Temporal Workflow Definition that demonstrates the execution of a Child Workflow. Child @@ -105,13 +107,18 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the worker factory. It is used to create workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloCron.java b/core/src/main/java/io/temporal/samples/hello/HelloCron.java index 1d46d1c33..dafbfe11e 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloCron.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloCron.java @@ -7,12 +7,14 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowExecutionAlreadyStarted; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** @@ -108,13 +110,18 @@ public void greet(String greeting) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloDelayedStart.java b/core/src/main/java/io/temporal/samples/hello/HelloDelayedStart.java index 13d3d9041..a407e64d6 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloDelayedStart.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloDelayedStart.java @@ -3,12 +3,14 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.common.WorkflowExecutionHistory; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** Sample Temporal Workflow Definition that shows how to use delayed start. */ @@ -50,13 +52,18 @@ public void start() { } public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloDetachedCancellationScope.java b/core/src/main/java/io/temporal/samples/hello/HelloDetachedCancellationScope.java index 8baaf2364..a40087894 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloDetachedCancellationScope.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloDetachedCancellationScope.java @@ -8,11 +8,13 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.ActivityFailure; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.*; +import java.io.IOException; import java.time.Duration; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -132,13 +134,22 @@ public String queryGreeting() { public static void main(String[] args) throws InterruptedException { // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); /* * Get a Workflow service client which can be used to start, Signal, and Query Workflow * Executions. */ - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloDynamic.java b/core/src/main/java/io/temporal/samples/hello/HelloDynamic.java index f770f4263..f779bdfc3 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloDynamic.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloDynamic.java @@ -7,6 +7,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.common.converter.EncodedValues; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -14,6 +15,7 @@ import io.temporal.workflow.DynamicSignalHandler; import io.temporal.workflow.DynamicWorkflow; import io.temporal.workflow.Workflow; +import java.io.IOException; import java.time.Duration; public class HelloDynamic { @@ -71,14 +73,18 @@ public Object execute(EncodedValues args) { */ public static void main(String[] arg) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow - * Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloEagerWorkflowStart.java b/core/src/main/java/io/temporal/samples/hello/HelloEagerWorkflowStart.java index feb0d45f1..4e1a3b533 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloEagerWorkflowStart.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloEagerWorkflowStart.java @@ -5,12 +5,14 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -110,13 +112,18 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloException.java b/core/src/main/java/io/temporal/samples/hello/HelloException.java index 8c1daaccb..6b0788043 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloException.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloException.java @@ -8,6 +8,7 @@ import io.temporal.client.WorkflowException; import io.temporal.client.WorkflowOptions; import io.temporal.common.RetryOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -153,13 +154,18 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloLocalActivity.java b/core/src/main/java/io/temporal/samples/hello/HelloLocalActivity.java index 9436eab6b..c82a76e06 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloLocalActivity.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloLocalActivity.java @@ -5,12 +5,14 @@ import io.temporal.activity.LocalActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** @@ -90,10 +92,19 @@ public String composeGreeting(String greeting, String name) { } public static void main(String[] args) { - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/hello/HelloParallelActivity.java b/core/src/main/java/io/temporal/samples/hello/HelloParallelActivity.java index ab3e7c789..21b716070 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloParallelActivity.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloParallelActivity.java @@ -4,10 +4,12 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.*; +import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; @@ -116,13 +118,18 @@ public List getGreetings(List names) { */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloPeriodic.java b/core/src/main/java/io/temporal/samples/hello/HelloPeriodic.java index 418244684..f26370f21 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloPeriodic.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloPeriodic.java @@ -7,6 +7,7 @@ import io.temporal.client.WorkflowExecutionAlreadyStarted; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -14,6 +15,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.util.Random; @@ -183,13 +185,18 @@ public void greet(String greeting) { "CatchAndPrintStackTrace") // in this simple example advanced error logging is not required public static void main(String[] args) throws InterruptedException { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloPolymorphicActivity.java b/core/src/main/java/io/temporal/samples/hello/HelloPolymorphicActivity.java index a6bb70f1f..71a2c3ffd 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloPolymorphicActivity.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloPolymorphicActivity.java @@ -4,12 +4,14 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** @@ -150,13 +152,18 @@ public String composeGreeting(String name) { */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloQuery.java b/core/src/main/java/io/temporal/samples/hello/HelloQuery.java index 012ae1b97..e89f83f07 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloQuery.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloQuery.java @@ -2,6 +2,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -9,6 +10,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** Sample Temporal Workflow Definition that demonstrates how to Query a Workflow. */ @@ -78,13 +80,18 @@ public String queryGreeting() { */ public static void main(String[] args) throws InterruptedException { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSaga.java b/core/src/main/java/io/temporal/samples/hello/HelloSaga.java index 5dfc0848b..4fb3bc6a1 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSaga.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSaga.java @@ -5,6 +5,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -14,6 +15,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; /** @@ -258,13 +260,18 @@ public void execute() { */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSchedules.java b/core/src/main/java/io/temporal/samples/hello/HelloSchedules.java index 7d3c5ef1a..698f4f83b 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSchedules.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSchedules.java @@ -9,12 +9,14 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.schedules.*; import io.temporal.common.converter.GlobalDataConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.time.Instant; import java.util.Collections; @@ -130,13 +132,18 @@ public void greet(String greeting) { */ public static void main(String[] args) throws InterruptedException { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java b/core/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java index e2b1c0f9c..7115ebaa5 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSearchAttributes.java @@ -12,12 +12,14 @@ import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.DataConverter; import io.temporal.common.converter.GlobalDataConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -113,13 +115,18 @@ public String composeGreeting(String greeting, String name) { */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSideEffect.java b/core/src/main/java/io/temporal/samples/hello/HelloSideEffect.java index e0c39bf91..f894dc343 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSideEffect.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSideEffect.java @@ -4,6 +4,7 @@ import io.temporal.activity.ActivityOptions; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -11,6 +12,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.security.SecureRandom; import java.time.Duration; import java.util.Random; @@ -159,14 +161,18 @@ public String sayGoodBye(String greeting) { */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow - * Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSignal.java b/core/src/main/java/io/temporal/samples/hello/HelloSignal.java index cd5a488ab..e2e50fc85 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSignal.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSignal.java @@ -2,6 +2,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; @@ -9,6 +10,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -94,13 +96,18 @@ public void exit() { */ public static void main(String[] args) throws Exception { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSignalWithStartAndWorkflowInit.java b/core/src/main/java/io/temporal/samples/hello/HelloSignalWithStartAndWorkflowInit.java index 096516b10..f579388ae 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSignalWithStartAndWorkflowInit.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSignalWithStartAndWorkflowInit.java @@ -6,11 +6,13 @@ import io.temporal.client.WorkflowFailedException; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkflowImplementationOptions; import io.temporal.workflow.*; +import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -147,8 +149,17 @@ public void setAge(int age) { } public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/hello/HelloSignalWithTimer.java b/core/src/main/java/io/temporal/samples/hello/HelloSignalWithTimer.java index 26c22b2a2..ea2d29d2a 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloSignalWithTimer.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloSignalWithTimer.java @@ -5,11 +5,13 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.CanceledFailure; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.*; +import java.io.IOException; import java.time.Duration; import org.slf4j.Logger; @@ -116,8 +118,17 @@ public void processValue(String value) { } public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/hello/HelloTypedSearchAttributes.java b/core/src/main/java/io/temporal/samples/hello/HelloTypedSearchAttributes.java index f0dfb76c4..8629dfd62 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloTypedSearchAttributes.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloTypedSearchAttributes.java @@ -6,12 +6,14 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.common.SearchAttributeKey; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.time.OffsetDateTime; import java.time.ZoneOffset; @@ -149,13 +151,18 @@ public String composeGreeting(String greeting, List salutations, String */ public static void main(String[] args) { - // Define the workflow service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Define the workflow service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java b/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java index 329569738..6df8a8694 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloUpdate.java @@ -6,6 +6,7 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.client.WorkflowUpdateException; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.ApplicationFailure; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; @@ -16,6 +17,7 @@ import io.temporal.workflow.Workflow; import io.temporal.workflow.WorkflowInterface; import io.temporal.workflow.WorkflowMethod; +import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -157,13 +159,18 @@ public void exit() { */ public static void main(String[] args) throws Exception { - // Get a Workflow service stub. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } - /* - * Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions. - */ - WorkflowClient client = WorkflowClient.newInstance(service); + // Get a Workflow service stub. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); /* * Define the workflow factory. It is used to create workflow workers for a specific task queue. diff --git a/core/src/main/java/io/temporal/samples/hello/HelloWorkflowTimer.java b/core/src/main/java/io/temporal/samples/hello/HelloWorkflowTimer.java index 94570db98..ec6f8a5ba 100644 --- a/core/src/main/java/io/temporal/samples/hello/HelloWorkflowTimer.java +++ b/core/src/main/java/io/temporal/samples/hello/HelloWorkflowTimer.java @@ -5,6 +5,7 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.failure.ActivityFailure; import io.temporal.failure.CanceledFailure; import io.temporal.failure.ChildWorkflowFailure; @@ -12,6 +13,7 @@ import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.workflow.*; +import java.io.IOException; import java.time.Duration; /** Sample shows how to use workflow timer instead of WorkflowOptions->Run/ExecutionTimeout */ @@ -190,10 +192,19 @@ public String executeChild(String input) { } public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + // Create service stubs - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - // Crete workflow client - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + // Create workflow client + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Create worker factory WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/keymanagementencryption/awsencryptionsdk/EncryptedPayloads.java b/core/src/main/java/io/temporal/samples/keymanagementencryption/awsencryptionsdk/EncryptedPayloads.java index f36f3176c..03392674c 100644 --- a/core/src/main/java/io/temporal/samples/keymanagementencryption/awsencryptionsdk/EncryptedPayloads.java +++ b/core/src/main/java/io/temporal/samples/keymanagementencryption/awsencryptionsdk/EncryptedPayloads.java @@ -5,10 +5,12 @@ import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.CodecDataConverter; import io.temporal.common.converter.DefaultDataConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.hello.HelloActivity; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.util.Collections; import software.amazon.cryptography.materialproviders.IKeyring; import software.amazon.cryptography.materialproviders.MaterialProviders; @@ -36,7 +38,16 @@ public static void main(String[] args) { CreateAwsKmsMultiKeyringInput.builder().generator(generatorKey).build(); final IKeyring kmsKeyring = materialProviders.CreateAwsKmsMultiKeyring(keyringInput); // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows WorkflowClient client = WorkflowClient.newInstance( diff --git a/core/src/main/java/io/temporal/samples/listworkflows/Starter.java b/core/src/main/java/io/temporal/samples/listworkflows/Starter.java index 1d9ef916c..ad7f62369 100644 --- a/core/src/main/java/io/temporal/samples/listworkflows/Starter.java +++ b/core/src/main/java/io/temporal/samples/listworkflows/Starter.java @@ -6,9 +6,11 @@ import io.temporal.api.workflowservice.v1.ListWorkflowExecutionsResponse; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -17,11 +19,23 @@ public class Starter { public static final String TASK_QUEUE = "customerTaskQueue"; - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); - private static final WorkerFactory factory = WorkerFactory.newInstance(client); + private static WorkflowServiceStubs service; + private static WorkflowClient client; + private static WorkerFactory factory; public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + service = WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + factory = WorkerFactory.newInstance(client); + // create some fake customers List customers = new ArrayList<>(); customers.add(new Customer("c1", "John", "john@john.com", "new")); diff --git a/core/src/main/java/io/temporal/samples/metrics/MetricsStarter.java b/core/src/main/java/io/temporal/samples/metrics/MetricsStarter.java index a213c3f81..ffe222899 100644 --- a/core/src/main/java/io/temporal/samples/metrics/MetricsStarter.java +++ b/core/src/main/java/io/temporal/samples/metrics/MetricsStarter.java @@ -9,9 +9,11 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.common.reporter.MicrometerClientStatsReporter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.metrics.workflow.MetricsWorkflow; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.serviceclient.WorkflowServiceStubsOptions; +import java.io.IOException; public class MetricsStarter { public static void main(String[] args) { @@ -35,12 +37,22 @@ public static void main(String[] args) { // scrape endpoint. Runtime.getRuntime().addShutdownHook(new Thread(() -> scrapeEndpoint.stop(1))); - // Add metrics scope to workflow service stub options + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // Add metrics scope to workflow service stub options, preserving env config WorkflowServiceStubsOptions stubOptions = - WorkflowServiceStubsOptions.newBuilder().setMetricsScope(scope).build(); + WorkflowServiceStubsOptions.newBuilder(profile.toWorkflowServiceStubsOptions()) + .setMetricsScope(scope) + .build(); WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs(stubOptions); - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkflowOptions workflowOptions = WorkflowOptions.newBuilder() diff --git a/core/src/main/java/io/temporal/samples/metrics/MetricsWorker.java b/core/src/main/java/io/temporal/samples/metrics/MetricsWorker.java index 4b5f3173f..9f95107cf 100644 --- a/core/src/main/java/io/temporal/samples/metrics/MetricsWorker.java +++ b/core/src/main/java/io/temporal/samples/metrics/MetricsWorker.java @@ -8,12 +8,14 @@ import io.micrometer.prometheus.PrometheusMeterRegistry; import io.temporal.client.WorkflowClient; import io.temporal.common.reporter.MicrometerClientStatsReporter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.metrics.activities.MetricsActivitiesImpl; import io.temporal.samples.metrics.workflow.MetricsWorkflowImpl; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.serviceclient.WorkflowServiceStubsOptions; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class MetricsWorker { @@ -41,12 +43,22 @@ public static void main(String[] args) { // Stopping the worker will stop the http server that exposes the // scrape endpoint. Runtime.getRuntime().addShutdownHook(new Thread(() -> scrapeEndpoint.stop(1))); - // Add metrics scope to workflow service stub options + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // Add metrics scope to workflow service stub options, preserving env config WorkflowServiceStubsOptions stubOptions = - WorkflowServiceStubsOptions.newBuilder().setMetricsScope(scope).build(); + WorkflowServiceStubsOptions.newBuilder(profile.toWorkflowServiceStubsOptions()) + .setMetricsScope(scope) + .build(); WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs(stubOptions); - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(DEFAULT_TASK_QUEUE_NAME); diff --git a/core/src/main/java/io/temporal/samples/moneybatch/AccountActivityWorker.java b/core/src/main/java/io/temporal/samples/moneybatch/AccountActivityWorker.java index ecee1ad05..d67014f80 100644 --- a/core/src/main/java/io/temporal/samples/moneybatch/AccountActivityWorker.java +++ b/core/src/main/java/io/temporal/samples/moneybatch/AccountActivityWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.moneybatch; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class AccountActivityWorker { @@ -11,8 +13,17 @@ public class AccountActivityWorker { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/moneybatch/AccountTransferWorker.java b/core/src/main/java/io/temporal/samples/moneybatch/AccountTransferWorker.java index d9c5ef7cd..99529467d 100644 --- a/core/src/main/java/io/temporal/samples/moneybatch/AccountTransferWorker.java +++ b/core/src/main/java/io/temporal/samples/moneybatch/AccountTransferWorker.java @@ -1,16 +1,27 @@ package io.temporal.samples.moneybatch; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class AccountTransferWorker { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker(AccountActivityWorker.TASK_QUEUE); diff --git a/core/src/main/java/io/temporal/samples/moneybatch/TransferRequester.java b/core/src/main/java/io/temporal/samples/moneybatch/TransferRequester.java index 8a63c02e3..31b2f507f 100644 --- a/core/src/main/java/io/temporal/samples/moneybatch/TransferRequester.java +++ b/core/src/main/java/io/temporal/samples/moneybatch/TransferRequester.java @@ -3,7 +3,9 @@ import io.temporal.client.BatchRequest; import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import java.util.Random; import java.util.UUID; @@ -16,8 +18,18 @@ public class TransferRequester { public static void main(String[] args) { String reference = UUID.randomUUID().toString(); int amountCents = (new Random().nextInt(5) + 1) * 25; - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient workflowClient = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient workflowClient = + WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); String from = "account1"; String to = "account2"; diff --git a/core/src/main/java/io/temporal/samples/moneytransfer/AccountActivityWorker.java b/core/src/main/java/io/temporal/samples/moneytransfer/AccountActivityWorker.java index a2bbee418..a3113fe5d 100644 --- a/core/src/main/java/io/temporal/samples/moneytransfer/AccountActivityWorker.java +++ b/core/src/main/java/io/temporal/samples/moneytransfer/AccountActivityWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.moneytransfer; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class AccountActivityWorker { @@ -11,10 +13,19 @@ public class AccountActivityWorker { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/moneytransfer/AccountTransferWorker.java b/core/src/main/java/io/temporal/samples/moneytransfer/AccountTransferWorker.java index 6d237d8fa..97ab56ff9 100644 --- a/core/src/main/java/io/temporal/samples/moneytransfer/AccountTransferWorker.java +++ b/core/src/main/java/io/temporal/samples/moneytransfer/AccountTransferWorker.java @@ -3,19 +3,30 @@ import static io.temporal.samples.moneytransfer.AccountActivityWorker.TASK_QUEUE; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class AccountTransferWorker { @SuppressWarnings("CatchAndPrintStackTrace") public static void main(String[] args) { // Get worker to poll the common task queue. - // gRPC stubs wrapper that talks to the local docker instance of temporal service. - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + // gRPC stubs wrapper that talks to the temporal service. + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient client = WorkflowClient.newInstance(service); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // worker factory that can be used to create workers for specific task queues WorkerFactory factory = WorkerFactory.newInstance(client); diff --git a/core/src/main/java/io/temporal/samples/moneytransfer/TransferRequester.java b/core/src/main/java/io/temporal/samples/moneytransfer/TransferRequester.java index b333b9341..6fda6598e 100644 --- a/core/src/main/java/io/temporal/samples/moneytransfer/TransferRequester.java +++ b/core/src/main/java/io/temporal/samples/moneytransfer/TransferRequester.java @@ -4,7 +4,9 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import java.util.Random; import java.util.UUID; @@ -21,9 +23,19 @@ public static void main(String[] args) { reference = args[0]; amountCents = Integer.parseInt(args[1]); } - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // client that can be used to start and signal workflows - WorkflowClient workflowClient = WorkflowClient.newInstance(service); + WorkflowClient workflowClient = + WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // now we can start running instances of the saga - its state will be persisted WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build(); diff --git a/core/src/main/java/io/temporal/samples/packetdelivery/Starter.java b/core/src/main/java/io/temporal/samples/packetdelivery/Starter.java index e1d97e621..f6ca6000d 100644 --- a/core/src/main/java/io/temporal/samples/packetdelivery/Starter.java +++ b/core/src/main/java/io/temporal/samples/packetdelivery/Starter.java @@ -4,16 +4,27 @@ import io.temporal.client.WorkflowNotFoundException; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.util.Collections; import java.util.List; public class Starter { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); Worker worker = factory.newWorker("packet-delivery-taskqueue"); diff --git a/core/src/main/java/io/temporal/samples/payloadconverter/cloudevents/Starter.java b/core/src/main/java/io/temporal/samples/payloadconverter/cloudevents/Starter.java index 2e17f4cb0..e9e368a3b 100644 --- a/core/src/main/java/io/temporal/samples/payloadconverter/cloudevents/Starter.java +++ b/core/src/main/java/io/temporal/samples/payloadconverter/cloudevents/Starter.java @@ -7,9 +7,11 @@ import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.DefaultDataConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.net.URI; import java.nio.charset.Charset; import java.util.ArrayList; @@ -20,7 +22,16 @@ public class Starter { private static final String TASK_QUEUE = "CloudEventsConverterQueue"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // Add CloudEventsPayloadConverter // It has the same encoding type as JacksonJsonPayloadConverter diff --git a/core/src/main/java/io/temporal/samples/payloadconverter/crypto/Starter.java b/core/src/main/java/io/temporal/samples/payloadconverter/crypto/Starter.java index dffdb41a1..4a5e121ef 100644 --- a/core/src/main/java/io/temporal/samples/payloadconverter/crypto/Starter.java +++ b/core/src/main/java/io/temporal/samples/payloadconverter/crypto/Starter.java @@ -9,16 +9,27 @@ import io.temporal.client.WorkflowOptions; import io.temporal.common.converter.DefaultDataConverter; import io.temporal.common.converter.JacksonJsonPayloadConverter; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class Starter { private static final String TASK_QUEUE = "CryptoConverterQueue"; private static final String encryptDecryptPassword = "encryptDecryptPassword"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); // Set crypto data converter in client options WorkflowClient client = diff --git a/core/src/main/java/io/temporal/samples/peractivityoptions/Starter.java b/core/src/main/java/io/temporal/samples/peractivityoptions/Starter.java index 7db5df86d..58062c176 100644 --- a/core/src/main/java/io/temporal/samples/peractivityoptions/Starter.java +++ b/core/src/main/java/io/temporal/samples/peractivityoptions/Starter.java @@ -5,20 +5,32 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.common.RetryOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkflowImplementationOptions; +import java.io.IOException; import java.time.Duration; public class Starter { public static final String TASK_QUEUE = "perActivityTaskQueue"; - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); - private static final WorkerFactory factory = WorkerFactory.newInstance(client); public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + WorkerFactory factory = WorkerFactory.newInstance(client); + // Create Worker Worker worker = factory.newWorker(TASK_QUEUE); // Register workflow impl and set the per-activity options diff --git a/core/src/main/java/io/temporal/samples/polling/frequent/FrequentPollingStarter.java b/core/src/main/java/io/temporal/samples/polling/frequent/FrequentPollingStarter.java index 4a52cab2f..ed8fa477f 100644 --- a/core/src/main/java/io/temporal/samples/polling/frequent/FrequentPollingStarter.java +++ b/core/src/main/java/io/temporal/samples/polling/frequent/FrequentPollingStarter.java @@ -2,15 +2,31 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.polling.PollingWorkflow; import io.temporal.samples.polling.TestService; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class FrequentPollingStarter { - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); + private static WorkflowServiceStubs service; + private static WorkflowClient client; + + static { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + service = WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + } + private static final String taskQueue = "pollingSampleQueue"; private static final String workflowId = "FrequentPollingSampleWorkflow"; diff --git a/core/src/main/java/io/temporal/samples/polling/infrequent/InfrequentPollingStarter.java b/core/src/main/java/io/temporal/samples/polling/infrequent/InfrequentPollingStarter.java index 2a6cb7a85..f778ce287 100644 --- a/core/src/main/java/io/temporal/samples/polling/infrequent/InfrequentPollingStarter.java +++ b/core/src/main/java/io/temporal/samples/polling/infrequent/InfrequentPollingStarter.java @@ -2,15 +2,31 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.polling.PollingWorkflow; import io.temporal.samples.polling.TestService; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class InfrequentPollingStarter { - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); + private static WorkflowServiceStubs service; + private static WorkflowClient client; + + static { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + service = WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + } + private static final String taskQueue = "pollingSampleQueue"; private static final String workflowId = "InfrequentPollingSampleWorkflow"; diff --git a/core/src/main/java/io/temporal/samples/polling/infrequentwithretryafter/InfrequentPollingWithRetryAfterStarter.java b/core/src/main/java/io/temporal/samples/polling/infrequentwithretryafter/InfrequentPollingWithRetryAfterStarter.java index 81853ec71..93e3c9e6b 100644 --- a/core/src/main/java/io/temporal/samples/polling/infrequentwithretryafter/InfrequentPollingWithRetryAfterStarter.java +++ b/core/src/main/java/io/temporal/samples/polling/infrequentwithretryafter/InfrequentPollingWithRetryAfterStarter.java @@ -2,15 +2,31 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.polling.PollingWorkflow; import io.temporal.samples.polling.TestService; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class InfrequentPollingWithRetryAfterStarter { - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); + private static WorkflowServiceStubs service; + private static WorkflowClient client; + + static { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + service = WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + } + private static final String taskQueue = "pollingSampleQueue"; private static final String workflowId = "InfrequentPollingWithRetryAfterWorkflow"; diff --git a/core/src/main/java/io/temporal/samples/polling/periodicsequence/PeriodicPollingStarter.java b/core/src/main/java/io/temporal/samples/polling/periodicsequence/PeriodicPollingStarter.java index f2ef3eb1f..34c3e8a5a 100644 --- a/core/src/main/java/io/temporal/samples/polling/periodicsequence/PeriodicPollingStarter.java +++ b/core/src/main/java/io/temporal/samples/polling/periodicsequence/PeriodicPollingStarter.java @@ -2,15 +2,31 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.samples.polling.PollingWorkflow; import io.temporal.samples.polling.TestService; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class PeriodicPollingStarter { - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); + private static WorkflowServiceStubs service; + private static WorkflowClient client; + + static { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + service = WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + } + private static final String taskQueue = "pollingSampleQueue"; private static final String workflowId = "PeriodicPollingSampleWorkflow"; diff --git a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/FailureRequester.java b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/FailureRequester.java index cd3e546da..c948ba02e 100644 --- a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/FailureRequester.java +++ b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/FailureRequester.java @@ -3,7 +3,9 @@ import static io.temporal.samples.retryonsignalinterceptor.MyWorkflowWorker.WORKFLOW_ID; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; /** * Send signal requesting that an exception thrown from the activity is propagated to the workflow. @@ -11,8 +13,17 @@ public class FailureRequester { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Note that we use the listener interface that the interceptor registered dynamically, not the // workflow interface. diff --git a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/MyWorkflowWorker.java b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/MyWorkflowWorker.java index 42fd358bd..55b9ebe17 100644 --- a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/MyWorkflowWorker.java +++ b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/MyWorkflowWorker.java @@ -2,10 +2,12 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerFactoryOptions; +import java.io.IOException; public class MyWorkflowWorker { @@ -14,8 +16,17 @@ public class MyWorkflowWorker { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Register interceptor with the factory. WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder() diff --git a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/QueryRequester.java b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/QueryRequester.java index c54f8d0ab..08a7afcbb 100644 --- a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/QueryRequester.java +++ b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/QueryRequester.java @@ -3,13 +3,24 @@ import static io.temporal.samples.retryonsignalinterceptor.MyWorkflowWorker.WORKFLOW_ID; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class QueryRequester { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Note that we use the listener interface that the interceptor registered dynamically, not the // workflow interface. diff --git a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryRequester.java b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryRequester.java index b0cf85ef8..a5469d80f 100644 --- a/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryRequester.java +++ b/core/src/main/java/io/temporal/samples/retryonsignalinterceptor/RetryRequester.java @@ -3,13 +3,24 @@ import static io.temporal.samples.retryonsignalinterceptor.MyWorkflowWorker.WORKFLOW_ID; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class RetryRequester { public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Note that we use the listener interface that the interceptor registered dynamically, not the // workflow interface. diff --git a/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowStarter.java b/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowStarter.java index 1913a3e40..71ae380cb 100644 --- a/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowStarter.java +++ b/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowStarter.java @@ -7,7 +7,9 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.client.WorkflowUpdateStage; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -29,8 +31,17 @@ public static void main(String[] args) { + " "); System.exit(1); } - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); boolean shouldTestContinueAsNew = args.length > 0 ? Boolean.parseBoolean(args[0]) : false; ClusterManagerWorkflow cluster = client.newWorkflowStub( diff --git a/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorker.java b/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorker.java index 2f063a663..a4fa8d69f 100644 --- a/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorker.java +++ b/core/src/main/java/io/temporal/samples/safemessagepassing/ClusterManagerWorkflowWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.safemessagepassing; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,8 +15,17 @@ public class ClusterManagerWorkflowWorker { static final String CLUSTER_MANAGER_WORKFLOW_ID = "ClusterManagerWorkflow"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); final Worker worker = factory.newWorker(TASK_QUEUE); worker.registerWorkflowImplementationTypes(ClusterManagerWorkflowImpl.class); diff --git a/core/src/main/java/io/temporal/samples/sleepfordays/Starter.java b/core/src/main/java/io/temporal/samples/sleepfordays/Starter.java index cf5e9a9a7..91ed89325 100644 --- a/core/src/main/java/io/temporal/samples/sleepfordays/Starter.java +++ b/core/src/main/java/io/temporal/samples/sleepfordays/Starter.java @@ -3,15 +3,30 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; +import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class Starter { public static final String TASK_QUEUE = "SleepForDaysTaskQueue"; public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + // Start a workflow execution. SleepForDaysWorkflow workflow = - Worker.client.newWorkflowStub( + client.newWorkflowStub( SleepForDaysWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build()); diff --git a/core/src/main/java/io/temporal/samples/sleepfordays/Worker.java b/core/src/main/java/io/temporal/samples/sleepfordays/Worker.java index 301326c27..b5abac1cb 100644 --- a/core/src/main/java/io/temporal/samples/sleepfordays/Worker.java +++ b/core/src/main/java/io/temporal/samples/sleepfordays/Worker.java @@ -1,16 +1,28 @@ package io.temporal.samples.sleepfordays; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.WorkerFactory; +import java.io.IOException; public class Worker { public static final String TASK_QUEUE = "SleepForDaysTaskQueue"; - public static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - public static final WorkflowClient client = WorkflowClient.newInstance(service); - public static final WorkerFactory factory = WorkerFactory.newInstance(client); public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + WorkerFactory factory = WorkerFactory.newInstance(client); + io.temporal.worker.Worker worker = factory.newWorker(TASK_QUEUE); worker.registerWorkflowImplementationTypes(SleepForDaysImpl.class); worker.registerActivitiesImplementations(new SendEmailActivityImpl()); diff --git a/core/src/main/java/io/temporal/samples/terminateworkflow/Starter.java b/core/src/main/java/io/temporal/samples/terminateworkflow/Starter.java index 20f0d171d..e36a407c7 100644 --- a/core/src/main/java/io/temporal/samples/terminateworkflow/Starter.java +++ b/core/src/main/java/io/temporal/samples/terminateworkflow/Starter.java @@ -7,21 +7,33 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import java.util.concurrent.TimeUnit; public class Starter { public static final String TASK_QUEUE = "terminateQueue"; - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); - private static final WorkerFactory factory = WorkerFactory.newInstance(client); public static void main(String[] args) { + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + WorkerFactory factory = WorkerFactory.newInstance(client); + // Create Worker - createWorker(); + createWorker(factory); // Create Workflow options WorkflowOptions workflowOptions = @@ -44,13 +56,13 @@ public static void main(String[] args) { untyped.terminate("Sample reason"); // Check workflow status, should be WORKFLOW_EXECUTION_STATUS_TERMINATED - System.out.println("Status: " + getStatusAsString(execution)); + System.out.println("Status: " + getStatusAsString(execution, client, service)); System.exit(0); } /** This method creates a Worker from the factory. */ - private static void createWorker() { + private static void createWorker(WorkerFactory factory) { Worker worker = factory.newWorker(TASK_QUEUE); worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class); @@ -78,7 +90,8 @@ private static void sleepSeconds(int seconds) { * @param execution workflow execution * @return Workflow status */ - private static String getStatusAsString(WorkflowExecution execution) { + private static String getStatusAsString( + WorkflowExecution execution, WorkflowClient client, WorkflowServiceStubs service) { DescribeWorkflowExecutionRequest describeWorkflowExecutionRequest = DescribeWorkflowExecutionRequest.newBuilder() .setNamespace(client.getOptions().getNamespace()) diff --git a/core/src/main/java/io/temporal/samples/tracing/Starter.java b/core/src/main/java/io/temporal/samples/tracing/Starter.java index ebb830c19..bb1eaaae3 100644 --- a/core/src/main/java/io/temporal/samples/tracing/Starter.java +++ b/core/src/main/java/io/temporal/samples/tracing/Starter.java @@ -4,12 +4,13 @@ import io.temporal.client.WorkflowClientOptions; import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.opentracing.OpenTracingClientInterceptor; import io.temporal.samples.tracing.workflow.TracingWorkflow; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; public class Starter { - public static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); public static final String TASK_QUEUE_NAME = "tracingTaskQueue"; public static void main(String[] args) { @@ -18,9 +19,20 @@ public static void main(String[] args) { type = args[0]; } - // Set the OpenTracing client interceptor + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + + // Set the OpenTracing client interceptor, preserving env config WorkflowClientOptions clientOptions = - WorkflowClientOptions.newBuilder() + profile.toWorkflowClientOptions().toBuilder() .setInterceptors(new OpenTracingClientInterceptor(JaegerUtils.getJaegerOptions(type))) .build(); WorkflowClient client = WorkflowClient.newInstance(service, clientOptions); diff --git a/core/src/main/java/io/temporal/samples/tracing/TracingWorker.java b/core/src/main/java/io/temporal/samples/tracing/TracingWorker.java index 221c3efef..b726bcaae 100644 --- a/core/src/main/java/io/temporal/samples/tracing/TracingWorker.java +++ b/core/src/main/java/io/temporal/samples/tracing/TracingWorker.java @@ -1,6 +1,7 @@ package io.temporal.samples.tracing; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.opentracing.OpenTracingWorkerInterceptor; import io.temporal.samples.tracing.workflow.TracingActivitiesImpl; import io.temporal.samples.tracing.workflow.TracingChildWorkflowImpl; @@ -9,10 +10,9 @@ import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerFactoryOptions; +import java.io.IOException; public class TracingWorker { - private static final WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - private static final WorkflowClient client = WorkflowClient.newInstance(service); public static final String TASK_QUEUE_NAME = "tracingTaskQueue"; public static void main(String[] args) { @@ -21,6 +21,18 @@ public static void main(String[] args) { type = args[0]; } + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); + // Set the OpenTracing client interceptor WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder() diff --git a/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowStarter.java b/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowStarter.java index d1f38e1ab..0cd1bb14c 100644 --- a/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowStarter.java +++ b/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowStarter.java @@ -8,7 +8,9 @@ import io.temporal.client.WorkflowClient; import io.temporal.client.WorkflowExecutionAlreadyStarted; import io.temporal.client.WorkflowOptions; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +19,17 @@ public class DynamicSleepWorkflowStarter { private static final Logger logger = LoggerFactory.getLogger(DynamicSleepWorkflowStarter.class); public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); DynamicSleepWorkflow workflow = client.newWorkflowStub( diff --git a/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowWorker.java b/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowWorker.java index d0a4e712b..a7db34126 100644 --- a/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowWorker.java +++ b/core/src/main/java/io/temporal/samples/updatabletimer/DynamicSleepWorkflowWorker.java @@ -1,9 +1,11 @@ package io.temporal.samples.updatabletimer; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerFactory; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +19,17 @@ public class DynamicSleepWorkflowWorker { static final String DYNAMIC_SLEEP_WORKFLOW_ID = "DynamicSleepWorkflow"; public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerFactory factory = WorkerFactory.newInstance(client); final Worker worker = factory.newWorker(TASK_QUEUE); worker.registerWorkflowImplementationTypes(DynamicSleepWorkflowImpl.class); diff --git a/core/src/main/java/io/temporal/samples/updatabletimer/WakeUpTimeUpdater.java b/core/src/main/java/io/temporal/samples/updatabletimer/WakeUpTimeUpdater.java index 0a13ff071..3a8f935a2 100644 --- a/core/src/main/java/io/temporal/samples/updatabletimer/WakeUpTimeUpdater.java +++ b/core/src/main/java/io/temporal/samples/updatabletimer/WakeUpTimeUpdater.java @@ -3,7 +3,9 @@ import static io.temporal.samples.updatabletimer.DynamicSleepWorkflowWorker.DYNAMIC_SLEEP_WORKFLOW_ID; import io.temporal.client.WorkflowClient; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,8 +14,17 @@ public class WakeUpTimeUpdater { private static final Logger logger = LoggerFactory.getLogger(WakeUpTimeUpdater.class); public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Create a stub that points to an existing workflow with the given ID DynamicSleepWorkflow workflow = diff --git a/core/src/main/java/io/temporal/samples/workerversioning/Starter.java b/core/src/main/java/io/temporal/samples/workerversioning/Starter.java index a48902557..b743cf821 100644 --- a/core/src/main/java/io/temporal/samples/workerversioning/Starter.java +++ b/core/src/main/java/io/temporal/samples/workerversioning/Starter.java @@ -7,7 +7,9 @@ import io.temporal.client.WorkflowOptions; import io.temporal.client.WorkflowStub; import io.temporal.common.WorkerDeploymentVersion; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; +import java.io.IOException; import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,8 +21,17 @@ public class Starter { private static final Logger logger = LoggerFactory.getLogger(Starter.class); public static void main(String[] args) throws Exception { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); // Wait for v1 worker and set as current version logger.info( @@ -146,6 +157,7 @@ private static void waitForWorkerAndMakeCurrent( break; } } catch (Exception ignored) { + System.out.println(); } Thread.sleep(1000); } diff --git a/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1.java b/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1.java index 6d90b82fd..42ff216e0 100644 --- a/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1.java +++ b/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1.java @@ -2,11 +2,13 @@ import io.temporal.client.WorkflowClient; import io.temporal.common.WorkerDeploymentVersion; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerDeploymentOptions; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerOptions; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,8 +17,17 @@ public class WorkerV1 { private static final Logger logger = LoggerFactory.getLogger(WorkerV1.class); public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerDeploymentVersion version = new WorkerDeploymentVersion(Starter.DEPLOYMENT_NAME, "1.0"); WorkerDeploymentOptions deploymentOptions = diff --git a/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1_1.java b/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1_1.java index 5b1235460..76ec8e278 100644 --- a/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1_1.java +++ b/core/src/main/java/io/temporal/samples/workerversioning/WorkerV1_1.java @@ -2,11 +2,13 @@ import io.temporal.client.WorkflowClient; import io.temporal.common.WorkerDeploymentVersion; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerDeploymentOptions; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerOptions; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,8 +17,17 @@ public class WorkerV1_1 { private static final Logger logger = LoggerFactory.getLogger(WorkerV1_1.class); public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerDeploymentVersion version = new WorkerDeploymentVersion(Starter.DEPLOYMENT_NAME, "1.1"); WorkerDeploymentOptions deploymentOptions = diff --git a/core/src/main/java/io/temporal/samples/workerversioning/WorkerV2.java b/core/src/main/java/io/temporal/samples/workerversioning/WorkerV2.java index 57edd0ed3..2c436a2dd 100644 --- a/core/src/main/java/io/temporal/samples/workerversioning/WorkerV2.java +++ b/core/src/main/java/io/temporal/samples/workerversioning/WorkerV2.java @@ -2,11 +2,13 @@ import io.temporal.client.WorkflowClient; import io.temporal.common.WorkerDeploymentVersion; +import io.temporal.envconfig.ClientConfigProfile; import io.temporal.serviceclient.WorkflowServiceStubs; import io.temporal.worker.Worker; import io.temporal.worker.WorkerDeploymentOptions; import io.temporal.worker.WorkerFactory; import io.temporal.worker.WorkerOptions; +import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,8 +17,17 @@ public class WorkerV2 { private static final Logger logger = LoggerFactory.getLogger(WorkerV2.class); public static void main(String[] args) { - WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); - WorkflowClient client = WorkflowClient.newInstance(service); + // Load configuration from environment and files + ClientConfigProfile profile; + try { + profile = ClientConfigProfile.load(); + } catch (IOException e) { + throw new RuntimeException("Failed to load client configuration", e); + } + + WorkflowServiceStubs service = + WorkflowServiceStubs.newServiceStubs(profile.toWorkflowServiceStubsOptions()); + WorkflowClient client = WorkflowClient.newInstance(service, profile.toWorkflowClientOptions()); WorkerDeploymentVersion version = new WorkerDeploymentVersion(Starter.DEPLOYMENT_NAME, "2.0"); WorkerDeploymentOptions deploymentOptions = diff --git a/springboot/build.gradle b/springboot/build.gradle index 7120304e9..674333429 100644 --- a/springboot/build.gradle +++ b/springboot/build.gradle @@ -9,6 +9,9 @@ dependencies { // we set this as impl depends to use embedded kafka in samples not just tests implementation "org.springframework.kafka:spring-kafka-test" implementation "io.temporal:temporal-spring-boot-starter:$javaSDKVersion" + + // Environment configuration + implementation "io.temporal:temporal-envconfig" implementation "org.apache.camel.springboot:camel-spring-boot-starter:$camelVersion" implementation "org.apache.camel.springboot:camel-servlet-starter:$camelVersion" runtimeOnly "io.micrometer:micrometer-registry-prometheus"