Search in sources :

Example 1 with WorkflowClientOptions

use of io.temporal.client.WorkflowClientOptions in project samples-java by temporalio.

the class Starter method main.

public static void main(String[] args) {
    String type = "OpenTelemetry";
    if (args.length == 1) {
        type = args[0];
    }
    // Set the OpenTracing client interceptor
    WorkflowClientOptions clientOptions = WorkflowClientOptions.newBuilder().setInterceptors(new OpenTracingClientInterceptor(JaegerUtils.getJaegerOptions(type))).build();
    WorkflowClient client = WorkflowClient.newInstance(service, clientOptions);
    WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setWorkflowId("tracingWorkflow").setTaskQueue(TASK_QUEUE_NAME).build();
    // Create typed workflow stub
    TracingWorkflow workflow = client.newWorkflowStub(TracingWorkflow.class, workflowOptions);
    // Convert to untyped and start it with signalWithStart
    WorkflowStub untyped = WorkflowStub.fromTyped(workflow);
    untyped.signalWithStart("setLanguage", new Object[] { "Spanish" }, new Object[] { "John" });
    String greeting = untyped.getResult(String.class);
    System.out.println("Greeting: " + greeting);
    System.exit(0);
}
Also used : WorkflowClientOptions(io.temporal.client.WorkflowClientOptions) WorkflowStub(io.temporal.client.WorkflowStub) TracingWorkflow(io.temporal.samples.tracing.workflow.TracingWorkflow) WorkflowClient(io.temporal.client.WorkflowClient) WorkflowOptions(io.temporal.client.WorkflowOptions) OpenTracingClientInterceptor(io.temporal.opentracing.OpenTracingClientInterceptor)

Example 2 with WorkflowClientOptions

use of io.temporal.client.WorkflowClientOptions in project samples-java by temporalio.

the class Starter method main.

public static void main(String[] args) {
    WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
    // Add CloudEventsPayloadConverter
    // It has the same encoding type as JacksonJsonPayloadConverter
    DefaultDataConverter ddc = DefaultDataConverter.newDefaultInstance().withPayloadConverterOverrides(new CloudEventsPayloadConverter());
    WorkflowClientOptions workflowClientOptions = WorkflowClientOptions.newBuilder().setDataConverter(ddc).build();
    WorkflowClient client = WorkflowClient.newInstance(service, workflowClientOptions);
    WorkerFactory factory = WorkerFactory.newInstance(client);
    Worker worker = factory.newWorker(TASK_QUEUE);
    worker.registerWorkflowImplementationTypes(CEWorkflowImpl.class);
    factory.start();
    WorkflowOptions newCustomerWorkflowOptions = WorkflowOptions.newBuilder().setTaskQueue(TASK_QUEUE).build();
    CEWorkflow workflow = client.newWorkflowStub(CEWorkflow.class, newCustomerWorkflowOptions);
    // Create 10 cloud events
    List<CloudEvent> cloudEventList = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        cloudEventList.add(CloudEventBuilder.v1().withId(String.valueOf(100 + i)).withType("example.demo").withSource(URI.create("http://temporal.io")).withData("application/json", ("{\n" + "\"greeting\": \"hello " + i + "\"\n" + "}").getBytes(Charset.defaultCharset())).build());
    }
    WorkflowClient.start(workflow::exec, cloudEventList.get(0));
    // Send signals (cloud event data)
    for (int j = 1; j < 10; j++) {
        workflow.addEvent(cloudEventList.get(j));
    }
    // Get the CE result and get its data (JSON)
    String result = ((JsonCloudEventData) workflow.getLastEvent().getData()).getNode().get("greeting").asText();
    System.out.println("Last event body: " + result);
    System.exit(0);
}
Also used : ArrayList(java.util.ArrayList) WorkflowClient(io.temporal.client.WorkflowClient) DefaultDataConverter(io.temporal.common.converter.DefaultDataConverter) WorkerFactory(io.temporal.worker.WorkerFactory) JsonCloudEventData(io.cloudevents.jackson.JsonCloudEventData) WorkflowClientOptions(io.temporal.client.WorkflowClientOptions) Worker(io.temporal.worker.Worker) WorkflowOptions(io.temporal.client.WorkflowOptions) CloudEvent(io.cloudevents.CloudEvent) WorkflowServiceStubs(io.temporal.serviceclient.WorkflowServiceStubs)

Example 3 with WorkflowClientOptions

use of io.temporal.client.WorkflowClientOptions 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)

Aggregations

WorkflowClientOptions (io.temporal.client.WorkflowClientOptions)3 WorkflowClient (io.temporal.client.WorkflowClient)2 WorkflowOptions (io.temporal.client.WorkflowOptions)2 CloudEvent (io.cloudevents.CloudEvent)1 JsonCloudEventData (io.cloudevents.jackson.JsonCloudEventData)1 WorkflowStub (io.temporal.client.WorkflowStub)1 DefaultDataConverter (io.temporal.common.converter.DefaultDataConverter)1 OpenTracingClientInterceptor (io.temporal.opentracing.OpenTracingClientInterceptor)1 TracingWorkflow (io.temporal.samples.tracing.workflow.TracingWorkflow)1 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)1 Worker (io.temporal.worker.Worker)1 WorkerFactory (io.temporal.worker.WorkerFactory)1 WorkerFactoryOptions (io.temporal.worker.WorkerFactoryOptions)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1