17
17
18
18
package com .uber .cadence .samples .hello ;
19
19
20
- import static com .uber .cadence .samples .common .SampleConstants .DOMAIN ;
21
-
22
20
import com .uber .cadence .activity .ActivityMethod ;
23
21
import com .uber .cadence .client .WorkflowClient ;
22
+ import com .uber .cadence .serviceclient .ClientOptions ;
23
+ import com .uber .cadence .serviceclient .IWorkflowService ;
24
+ import com .uber .cadence .serviceclient .WorkflowServiceTChannel ;
24
25
import com .uber .cadence .worker .Worker ;
26
+ import com .uber .cadence .worker .WorkerFactory ;
25
27
import com .uber .cadence .worker .WorkerOptions ;
26
28
import com .uber .cadence .workflow .Workflow ;
27
29
import com .uber .cadence .workflow .WorkflowMethod ;
@@ -91,21 +93,21 @@ public String composeGreeting(String greeting, String name) {
91
93
}
92
94
93
95
public static void main (String [] args ) throws IOException {
96
+ final ClientOptions clientOptions =
97
+ ClientOptions .newBuilder ().setMetricsScope (createMetricScope ()).build ();
98
+ // final ClientOptions clientOptions = ClientOptions.newBuilder().build();
99
+ IWorkflowService service = new WorkflowServiceTChannel (clientOptions );
100
+ final WorkflowClient workflowClient = WorkflowClient .newInstance (service );
94
101
// Start a worker that hosts both workflow and activity implementations.
95
- Worker .Factory factory = new Worker .Factory (DOMAIN );
96
- PrometheusReporter .builder ().registry (CollectorRegistry .defaultRegistry ).build ();
97
- final WorkerOptions workerOptions =
98
- new WorkerOptions .Builder ().setMetricsScope (createMetricScope ()).build ();
99
- Worker worker = factory .newWorker (TASK_LIST , workerOptions );
102
+ WorkerFactory factory = WorkerFactory .newInstance (workflowClient );
103
+ Worker worker = factory .newWorker (TASK_LIST , WorkerOptions .defaultInstance ());
100
104
// Workflows are stateful. So you need a type to create instances.
101
105
worker .registerWorkflowImplementationTypes (GreetingWorkflowImpl .class );
102
106
// Activities are stateless and thread safe. So a shared instance is used.
103
107
worker .registerActivitiesImplementations (new GreetingActivitiesImpl ());
104
108
// Start listening to the workflow and activity task lists.
105
109
factory .start ();
106
110
107
- // Start a workflow execution. Usually this is done from another program.
108
- WorkflowClient workflowClient = WorkflowClient .newInstance (DOMAIN );
109
111
// Get a workflow stub using the same task list the worker uses.
110
112
GreetingWorkflow workflow = workflowClient .newWorkflowStub (GreetingWorkflow .class );
111
113
// Execute a workflow waiting for it to complete.
@@ -117,7 +119,9 @@ private static Scope createMetricScope() throws IOException {
117
119
CollectorRegistry registry = CollectorRegistry .defaultRegistry ;
118
120
HTTPServer httpServer = new HTTPServer (new InetSocketAddress (9098 ), registry );
119
121
PrometheusReporter reporter = PrometheusReporter .builder ().registry (registry ).build ();
120
- Scope scope = new RootScopeBuilder ().reporter (reporter ).reportEvery (Duration .ofSeconds (1 ));
122
+ // Make sure to set separator to "_" for Prometheus. Default is "." and doesn't work.
123
+ Scope scope =
124
+ new RootScopeBuilder ().separator ("_" ).reporter (reporter ).reportEvery (Duration .ofSeconds (1 ));
121
125
return new PrometheusScope (scope );
122
126
}
123
127
}
0 commit comments