Skip to content
38 changes: 16 additions & 22 deletions docs/best-practices/worker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ production-ready Worker image:

{/* SNIPSTART oms-dockerfile-worker */}
[Dockerfile](https://github.com/temporalio/reference-app-orders-go/blob/main/Dockerfile)

```Dockerfile
FROM golang:1.23.8 AS oms-builder

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

FROM busybox AS oms-worker
```

{/* SNIPEND oms-dockerfile-worker */}

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

{/* SNIPSTART oms-billing-worker-deployment {"selectedLines": ["20-35"]} */}
[deployments/k8s/billing-worker-deployment.yaml](https://github.com/temporalio/reference-app-orders-go/blob/main/deployments/k8s/billing-worker-deployment.yaml)

```yaml
# ...
spec:
containers:
- args:
- -k
- supersecretkey
- -s
- billing
env:
- name: FRAUD_API_URL
value: http://billing-api:8084
- name: TEMPORAL_ADDRESS
value: temporal-frontend.temporal:7233
image: ghcr.io/temporalio/reference-app-orders-go-worker:latest
name: billing-worker
imagePullPolicy: Always
enableServiceLinks: false
spec:
containers:
- args:
- -k
- supersecretkey
- -s
- billing
env:
- name: FRAUD_API_URL
value: http://billing-api:8084
- name: TEMPORAL_ADDRESS
value: temporal-frontend.temporal:7233
image: ghcr.io/temporalio/reference-app-orders-go-worker:latest
name: billing-worker
imagePullPolicy: Always
enableServiceLinks: false
```

{/* SNIPEND */}

### Separate Task Queues logically
Expand Down Expand Up @@ -132,7 +128,6 @@ Worker reference to avoid this issue.

{/* SNIPSTART oms-billing-worker-go {"selectedLines": ["12-23"]} */}
[app/billing/worker.go](https://github.com/temporalio/reference-app-orders-go/blob/main/app/billing/worker.go)

```go
// ...
// RunWorker runs a Workflow and Activity worker for the Billing system.
Expand All @@ -148,7 +143,6 @@ func RunWorker(ctx context.Context, config config.AppConfig, client client.Clien
return w.Run(temporalutil.WorkerInterruptFromContext(ctx))
}
```

{/* SNIPEND */}

### Use Worker Versioning to safely deploy new Workflow code
Expand Down
127 changes: 126 additions & 1 deletion docs/develop/environment-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,66 @@ main().catch((err) => {
{/* SNIPEND */}

</SdkTabs.TypeScript>

<SdkTabs.Java>

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.

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.

```java
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.envconfig.ClientConfigProfile;
import io.temporal.envconfig.LoadClientConfigProfileOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoadFromFile {

private static final Logger logger = LoggerFactory.getLogger(LoadFromFile.class);

public static void main(String[] args) {
try {

ClientConfigProfile profile = ClientConfigProfile.load(LoadClientConfigProfileOptions.newBuilder().build());

WorkflowServiceStubsOptions serviceStubsOptions = profile.toWorkflowServiceStubsOptions();
WorkflowClientOptions clientOptions = profile.toWorkflowClientOptions();

try {
// Create the workflow client using the loaded configuration
WorkflowClient client =
WorkflowClient.newInstance(
WorkflowServiceStubs.newServiceStubs(serviceStubsOptions), clientOptions);

// Test the connection by getting system info
var systemInfo =
client
.getWorkflowServiceStubs()
.blockingStub()
.getSystemInfo(
io.temporal.api.workflowservice.v1.GetSystemInfoRequest.getDefaultInstance());

logger.info("✅ Client connected successfully!");
logger.info(" Server version: {}", systemInfo.getServerVersion());

} catch (Exception e) {
logger.error("❌ Failed to connect: {}", e.getMessage());
}

} catch (Exception e) {
logger.error("Failed to load configuration: {}", e.getMessage(), e);
System.exit(1);
}
}
}
```

</SdkTabs.Java>
</SdkTabs>

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

</SdkTabs.TypeScript>

</SdkTabs>
<SdkTabs.Java>

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.

```java {21-25}
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.envconfig.ClientConfigProfile;
import io.temporal.envconfig.LoadClientConfigProfileOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoadFromFile {

private static final Logger logger = LoggerFactory.getLogger(LoadFromFile.class);

public static void main(String[] args) {
try {

String configFilePath =
Paths.get(LoadFromFile.class.getResource("/config.toml").toURI()).toString();

ClientConfigProfile profile =
ClientConfigProfile.load(
LoadClientConfigProfileOptions.newBuilder()
.setConfigFilePath(configFilePath)
.build());

WorkflowServiceStubsOptions serviceStubsOptions = profile.toWorkflowServiceStubsOptions();
WorkflowClientOptions clientOptions = profile.toWorkflowClientOptions();

try {
// Create the workflow client using the loaded configuration
WorkflowClient client =
WorkflowClient.newInstance(
WorkflowServiceStubs.newServiceStubs(serviceStubsOptions), clientOptions);

// Test the connection by getting system info
var systemInfo =
client
.getWorkflowServiceStubs()
.blockingStub()
.getSystemInfo(
io.temporal.api.workflowservice.v1.GetSystemInfoRequest.getDefaultInstance());

logger.info("✅ Client connected successfully!");
logger.info(" Server version: {}", systemInfo.getServerVersion());

} catch (Exception e) {
logger.error("❌ Failed to connect: {}", e.getMessage());
}

} catch (Exception e) {
logger.error("Failed to load configuration: {}", e.getMessage(), e);
System.exit(1);
}
}
}
```

</SdkTabs.Java>


</SdkTabs>
2 changes: 1 addition & 1 deletion docs/develop/go/temporal-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tags:
---

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

Expand Down
1 change: 0 additions & 1 deletion docs/develop/java/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Use the essential components of a Temporal Application (Workflows, Activities, a
Connect to a Temporal Service and start a Workflow Execution.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/java/namespaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The Retention Period setting using `WorkflowExecutionRetentionPeriod` is mandato
The minimum value you can set for this period is 1 day.

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

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