Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,26 @@ Demonstrates a complex workflow with parallel execution and stateful logic.

### Temporal Connection

Edit `src/main/resources/application.yml`:
The application uses environment variables for configuration with sensible defaults:

```yaml
temporal:
service-address: localhost:7233 # Temporal server address
namespace: default # Temporal namespace
service-address: ${TEMPORAL_ADDRESS:localhost:7233} # Temporal server address
namespace: ${TEMPORAL_NAMESPACE:default} # Temporal namespace
cert-path: ${TEMPORAL_CERT_PATH:} # Path to client certificate (for mTLS)
key-path: ${TEMPORAL_KEY_PATH:} # Path to private key (for mTLS)
```

**For local development**, no configuration is needed. The application defaults to `localhost:7233` with namespace `default`.

### Temporal Cloud (mTLS)

For production deployments using Temporal Cloud, the application automatically detects and configures mTLS when certificate paths are provided via environment variables.
For production deployments using Temporal Cloud, configure via environment variables:

**Set environment variables:**

```bash
export TEMPORAL_SERVICE_ADDRESS=<namespace>.<account-id>.tmprl.cloud:7233
export TEMPORAL_ADDRESS=<namespace>.<account-id>.tmprl.cloud:7233
export TEMPORAL_NAMESPACE=<your-namespace>
export TEMPORAL_CERT_PATH=/path/to/client.pem
export TEMPORAL_KEY_PATH=/path/to/client.key
Expand All @@ -181,12 +185,19 @@ export TEMPORAL_KEY_PATH=/path/to/client.key
./gradlew runCrawlerWorker
```

The application will automatically:
- Detect the presence of `TEMPORAL_CERT_PATH` and `TEMPORAL_KEY_PATH`
- Configure mTLS for Temporal Cloud connection
- Fall back to local connection if certificates are not provided
The workers will automatically use the environment variables and:
- Connect to your Temporal Cloud namespace
- Use mTLS authentication if certificate paths are provided
- Display connection information on startup

**Example startup output:**

**Note**: For local development, no configuration is needed. The application defaults to `localhost:7233` with namespace `default`.
```
HTTP Worker started
Temporal Service: my-namespace.a2b3c.tmprl.cloud:7233
Task Queue: http-task-queue
Press Ctrl+C to stop the worker.
```

### Worker Configuration

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.temporal.workflows.crawler;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import io.temporal.worker.Worker;
Expand All @@ -18,8 +19,10 @@
public class CrawlerWorker {

public static final String TASK_QUEUE = "crawler-task-queue";
private static final String TEMPORAL_SERVICE_ADDRESS = "localhost:7233";
private static final String NAMESPACE = "default";
private static final String TEMPORAL_SERVICE_ADDRESS =
System.getenv().getOrDefault("TEMPORAL_ADDRESS", "localhost:7233");
private static final String NAMESPACE =
System.getenv().getOrDefault("TEMPORAL_NAMESPACE", "default");
private static final int MAX_CONCURRENT_ACTIVITIES = 16;

public static void main(String[] args) {
Expand All @@ -28,7 +31,9 @@ public static void main(String[] args) {
WorkflowServiceStubsOptions.newBuilder().setTarget(TEMPORAL_SERVICE_ADDRESS).build();

WorkflowServiceStubs service = WorkflowServiceStubs.newServiceStubs(options);
WorkflowClient client = WorkflowClient.newInstance(service);
WorkflowClientOptions clientOptions =
WorkflowClientOptions.newBuilder().setNamespace(NAMESPACE).build();
WorkflowClient client = WorkflowClient.newInstance(service, clientOptions);

// Create worker factory
WorkerFactory factory = WorkerFactory.newInstance(client);
Expand All @@ -50,7 +55,10 @@ public static void main(String[] args) {
// Start the worker
factory.start();

System.out.println("Crawler Worker started. Polling task queue: " + TASK_QUEUE);
System.out.println("Crawler Worker started");
System.out.println("Temporal Service: " + TEMPORAL_SERVICE_ADDRESS);
System.out.println("Namespace: " + NAMESPACE);
System.out.println("Task Queue: " + TASK_QUEUE);
System.out.println("Max concurrent activities: " + MAX_CONCURRENT_ACTIVITIES);
System.out.println("Press Ctrl+C to stop the worker.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
public class HttpWorker {

public static final String TASK_QUEUE = "http-task-queue";
private static final String TEMPORAL_SERVICE_ADDRESS = "localhost:7233";
private static final String NAMESPACE = "default";
private static final String TEMPORAL_SERVICE_ADDRESS =
System.getenv().getOrDefault("TEMPORAL_ADDRESS", "localhost:7233");

public static void main(String[] args) {
// Create connection to Temporal service
Expand All @@ -43,7 +43,9 @@ public static void main(String[] args) {
// Start the worker
factory.start();

System.out.println("HTTP Worker started. Polling task queue: " + TASK_QUEUE);
System.out.println("HTTP Worker started");
System.out.println("Temporal Service: " + TEMPORAL_SERVICE_ADDRESS);
System.out.println("Task Queue: " + TASK_QUEUE);
System.out.println("Press Ctrl+C to stop the worker.");
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
temporal:
service-address: ${TEMPORAL_SERVICE_ADDRESS:localhost:7233}
service-address: ${TEMPORAL_ADDRESS:localhost:7233}
namespace: ${TEMPORAL_NAMESPACE:default}
cert-path: ${TEMPORAL_CERT_PATH:}
key-path: ${TEMPORAL_KEY_PATH:}
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
temporal:
service-address: localhost:7233
namespace: test
service-address: ${TEMPORAL_ADDRESS:localhost:7233}
namespace: ${TEMPORAL_NAMESPACE:test}

spring:
application:
Expand Down