Skip to content

Commit 5ae487f

Browse files
authored
added ssl full example and readme (temporalio#472)
1 parent 9d144cc commit 5ae487f

File tree

5 files changed

+126
-6
lines changed

5 files changed

+126
-6
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.samples.ssl;
21+
22+
import io.temporal.workflow.WorkflowInterface;
23+
import io.temporal.workflow.WorkflowMethod;
24+
25+
@WorkflowInterface
26+
public interface MyWorkflow {
27+
@WorkflowMethod
28+
String execute();
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.samples.ssl;
21+
22+
public class MyWorkflowImpl implements MyWorkflow {
23+
@Override
24+
public String execute() {
25+
return "done";
26+
}
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Workflow execution with mTLS
2+
3+
4+
This example shows how to secure your Temporal application with [mTLS](https://docs.temporal.io/security/#encryption-in-transit-with-mtls).
5+
This is required to connect with Temporal Cloud or any production Temporal deployment.
6+
7+
8+
## Export env variables
9+
Before running the example you need to export the following env variables:
10+
11+
- TEMPORAL_ENDPOINT: grpc endpoint, for Temporal Cloud would like `${namespace}.tmprl.cloud:7233`.
12+
- TEMPORAL_NAMESPACE: Namespace.
13+
- TEMPORAL_CLIENT_CERT: For Temporal Cloud see requirements [here](https://docs.temporal.io/cloud/how-to-manage-certificates-in-temporal-cloud#end-entity-certificates).
14+
- TEMPORAL_CLIENT_KEY: For Temporal Cloud see requirements [here](https://docs.temporal.io/cloud/how-to-manage-certificates-in-temporal-cloud#end-entity-certificates).
15+
16+
17+
18+
## Running this sample
19+
20+
```bash
21+
./gradlew -q execute -PmainClass=io.temporal.samples.ssl.Starter
22+
```

core/src/main/java/io/temporal/samples/ssl/SslEnabledWorker.java renamed to core/src/main/java/io/temporal/samples/ssl/Starter.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121

2222
import io.temporal.client.WorkflowClient;
2323
import io.temporal.client.WorkflowClientOptions;
24+
import io.temporal.client.WorkflowOptions;
2425
import io.temporal.serviceclient.SimpleSslContextBuilder;
2526
import io.temporal.serviceclient.WorkflowServiceStubs;
2627
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
28+
import io.temporal.worker.Worker;
2729
import io.temporal.worker.WorkerFactory;
2830
import java.io.FileInputStream;
2931
import java.io.InputStream;
3032

31-
public class SslEnabledWorker {
33+
public class Starter {
3234

3335
static final String TASK_QUEUE = "MyTaskQueue";
36+
static final String WORKFLOW_ID = "HelloSSLWorkflow";
3437

3538
public static void main(String[] args) throws Exception {
3639
// Load your client certificate, which should look like:
@@ -47,6 +50,7 @@ public static void main(String[] args) throws Exception {
4750
String targetEndpoint = System.getenv("TEMPORAL_ENDPOINT");
4851
// Your registered namespace.
4952
String namespace = System.getenv("TEMPORAL_NAMESPACE");
53+
5054
// Create SSL enabled client by passing SslContext, created by SimpleSslContextBuilder.
5155
WorkflowServiceStubs service =
5256
WorkflowServiceStubs.newServiceStubs(
@@ -63,11 +67,49 @@ public static void main(String[] args) throws Exception {
6367
service, WorkflowClientOptions.newBuilder().setNamespace(namespace).build());
6468
// worker factory that can be used to create workers for specific task queues
6569
WorkerFactory factory = WorkerFactory.newInstance(client);
66-
// Worker that listens on a task queue and hosts both workflow and activity implementations.
67-
factory.newWorker(TASK_QUEUE);
68-
// TODO now register your workflow types and activity implementations.
69-
// worker.registerWorkflowImplementationTypes(...);
70+
71+
/*
72+
* Define the workflow worker. Workflow workers listen to a defined task queue and process
73+
* workflows and activities.
74+
*/
75+
Worker worker = factory.newWorker(TASK_QUEUE);
76+
77+
/*
78+
* Register our workflow implementation with the worker.
79+
* Workflow implementations must be known to the worker at runtime in
80+
* order to dispatch workflow tasks.
81+
*/
82+
worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class);
83+
84+
/**
85+
* Register our Activity Types with the Worker. Since Activities are stateless and thread-safe,
86+
* the Activity Type is a shared instance.
87+
*/
7088
// worker.registerActivitiesImplementations(...);
89+
90+
/*
91+
* Start all the workers registered for a specific task queue.
92+
* The started workers then start polling for workflows and activities.
93+
*/
7194
factory.start();
95+
96+
// Create the workflow client stub. It is used to start our workflow execution.
97+
MyWorkflow workflow =
98+
client.newWorkflowStub(
99+
MyWorkflow.class,
100+
WorkflowOptions.newBuilder()
101+
.setWorkflowId(WORKFLOW_ID)
102+
.setTaskQueue(TASK_QUEUE)
103+
.build());
104+
105+
/*
106+
* Execute our workflow and wait for it to complete. The call to our execute method is
107+
* synchronous.
108+
*/
109+
String greeting = workflow.execute();
110+
111+
// Display workflow execution results
112+
System.out.println(greeting);
113+
System.exit(0);
72114
}
73115
}

core/src/main/java/io/temporal/samples/terminateworkflow/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Terminate Workflow execution
22

3-
The sample demonstrates shows how to terminate Workflow Execution using the Client API.
3+
The sample demonstrates how to terminate Workflow Execution using the Client API.
44

55
```bash
66
./gradlew -q execute -PmainClass=io.temporal.samples.terminateworkflow.Starter

0 commit comments

Comments
 (0)