Search in sources :

Example 1 with WorkerFactoryOptions

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);
}
Also used : WorkflowStub(io.temporal.client.WorkflowStub) WorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions) WorkflowClient(io.temporal.client.WorkflowClient) Worker(io.temporal.worker.Worker) MyActivitiesImpl(io.temporal.samples.interceptor.activities.MyActivitiesImpl) WorkflowOptions(io.temporal.client.WorkflowOptions) WorkerFactory(io.temporal.worker.WorkerFactory) MyWorkflow(io.temporal.samples.interceptor.workflow.MyWorkflow) WorkflowServiceStubs(io.temporal.serviceclient.WorkflowServiceStubs)

Example 2 with WorkerFactoryOptions

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();
}
Also used : WorkflowClientOptions(io.temporal.client.WorkflowClientOptions) WorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions) Test(org.junit.Test)

Example 3 with WorkerFactoryOptions

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();
}
Also used : WorkerFactoryOptions(io.temporal.worker.WorkerFactoryOptions) TracingActivitiesImpl(io.temporal.samples.tracing.workflow.TracingActivitiesImpl) Worker(io.temporal.worker.Worker) OpenTracingWorkerInterceptor(io.temporal.opentracing.OpenTracingWorkerInterceptor) WorkerFactory(io.temporal.worker.WorkerFactory)

Aggregations

WorkerFactoryOptions (io.temporal.worker.WorkerFactoryOptions)3 Worker (io.temporal.worker.Worker)2 WorkerFactory (io.temporal.worker.WorkerFactory)2 WorkflowClient (io.temporal.client.WorkflowClient)1 WorkflowClientOptions (io.temporal.client.WorkflowClientOptions)1 WorkflowOptions (io.temporal.client.WorkflowOptions)1 WorkflowStub (io.temporal.client.WorkflowStub)1 OpenTracingWorkerInterceptor (io.temporal.opentracing.OpenTracingWorkerInterceptor)1 MyActivitiesImpl (io.temporal.samples.interceptor.activities.MyActivitiesImpl)1 MyWorkflow (io.temporal.samples.interceptor.workflow.MyWorkflow)1 TracingActivitiesImpl (io.temporal.samples.tracing.workflow.TracingActivitiesImpl)1 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)1 Test (org.junit.Test)1