mirror of https://github.com/dapr/java-sdk.git
Merge c9114237d0 into a160717c91
This commit is contained in:
commit
2f6b64d7bb
|
|
@ -47,7 +47,11 @@
|
|||
<dependency>
|
||||
<groupId>io.dapr</groupId>
|
||||
<artifactId>durabletask-client</artifactId>
|
||||
<version>1.5.7</version>
|
||||
<version>1.5.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.opentelemetry</groupId>
|
||||
<artifactId>opentelemetry-api</artifactId>
|
||||
</dependency>
|
||||
<!--
|
||||
manually declare durabletask-client's jackson dependencies
|
||||
|
|
|
|||
|
|
@ -21,10 +21,9 @@ import io.dapr.durabletask.OrchestrationMetadata;
|
|||
import io.dapr.durabletask.PurgeResult;
|
||||
import io.dapr.utils.NetworkUtils;
|
||||
import io.dapr.workflows.Workflow;
|
||||
import io.dapr.workflows.internal.ApiTokenClientInterceptor;
|
||||
import io.dapr.workflows.runtime.DefaultWorkflowInstanceStatus;
|
||||
import io.grpc.ClientInterceptor;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.opentelemetry.context.Context;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
|
@ -37,7 +36,6 @@ import java.util.concurrent.TimeoutException;
|
|||
*/
|
||||
public class DaprWorkflowClient implements AutoCloseable {
|
||||
|
||||
private ClientInterceptor workflowApiTokenInterceptor;
|
||||
private DurableTaskClient innerClient;
|
||||
private ManagedChannel grpcChannel;
|
||||
|
||||
|
|
@ -54,7 +52,7 @@ public class DaprWorkflowClient implements AutoCloseable {
|
|||
* @param properties Properties for the GRPC Channel.
|
||||
*/
|
||||
public DaprWorkflowClient(Properties properties) {
|
||||
this(NetworkUtils.buildGrpcManagedChannel(properties, new ApiTokenClientInterceptor(properties)));
|
||||
this(NetworkUtils.buildGrpcManagedChannel(properties));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,6 +98,11 @@ public class DaprWorkflowClient implements AutoCloseable {
|
|||
return this.innerClient.scheduleNewOrchestrationInstance(clazz.getCanonicalName(), input);
|
||||
}
|
||||
|
||||
public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, Object input, String instanceId,
|
||||
Context context) {
|
||||
return this.innerClient.scheduleNewOrchestrationInstance(clazz.getCanonicalName(), input, instanceId, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a new workflow using DurableTask client.
|
||||
*
|
||||
|
|
@ -128,6 +131,23 @@ public class DaprWorkflowClient implements AutoCloseable {
|
|||
orchestrationInstanceOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a new workflow with a specified set of options for execution.
|
||||
*
|
||||
* @param <T> any Workflow type
|
||||
* @param clazz Class extending Workflow to start an instance of.
|
||||
* @param options the options for the new workflow, including input, instance ID, etc.
|
||||
* @param context otel Context for trace propagation.
|
||||
* @return the <code>instanceId</code> parameter value.
|
||||
*/
|
||||
public <T extends Workflow> String scheduleNewWorkflow(Class<T> clazz, NewWorkflowOptions options,
|
||||
Context context) {
|
||||
NewOrchestrationInstanceOptions orchestrationInstanceOptions = fromNewWorkflowOptions(options);
|
||||
|
||||
return this.innerClient.scheduleNewOrchestrationInstance(clazz.getCanonicalName(),
|
||||
orchestrationInstanceOptions, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend the workflow associated with the provided instance id.
|
||||
*
|
||||
|
|
@ -278,8 +298,10 @@ public class DaprWorkflowClient implements AutoCloseable {
|
|||
* @return a new instance of a DurableTaskClient with a GRPC channel.
|
||||
*/
|
||||
private static DurableTaskClient createDurableTaskClient(ManagedChannel grpcChannel) {
|
||||
|
||||
return new DurableTaskGrpcClientBuilder()
|
||||
.grpcChannel(grpcChannel)
|
||||
.interceptor(new io.dapr.durabletask.interceptors.DaprWorkflowClientGrpcInterceptors())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,14 @@ package io.dapr.workflows.runtime;
|
|||
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.durabletask.DurableTaskGrpcWorkerBuilder;
|
||||
import io.dapr.durabletask.interceptors.DaprWorkflowClientGrpcInterceptors;
|
||||
import io.dapr.utils.NetworkUtils;
|
||||
import io.dapr.workflows.Workflow;
|
||||
import io.dapr.workflows.WorkflowActivity;
|
||||
import io.dapr.workflows.internal.ApiTokenClientInterceptor;
|
||||
import io.grpc.ClientInterceptor;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.opentelemetry.context.Context;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -65,7 +67,8 @@ public class WorkflowRuntimeBuilder {
|
|||
private WorkflowRuntimeBuilder(Properties properties, Logger logger) {
|
||||
this.workflowApiTokenInterceptor = new ApiTokenClientInterceptor(properties);
|
||||
this.managedChannel = NetworkUtils.buildGrpcManagedChannel(properties, workflowApiTokenInterceptor);
|
||||
this.builder = new DurableTaskGrpcWorkerBuilder().grpcChannel(this.managedChannel);
|
||||
this.builder = new DurableTaskGrpcWorkerBuilder().grpcChannel(this.managedChannel)
|
||||
.interceptors(new DaprWorkflowClientGrpcInterceptors());
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +80,8 @@ public class WorkflowRuntimeBuilder {
|
|||
public WorkflowRuntime build() {
|
||||
if (instance == null) {
|
||||
synchronized (WorkflowRuntime.class) {
|
||||
this.executorService = this.executorService == null ? Executors.newCachedThreadPool() : this.executorService;
|
||||
this.executorService = Context.taskWrapping(this.executorService == null ? Executors.newCachedThreadPool()
|
||||
: this.executorService);
|
||||
if (instance == null) {
|
||||
instance = new WorkflowRuntime(
|
||||
this.builder.withExecutorService(this.executorService).build(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue