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
19 changes: 16 additions & 3 deletions core/src/main/java/io/temporal/samples/apikey/ApiKeyWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
Expand All @@ -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);
Expand Down
19 changes: 16 additions & 3 deletions core/src/main/java/io/temporal/samples/apikey/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
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 {

static final String TASK_QUEUE = "MyTaskQueue";
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");
Expand All @@ -27,18 +37,21 @@ 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)
.build());

WorkflowClient client =
WorkflowClient.newInstance(
service, WorkflowClientOptions.newBuilder().setNamespace(namespace).build());
service,
WorkflowClientOptions.newBuilder(profile.toWorkflowClientOptions())
.setNamespace(namespace)
.build());

WorkerFactory factory = WorkerFactory.newInstance(client);

Expand Down
31 changes: 23 additions & 8 deletions core/src/main/java/io/temporal/samples/asyncchild/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading
Loading