use of io.temporal.worker.WorkerFactoryOptions in project samples-java by temporalio.
the class InterceptorStarter method main.
public static void main(String[] args) {
WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
WorkflowClient client = WorkflowClient.newInstance(service);
WorkerFactoryOptions wfo = WorkerFactoryOptions.newBuilder().setWorkerInterceptors(interceptor).validateAndBuildWithDefaults();
WorkerFactory factory = WorkerFactory.newInstance(client, wfo);
Worker worker = factory.newWorker(TEST_QUEUE);
worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class, MyChildWorkflowImpl.class);
worker.registerActivitiesImplementations(new MyActivitiesImpl());
factory.start();
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setWorkflowId(WORKFLOW_ID).setTaskQueue(TEST_QUEUE).build();
MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, workflowOptions);
WorkflowClient.start(workflow::exec);
workflow.signalNameAndTitle("John", "Customer");
String name = workflow.queryName();
String title = workflow.queryTitle();
// Send exit signal to workflow
workflow.exit();
// Wait for workflow completion via WorkflowStub
WorkflowStub untyped = WorkflowStub.fromTyped(workflow);
String result = untyped.getResult(String.class);
// Print workflow
logger.info("Workflow Result: " + result);
// Print the Query results
logger.info("Query results: ");
logger.info("Name: " + name);
logger.info("Title: " + title);
// Print the Counter Info
logger.info("Collected Counter Info: ");
logger.info(Counter.getInfo());
System.exit(0);
}
use of io.temporal.worker.WorkerFactoryOptions in project sdk-java by temporalio.
the class TestWorkflowEnvironmentCreationTest method testCreateWithValidatedDefaultOptions.
@Test
public void testCreateWithValidatedDefaultOptions() {
WorkflowClientOptions workflowClientOptions = WorkflowClientOptions.newBuilder().validateAndBuildWithDefaults();
WorkerFactoryOptions workerFactoryOptions = WorkerFactoryOptions.newBuilder().validateAndBuildWithDefaults();
TestWorkflowEnvironment testEnv = TestWorkflowEnvironment.newInstance(TestEnvironmentOptions.newBuilder().setWorkflowClientOptions(workflowClientOptions).setWorkerFactoryOptions(workerFactoryOptions).validateAndBuildWithDefaults());
testEnv.close();
}
use of io.temporal.worker.WorkerFactoryOptions in project samples-java by temporalio.
the class TracingWorker method main.
public static void main(String[] args) {
String type = "OpenTelemetry";
if (args.length == 1) {
type = args[0];
}
// Set the OpenTracing client interceptor
WorkerFactoryOptions factoryOptions = WorkerFactoryOptions.newBuilder().setWorkerInterceptors(new OpenTracingWorkerInterceptor(JaegerUtils.getJaegerOptions(type))).build();
WorkerFactory factory = WorkerFactory.newInstance(client, factoryOptions);
Worker worker = factory.newWorker(TASK_QUEUE_NAME);
worker.registerWorkflowImplementationTypes(TracingWorkflowImpl.class, TracingChildWorkflowImpl.class);
worker.registerActivitiesImplementations(new TracingActivitiesImpl());
factory.start();
}
Aggregations