Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion temporal-spring-boot-autoconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ Task Queue names directly for simplicity.

Note: Worker whose name is not explicitly specified is named after it's Task Queue.

## Interceptors

To enable interceptors users can create beans implementing the `io.temporal.common.interceptors.WorkflowClientInterceptor`
, `io.temporal.common.interceptors.ScheduleClientInterceptor`, or `io.temporal.common.interceptors.WorkerInterceptor`
interface. Interceptors will be registered in the order specified by the `@Order` annotation.

## Customization of `*Options`

To provide freedom in customization of `*Options` instances that are created by this module,
Expand Down Expand Up @@ -283,7 +289,8 @@ spring.temporal:
## Customization

All customization points for the root namespace also exist for the non-root namespaces. To specify for a particular
namespace users just need to append the alias/namespace to the bean.
namespace users just need to append the alias/namespace to the bean. Currently, auto registered interceptors are not
supported, but `WorkerFactoryOptions` can always be used to customize it per namespace.

```java
// TemporalOptionsCustomizer type beans must start with the namespace/alias you defined and end with function class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.common.base.MoreObjects;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.common.interceptors.WorkerInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptor;
import io.temporal.spring.boot.TemporalOptionsCustomizer;
import io.temporal.spring.boot.autoconfigure.properties.NonRootNamespaceProperties;
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
Expand All @@ -17,7 +20,7 @@
class AutoConfigurationUtils {

@Nullable
static DataConverter choseDataConverter(
static DataConverter chooseDataConverter(
List<DataConverter> dataConverters, DataConverter mainDataConverter) {
DataConverter chosenDataConverter = null;
if (dataConverters.size() == 1) {
Expand All @@ -38,7 +41,7 @@ static DataConverter choseDataConverter(
}

@Nullable
static DataConverter choseDataConverter(
static DataConverter chooseDataConverter(
Map<String, DataConverter> dataConverters,
DataConverter mainDataConverter,
TemporalProperties properties) {
Expand All @@ -47,7 +50,7 @@ static DataConverter choseDataConverter(
}
List<NonRootNamespaceProperties> nonRootNamespaceProperties = properties.getNamespaces();
if (Objects.isNull(nonRootNamespaceProperties) || nonRootNamespaceProperties.isEmpty()) {
return choseDataConverter(new ArrayList<>(dataConverters.values()), mainDataConverter);
return chooseDataConverter(new ArrayList<>(dataConverters.values()), mainDataConverter);
} else {
List<DataConverter> dataConverterList = new ArrayList<>();
List<String> nonRootBeanNames =
Expand All @@ -69,10 +72,28 @@ static DataConverter choseDataConverter(
}
dataConverterList.add(dataConverter);
}
return choseDataConverter(dataConverterList, mainDataConverter);
return chooseDataConverter(dataConverterList, mainDataConverter);
}
}

@Nullable
static List<WorkflowClientInterceptor> chooseWorkflowClientInterceptors(
List<WorkflowClientInterceptor> workflowClientInterceptors, TemporalProperties properties) {
return workflowClientInterceptors;
}

@Nullable
static List<ScheduleClientInterceptor> chooseScheduleClientInterceptors(
List<ScheduleClientInterceptor> scheduleClientInterceptor, TemporalProperties properties) {
return scheduleClientInterceptor;
}

@Nullable
static List<WorkerInterceptor> chooseWorkerInterceptors(
List<WorkerInterceptor> workerInterceptor, TemporalProperties properties) {
return workerInterceptor;
}

static <T> TemporalOptionsCustomizer<T> chooseTemporalCustomizerBean(
Map<String, TemporalOptionsCustomizer<T>> customizerMap,
Class<T> genericOptionsBuilderClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ private void injectBeanByNonRootNamespace(NonRootNamespaceProperties ns) {
ns,
workflowServiceStubs,
dataConverterByNamespace,
null, // Currently interceptors are not supported in non-root namespace
null,
null,
tracer,
testWorkflowEnvironment,
workFactoryCustomizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import io.temporal.client.schedules.ScheduleClient;
import io.temporal.client.schedules.ScheduleClientOptions;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.common.interceptors.WorkerInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptor;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.spring.boot.TemporalOptionsCustomizer;
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
Expand All @@ -19,6 +22,7 @@
import io.temporal.worker.WorkerOptions;
import io.temporal.worker.WorkflowImplementationOptions;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -64,6 +68,11 @@ public NamespaceTemplate rootNamespaceTemplate(
@Qualifier("mainDataConverter") @Autowired(required = false) @Nullable
DataConverter mainDataConverter,
@Autowired(required = false) @Nullable Tracer otTracer,
@Autowired(required = false) @Nullable
List<WorkflowClientInterceptor> workflowClientInterceptors,
@Autowired(required = false) @Nullable
List<ScheduleClientInterceptor> scheduleClientInterceptors,
@Autowired(required = false) @Nullable List<WorkerInterceptor> workerInterceptors,
@Qualifier("temporalTestWorkflowEnvironmentAdapter") @Autowired(required = false) @Nullable
TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
@Autowired(required = false) @Nullable
Expand All @@ -80,7 +89,15 @@ public NamespaceTemplate rootNamespaceTemplate(
Map<String, TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>>
workflowImplementationCustomizerMap) {
DataConverter chosenDataConverter =
AutoConfigurationUtils.choseDataConverter(dataConverters, mainDataConverter, properties);
AutoConfigurationUtils.chooseDataConverter(dataConverters, mainDataConverter, properties);
List<WorkflowClientInterceptor> chosenClientInterceptors =
AutoConfigurationUtils.chooseWorkflowClientInterceptors(
workflowClientInterceptors, properties);
List<ScheduleClientInterceptor> chosenScheduleClientInterceptors =
AutoConfigurationUtils.chooseScheduleClientInterceptors(
scheduleClientInterceptors, properties);
List<WorkerInterceptor> chosenWorkerInterceptors =
AutoConfigurationUtils.chooseWorkerInterceptors(workerInterceptors, properties);
TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer =
AutoConfigurationUtils.chooseTemporalCustomizerBean(
workerFactoryCustomizerMap, WorkerFactoryOptions.Builder.class, properties);
Expand All @@ -104,6 +121,9 @@ public NamespaceTemplate rootNamespaceTemplate(
properties,
workflowServiceStubs,
chosenDataConverter,
chosenClientInterceptors,
chosenScheduleClientInterceptors,
chosenWorkerInterceptors,
otTracer,
testWorkflowEnvironment,
workerFactoryCustomizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import io.temporal.client.WorkflowClientOptions;
import io.temporal.client.schedules.ScheduleClientOptions;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.common.interceptors.WorkerInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptor;
import io.temporal.spring.boot.TemporalOptionsCustomizer;
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
import io.temporal.spring.boot.autoconfigure.template.TestWorkflowEnvironmentAdapter;
Expand All @@ -13,6 +16,7 @@
import io.temporal.testing.TestEnvironmentOptions;
import io.temporal.testing.TestWorkflowEnvironment;
import io.temporal.worker.WorkerFactoryOptions;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.slf4j.Logger;
Expand Down Expand Up @@ -54,6 +58,11 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
@Qualifier("mainDataConverter") @Autowired(required = false) @Nullable
DataConverter mainDataConverter,
@Autowired(required = false) @Nullable Tracer otTracer,
@Autowired(required = false) @Nullable
List<WorkflowClientInterceptor> workflowClientInterceptors,
@Autowired(required = false) @Nullable
List<ScheduleClientInterceptor> scheduleClientInterceptors,
@Autowired(required = false) @Nullable List<WorkerInterceptor> workerInterceptors,
@Autowired(required = false) @Nullable
TemporalOptionsCustomizer<TestEnvironmentOptions.Builder> testEnvOptionsCustomizer,
@Autowired(required = false) @Nullable
Expand All @@ -65,7 +74,15 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
Map<String, TemporalOptionsCustomizer<ScheduleClientOptions.Builder>>
scheduleCustomizerMap) {
DataConverter chosenDataConverter =
AutoConfigurationUtils.choseDataConverter(dataConverters, mainDataConverter, properties);
AutoConfigurationUtils.chooseDataConverter(dataConverters, mainDataConverter, properties);
List<WorkflowClientInterceptor> chosenClientInterceptors =
AutoConfigurationUtils.chooseWorkflowClientInterceptors(
workflowClientInterceptors, properties);
List<ScheduleClientInterceptor> chosenScheduleClientInterceptors =
AutoConfigurationUtils.chooseScheduleClientInterceptors(
scheduleClientInterceptors, properties);
List<WorkerInterceptor> chosenWorkerInterceptors =
AutoConfigurationUtils.chooseWorkerInterceptors(workerInterceptors, properties);

TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer =
AutoConfigurationUtils.chooseTemporalCustomizerBean(
Expand All @@ -83,6 +100,8 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
new WorkflowClientOptionsTemplate(
properties.getNamespace(),
chosenDataConverter,
chosenClientInterceptors,
chosenScheduleClientInterceptors,
otTracer,
clientCustomizer,
scheduleCustomizer)
Expand All @@ -93,7 +112,8 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
}

options.setWorkerFactoryOptions(
new WorkerFactoryOptionsTemplate(properties, otTracer, workerFactoryCustomizer)
new WorkerFactoryOptionsTemplate(
properties, chosenWorkerInterceptors, otTracer, workerFactoryCustomizer)
.createWorkerFactoryOptions());

if (testEnvOptionsCustomizer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import io.temporal.client.schedules.ScheduleClient;
import io.temporal.client.schedules.ScheduleClientOptions;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptor;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.spring.boot.TemporalOptionsCustomizer;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

Expand All @@ -24,14 +27,22 @@ public class ClientTemplate {
public ClientTemplate(
@Nonnull String namespace,
@Nullable DataConverter dataConverter,
@Nullable List<WorkflowClientInterceptor> workflowClientInterceptors,
@Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors,
@Nullable Tracer tracer,
@Nullable WorkflowServiceStubs workflowServiceStubs,
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
@Nullable TemporalOptionsCustomizer<WorkflowClientOptions.Builder> clientCustomizer,
@Nullable TemporalOptionsCustomizer<ScheduleClientOptions.Builder> scheduleCustomer) {
this.optionsTemplate =
new WorkflowClientOptionsTemplate(
namespace, dataConverter, tracer, clientCustomizer, scheduleCustomer);
namespace,
dataConverter,
workflowClientInterceptors,
scheduleClientInterceptors,
tracer,
clientCustomizer,
scheduleCustomer);
this.workflowServiceStubs = workflowServiceStubs;
this.testWorkflowEnvironment = testWorkflowEnvironment;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
import io.temporal.client.WorkflowClientOptions;
import io.temporal.client.schedules.ScheduleClientOptions;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.common.interceptors.WorkerInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptor;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.spring.boot.TemporalOptionsCustomizer;
import io.temporal.spring.boot.autoconfigure.properties.NamespaceProperties;
import io.temporal.worker.WorkerFactoryOptions;
import io.temporal.worker.WorkerOptions;
import io.temporal.worker.WorkflowImplementationOptions;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class NamespaceTemplate {
private final @Nonnull NamespaceProperties namespaceProperties;
private final @Nonnull WorkflowServiceStubs workflowServiceStubs;
private final @Nullable DataConverter dataConverter;
private final @Nullable List<WorkflowClientInterceptor> workflowClientInterceptors;
private final @Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors;
private final @Nullable List<WorkerInterceptor> workerInterceptors;
private final @Nullable Tracer tracer;
private final @Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment;

Expand All @@ -36,6 +43,9 @@ public NamespaceTemplate(
@Nonnull NamespaceProperties namespaceProperties,
@Nonnull WorkflowServiceStubs workflowServiceStubs,
@Nullable DataConverter dataConverter,
@Nullable List<WorkflowClientInterceptor> workflowClientInterceptors,
@Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors,
@Nullable List<WorkerInterceptor> workerInterceptors,
@Nullable Tracer tracer,
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
@Nullable TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer,
Expand All @@ -48,6 +58,9 @@ public NamespaceTemplate(
this.namespaceProperties = namespaceProperties;
this.workflowServiceStubs = workflowServiceStubs;
this.dataConverter = dataConverter;
this.workflowClientInterceptors = workflowClientInterceptors;
this.scheduleClientInterceptors = scheduleClientInterceptors;
this.workerInterceptors = workerInterceptors;
this.tracer = tracer;
this.testWorkflowEnvironment = testWorkflowEnvironment;

Expand All @@ -64,6 +77,8 @@ public ClientTemplate getClientTemplate() {
new ClientTemplate(
namespaceProperties.getNamespace(),
dataConverter,
workflowClientInterceptors,
scheduleClientInterceptors,
tracer,
workflowServiceStubs,
testWorkflowEnvironment,
Expand All @@ -79,6 +94,7 @@ public WorkersTemplate getWorkersTemplate() {
new WorkersTemplate(
namespaceProperties,
getClientTemplate(),
workerInterceptors,
tracer,
testWorkflowEnvironment,
workerFactoryCustomizer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import io.temporal.client.WorkflowClientOptions;
import io.temporal.client.schedules.ScheduleClientOptions;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.common.interceptors.WorkerInterceptor;
import io.temporal.common.interceptors.WorkflowClientInterceptor;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.spring.boot.TemporalOptionsCustomizer;
import io.temporal.spring.boot.autoconfigure.properties.NonRootNamespaceProperties;
import io.temporal.worker.WorkerFactoryOptions;
import io.temporal.worker.WorkerOptions;
import io.temporal.worker.WorkflowImplementationOptions;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.springframework.beans.factory.BeanFactory;
Expand All @@ -24,6 +28,9 @@ public NonRootNamespaceTemplate(
@Nonnull NonRootNamespaceProperties namespaceProperties,
@Nonnull WorkflowServiceStubs workflowServiceStubs,
@Nullable DataConverter dataConverter,
@Nullable List<WorkflowClientInterceptor> workflowClientInterceptors,
@Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors,
@Nullable List<WorkerInterceptor> workerInterceptors,
@Nullable Tracer tracer,
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
@Nullable TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer,
Expand All @@ -37,6 +44,9 @@ public NonRootNamespaceTemplate(
namespaceProperties,
workflowServiceStubs,
dataConverter,
workflowClientInterceptors,
scheduleClientInterceptors,
workerInterceptors,
tracer,
testWorkflowEnvironment,
workerFactoryCustomizer,
Expand Down
Loading
Loading