Skip to content

Commit 9949f4b

Browse files
docs: add java to env config (#4062)
* docs: add env config to java * docs: add java samples to enc config docs * docs: edits after running java testing * docs: highlight lines * docs: fix highlight issues * docs: minor edit * docs: change default * Apply suggestions from code review Co-authored-by: Milecia McG <[email protected]> --------- Co-authored-by: Milecia McG <[email protected]>
1 parent 02028f6 commit 9949f4b

File tree

7 files changed

+575
-62
lines changed

7 files changed

+575
-62
lines changed

docs/best-practices/worker.mdx

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ production-ready Worker image:
4141

4242
{/* SNIPSTART oms-dockerfile-worker */}
4343
[Dockerfile](https://github.com/temporalio/reference-app-orders-go/blob/main/Dockerfile)
44-
4544
```Dockerfile
4645
FROM golang:1.23.8 AS oms-builder
4746

@@ -61,7 +60,6 @@ RUN --mount=type=cache,target=/go/pkg/mod \
6160

6261
FROM busybox AS oms-worker
6362
```
64-
6563
{/* SNIPEND oms-dockerfile-worker */}
6664

6765
This Dockerfile uses a multi-stage build pattern with two stages:
@@ -84,27 +82,25 @@ uses environment variables to configure the Worker:
8482

8583
{/* SNIPSTART oms-billing-worker-deployment {"selectedLines": ["20-35"]} */}
8684
[deployments/k8s/billing-worker-deployment.yaml](https://github.com/temporalio/reference-app-orders-go/blob/main/deployments/k8s/billing-worker-deployment.yaml)
87-
8885
```yaml
8986
# ...
90-
spec:
91-
containers:
92-
- args:
93-
- -k
94-
- supersecretkey
95-
- -s
96-
- billing
97-
env:
98-
- name: FRAUD_API_URL
99-
value: http://billing-api:8084
100-
- name: TEMPORAL_ADDRESS
101-
value: temporal-frontend.temporal:7233
102-
image: ghcr.io/temporalio/reference-app-orders-go-worker:latest
103-
name: billing-worker
104-
imagePullPolicy: Always
105-
enableServiceLinks: false
87+
spec:
88+
containers:
89+
- args:
90+
- -k
91+
- supersecretkey
92+
- -s
93+
- billing
94+
env:
95+
- name: FRAUD_API_URL
96+
value: http://billing-api:8084
97+
- name: TEMPORAL_ADDRESS
98+
value: temporal-frontend.temporal:7233
99+
image: ghcr.io/temporalio/reference-app-orders-go-worker:latest
100+
name: billing-worker
101+
imagePullPolicy: Always
102+
enableServiceLinks: false
106103
```
107-
108104
{/* SNIPEND */}
109105
110106
### Separate Task Queues logically
@@ -132,7 +128,6 @@ Worker reference to avoid this issue.
132128

133129
{/* SNIPSTART oms-billing-worker-go {"selectedLines": ["12-23"]} */}
134130
[app/billing/worker.go](https://github.com/temporalio/reference-app-orders-go/blob/main/app/billing/worker.go)
135-
136131
```go
137132
// ...
138133
// RunWorker runs a Workflow and Activity worker for the Billing system.
@@ -148,7 +143,6 @@ func RunWorker(ctx context.Context, config config.AppConfig, client client.Clien
148143
return w.Run(temporalutil.WorkerInterruptFromContext(ctx))
149144
}
150145
```
151-
152146
{/* SNIPEND */}
153147

154148
### Use Worker Versioning to safely deploy new Workflow code

docs/develop/environment-configuration.mdx

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,66 @@ main().catch((err) => {
381381
{/* SNIPEND */}
382382

383383
</SdkTabs.TypeScript>
384+
385+
<SdkTabs.Java>
386+
387+
To load the `default` profile along with any environment variables in Java, use the `ClientConfigProfile.load` method from the `envconfig` package. This method will load the `default` profile from the default location and any environment variables. Environment variables take precedence over the configuration file settings.
388+
389+
Then use `profile.toWorkflowServiceStubsOptions` and `profile.toWorkflowClientOptions` to convert the profile to `WorkflowServiceStubsOptions` and `WorkflowClientOptions` respectively. Then use `WorkflowClient.newInstance` to create a Temporal Client.
390+
391+
```java
392+
import io.temporal.client.WorkflowClient;
393+
import io.temporal.client.WorkflowClientOptions;
394+
import io.temporal.envconfig.ClientConfigProfile;
395+
import io.temporal.envconfig.LoadClientConfigProfileOptions;
396+
import io.temporal.serviceclient.WorkflowServiceStubs;
397+
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
398+
import java.nio.file.Paths;
399+
import org.slf4j.Logger;
400+
import org.slf4j.LoggerFactory;
401+
402+
public class LoadFromFile {
403+
404+
private static final Logger logger = LoggerFactory.getLogger(LoadFromFile.class);
405+
406+
public static void main(String[] args) {
407+
try {
408+
409+
ClientConfigProfile profile = ClientConfigProfile.load(LoadClientConfigProfileOptions.newBuilder().build());
410+
411+
WorkflowServiceStubsOptions serviceStubsOptions = profile.toWorkflowServiceStubsOptions();
412+
WorkflowClientOptions clientOptions = profile.toWorkflowClientOptions();
413+
414+
try {
415+
// Create the workflow client using the loaded configuration
416+
WorkflowClient client =
417+
WorkflowClient.newInstance(
418+
WorkflowServiceStubs.newServiceStubs(serviceStubsOptions), clientOptions);
419+
420+
// Test the connection by getting system info
421+
var systemInfo =
422+
client
423+
.getWorkflowServiceStubs()
424+
.blockingStub()
425+
.getSystemInfo(
426+
io.temporal.api.workflowservice.v1.GetSystemInfoRequest.getDefaultInstance());
427+
428+
logger.info("✅ Client connected successfully!");
429+
logger.info(" Server version: {}", systemInfo.getServerVersion());
430+
431+
} catch (Exception e) {
432+
logger.error("❌ Failed to connect: {}", e.getMessage());
433+
}
434+
435+
} catch (Exception e) {
436+
logger.error("Failed to load configuration: {}", e.getMessage(), e);
437+
System.exit(1);
438+
}
439+
}
440+
}
441+
```
442+
443+
</SdkTabs.Java>
384444
</SdkTabs>
385445

386446
## Load configuration from a custom path
@@ -674,5 +734,70 @@ main().catch((err) => {
674734

675735
</SdkTabs.TypeScript>
676736

677-
</SdkTabs>
737+
<SdkTabs.Java>
738+
739+
To load a profile configuration file from a custom path in Java, use the `ClientConfigProfile.load` method from the `envconfig` package with the `ConfigFilePath` parameter. This method will load the profile from the custom path and any environment variables. Environment variables take precedence over the configuration file settings.
740+
741+
```java {21-25}
742+
import io.temporal.client.WorkflowClient;
743+
import io.temporal.client.WorkflowClientOptions;
744+
import io.temporal.envconfig.ClientConfigProfile;
745+
import io.temporal.envconfig.LoadClientConfigProfileOptions;
746+
import io.temporal.serviceclient.WorkflowServiceStubs;
747+
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
748+
import java.nio.file.Paths;
749+
import org.slf4j.Logger;
750+
import org.slf4j.LoggerFactory;
751+
752+
public class LoadFromFile {
753+
754+
private static final Logger logger = LoggerFactory.getLogger(LoadFromFile.class);
755+
756+
public static void main(String[] args) {
757+
try {
758+
759+
String configFilePath =
760+
Paths.get(LoadFromFile.class.getResource("/config.toml").toURI()).toString();
761+
762+
ClientConfigProfile profile =
763+
ClientConfigProfile.load(
764+
LoadClientConfigProfileOptions.newBuilder()
765+
.setConfigFilePath(configFilePath)
766+
.build());
767+
768+
WorkflowServiceStubsOptions serviceStubsOptions = profile.toWorkflowServiceStubsOptions();
769+
WorkflowClientOptions clientOptions = profile.toWorkflowClientOptions();
770+
771+
try {
772+
// Create the workflow client using the loaded configuration
773+
WorkflowClient client =
774+
WorkflowClient.newInstance(
775+
WorkflowServiceStubs.newServiceStubs(serviceStubsOptions), clientOptions);
776+
777+
// Test the connection by getting system info
778+
var systemInfo =
779+
client
780+
.getWorkflowServiceStubs()
781+
.blockingStub()
782+
.getSystemInfo(
783+
io.temporal.api.workflowservice.v1.GetSystemInfoRequest.getDefaultInstance());
784+
785+
logger.info("✅ Client connected successfully!");
786+
logger.info(" Server version: {}", systemInfo.getServerVersion());
787+
788+
} catch (Exception e) {
789+
logger.error("❌ Failed to connect: {}", e.getMessage());
790+
}
791+
792+
} catch (Exception e) {
793+
logger.error("Failed to load configuration: {}", e.getMessage(), e);
794+
System.exit(1);
795+
}
796+
}
797+
}
678798
```
799+
800+
</SdkTabs.Java>
801+
802+
803+
</SdkTabs>

docs/develop/go/temporal-client.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tags:
3333
---
3434

3535
A [Temporal Client](/encyclopedia/temporal-sdks#temporal-client) enables you to communicate with the
36-
[Temporal Service](/temporal-service). Communication with a Temporal Service includes lets you perform actions such as
36+
[Temporal Service](/temporal-service). Communication with a Temporal Service lets you perform actions such as
3737
starting Workflow Executions, sending Signals to Workflow Executions, sending Queries to Workflow Executions, getting
3838
the results of a Workflow Execution, and providing Activity Task Tokens.
3939

docs/develop/java/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Use the essential components of a Temporal Application (Workflows, Activities, a
4646
Connect to a Temporal Service and start a Workflow Execution.
4747

4848
- [Connect to a development Temporal Service](/develop/java/temporal-client#connect-to-development-service)
49-
- [Connect to a custom Namespace](/develop/java/temporal-client#connect-to-custom-namespace)
5049
- [Connect to Temporal Cloud](/develop/java/temporal-client#connect-to-temporal-cloud)
5150
- [Start a Workflow Execution](/develop/java/temporal-client#start-workflow-execution)
5251

docs/develop/java/namespaces.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The Retention Period setting using `WorkflowExecutionRetentionPeriod` is mandato
6767
The minimum value you can set for this period is 1 day.
6868

6969
Once registered, set Namespace using `WorkflowClientOptions` within a Workflow Client to run your Workflow Executions within that Namespace.
70-
See [how to set Namespace in a Client in Java](/develop/java/temporal-client#connect-to-custom-namespace) for details.
70+
See [Connect to a Development Temporal Service](/develop/java/temporal-client#connect-to-development-service) for details.
7171

7272
Note that Namespace registration using this API takes up to 10 seconds to complete.
7373
Ensure that you wait for this registration to complete before starting the Workflow Execution against the Namespace.

0 commit comments

Comments
 (0)