Skip to content

Commit 1b0f1a9

Browse files
committed
docs: update Java tutorial
1 parent 8bbf9f0 commit 1b0f1a9

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

docs/01-get-started/02-java-hello-world.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ implementation group: 'com.uber.cadence', name: 'cadence-client', version: '<lat
2323
```
2424
Also add the following dependencies that cadence-client relies on:
2525
```gradle
26-
implementation group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
27-
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
26+
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.18'
2827
```
2928
Make sure that the following code compiles:
3029
```java
@@ -38,7 +37,7 @@ public class GettingStarted {
3837

3938
public interface HelloWorld {
4039
@WorkflowMethod
41-
void sayHello(String name);
40+
String sayHello(String name);
4241
}
4342

4443
}
@@ -67,7 +66,6 @@ Also add the following logback config file somewhere in your classpath:
6766

6867
Let's add `HelloWorldImpl` with the `sayHello` method that just logs the "Hello ..." and returns.
6968
```java
70-
import com.uber.cadence.worker.Worker;
7169
import com.uber.cadence.workflow.Workflow;
7270
import com.uber.cadence.workflow.WorkflowMethod;
7371
import org.slf4j.Logger;
@@ -78,14 +76,16 @@ public class GettingStarted {
7876

7977
public interface HelloWorld {
8078
@WorkflowMethod
81-
void sayHello(String name);
79+
String sayHello(String name);
8280
}
8381

8482
public static class HelloWorldImpl implements HelloWorld {
8583

8684
@Override
8785
public void sayHello(String name) {
88-
logger.info("Hello " + name + "!");
86+
final String result = "Hello " + name + "!";
87+
logger.info("{}", result);
88+
return result;
8989
}
9090
}
9191
}
@@ -94,17 +94,33 @@ To link the :workflow: implementation to the Cadence framework, it should be reg
9494
a Cadence Service. By default the :worker: connects to the locally running Cadence service.
9595

9696
```java
97-
public static void main(String[] args) {
98-
WorkflowClient workflowClient =
99-
WorkflowClient.newInstance(
100-
new WorkflowServiceTChannel(ClientOptions.defaultInstance()),
101-
WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build());
102-
// Get worker to poll the task list.
103-
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
104-
Worker worker = factory.newWorker(TASK_LIST);
105-
worker.registerWorkflowImplementationTypes(HelloWorldImpl.class);
106-
factory.start();
107-
}
97+
import com.uber.cadence.client.WorkflowClient;
98+
import com.uber.cadence.client.WorkflowClientOptions;
99+
import com.uber.cadence.serviceclient.ClientOptions;
100+
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
101+
import com.uber.cadence.worker.Worker;
102+
import com.uber.cadence.worker.WorkerFactory;
103+
104+
// other imports
105+
106+
public class GettingStarted {
107+
108+
private static final String DOMAIN = "test-domain";
109+
private static final String TASK_LIST = "HelloWorldTaskList";
110+
111+
// existing code
112+
113+
public static void main(String[] args) {
114+
WorkflowClient workflowClient =
115+
WorkflowClient.newInstance(
116+
new WorkflowServiceTChannel(ClientOptions.defaultInstance()),
117+
WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build());
118+
// Get worker to poll the task list.
119+
WorkerFactory factory = WorkerFactory.newInstance(workflowClient);
120+
Worker worker = factory.newWorker(TASK_LIST);
121+
worker.registerWorkflowImplementationTypes(HelloWorldImpl.class);
122+
factory.start();
123+
}
108124
```
109125

110126
The code is slightly different if you are using client version prior to 3.0.0:

0 commit comments

Comments
 (0)