Skip to content

Commit 027565d

Browse files
Add interceptor beans
1 parent 537d99d commit 027565d

12 files changed

Lines changed: 247 additions & 12 deletions

File tree

temporal-spring-boot-autoconfigure/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ Task Queue names directly for simplicity.
182182

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

185+
## Interceptors
186+
187+
To enable interceptors create beans implementing the `io.temporal.common.interceptors.WorkflowClientInterceptor` interface or `io.temporal.common.interceptors.WorkerInterceptor` interface.
188+
Interceptors will be registered in the order specified by the `@Order` annotation.
189+
185190
## Customization of `*Options`
186191

187192
To provide freedom in customization of `*Options` instances that are created by this module,
@@ -283,7 +288,7 @@ spring.temporal:
283288
## Customization
284289

285290
All customization points for the root namespace also exist for the non-root namespaces. To specify for a particular
286-
namespace users just need to append the alias/namespace to the bean.
291+
namespace users just need to append the alias/namespace to the bean. Currently interceptors are not supported.
287292

288293
```java
289294
// TemporalOptionsCustomizer type beans must start with the namespace/alias you defined and end with function class

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/AutoConfigurationUtils.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
import com.google.common.base.MoreObjects;
2424
import io.temporal.common.converter.DataConverter;
25+
import io.temporal.common.interceptors.ScheduleClientInterceptor;
26+
import io.temporal.common.interceptors.WorkerInterceptor;
27+
import io.temporal.common.interceptors.WorkflowClientInterceptor;
2528
import io.temporal.spring.boot.TemporalOptionsCustomizer;
2629
import io.temporal.spring.boot.autoconfigure.properties.NonRootNamespaceProperties;
2730
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
@@ -37,7 +40,7 @@
3740
class AutoConfigurationUtils {
3841

3942
@Nullable
40-
static DataConverter choseDataConverter(
43+
static DataConverter chooseDataConverter(
4144
List<DataConverter> dataConverters, DataConverter mainDataConverter) {
4245
DataConverter chosenDataConverter = null;
4346
if (dataConverters.size() == 1) {
@@ -58,7 +61,7 @@ static DataConverter choseDataConverter(
5861
}
5962

6063
@Nullable
61-
static DataConverter choseDataConverter(
64+
static DataConverter chooseDataConverter(
6265
Map<String, DataConverter> dataConverters,
6366
DataConverter mainDataConverter,
6467
TemporalProperties properties) {
@@ -67,7 +70,7 @@ static DataConverter choseDataConverter(
6770
}
6871
List<NonRootNamespaceProperties> nonRootNamespaceProperties = properties.getNamespaces();
6972
if (Objects.isNull(nonRootNamespaceProperties) || nonRootNamespaceProperties.isEmpty()) {
70-
return choseDataConverter(new ArrayList<>(dataConverters.values()), mainDataConverter);
73+
return chooseDataConverter(new ArrayList<>(dataConverters.values()), mainDataConverter);
7174
} else {
7275
List<DataConverter> dataConverterList = new ArrayList<>();
7376
List<String> nonRootBeanNames =
@@ -89,10 +92,28 @@ static DataConverter choseDataConverter(
8992
}
9093
dataConverterList.add(dataConverter);
9194
}
92-
return choseDataConverter(dataConverterList, mainDataConverter);
95+
return chooseDataConverter(dataConverterList, mainDataConverter);
9396
}
9497
}
9598

99+
@Nullable
100+
static List<WorkflowClientInterceptor> chooseWorkflowClientInterceptors(
101+
List<WorkflowClientInterceptor> workflowClientInterceptors, TemporalProperties properties) {
102+
return workflowClientInterceptors;
103+
}
104+
105+
@Nullable
106+
static List<ScheduleClientInterceptor> chooseScheduleClientInterceptors(
107+
List<ScheduleClientInterceptor> scheduleClientInterceptor, TemporalProperties properties) {
108+
return scheduleClientInterceptor;
109+
}
110+
111+
@Nullable
112+
static List<WorkerInterceptor> chooseWorkerInterceptors(
113+
List<WorkerInterceptor> workerInterceptor, TemporalProperties properties) {
114+
return workerInterceptor;
115+
}
116+
96117
static <T> TemporalOptionsCustomizer<T> chooseTemporalCustomizerBean(
97118
Map<String, TemporalOptionsCustomizer<T>> customizerMap,
98119
Class<T> genericOptionsBuilderClass,

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ private void injectBeanByNonRootNamespace(NonRootNamespaceProperties ns) {
129129
ns,
130130
workflowServiceStubs,
131131
dataConverterByNamespace,
132+
null, // Currently interceptors are not supported in non-root namespace
133+
null,
134+
null,
132135
tracer,
133136
testWorkflowEnvironment,
134137
workFactoryCustomizer,

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/RootNamespaceAutoConfiguration.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import io.temporal.client.schedules.ScheduleClient;
2727
import io.temporal.client.schedules.ScheduleClientOptions;
2828
import io.temporal.common.converter.DataConverter;
29+
import io.temporal.common.interceptors.ScheduleClientInterceptor;
30+
import io.temporal.common.interceptors.WorkerInterceptor;
31+
import io.temporal.common.interceptors.WorkflowClientInterceptor;
2932
import io.temporal.serviceclient.WorkflowServiceStubs;
3033
import io.temporal.spring.boot.TemporalOptionsCustomizer;
3134
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
@@ -39,6 +42,7 @@
3942
import io.temporal.worker.WorkerOptions;
4043
import io.temporal.worker.WorkflowImplementationOptions;
4144
import java.util.Collection;
45+
import java.util.List;
4246
import java.util.Map;
4347
import javax.annotation.Nonnull;
4448
import javax.annotation.Nullable;
@@ -84,6 +88,11 @@ public NamespaceTemplate rootNamespaceTemplate(
8488
@Qualifier("mainDataConverter") @Autowired(required = false) @Nullable
8589
DataConverter mainDataConverter,
8690
@Autowired(required = false) @Nullable Tracer otTracer,
91+
@Autowired(required = false) @Nullable
92+
List<WorkflowClientInterceptor> workflowClientInterceptors,
93+
@Autowired(required = false) @Nullable
94+
List<ScheduleClientInterceptor> scheduleClientInterceptors,
95+
@Autowired(required = false) @Nullable List<WorkerInterceptor> workerInterceptors,
8796
@Qualifier("temporalTestWorkflowEnvironmentAdapter") @Autowired(required = false) @Nullable
8897
TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
8998
@Autowired(required = false) @Nullable
@@ -100,7 +109,15 @@ public NamespaceTemplate rootNamespaceTemplate(
100109
Map<String, TemporalOptionsCustomizer<WorkflowImplementationOptions.Builder>>
101110
workflowImplementationCustomizerMap) {
102111
DataConverter chosenDataConverter =
103-
AutoConfigurationUtils.choseDataConverter(dataConverters, mainDataConverter, properties);
112+
AutoConfigurationUtils.chooseDataConverter(dataConverters, mainDataConverter, properties);
113+
List<WorkflowClientInterceptor> chosenClientInterceptors =
114+
AutoConfigurationUtils.chooseWorkflowClientInterceptors(
115+
workflowClientInterceptors, properties);
116+
List<ScheduleClientInterceptor> chosenScheduleClientInterceptors =
117+
AutoConfigurationUtils.chooseScheduleClientInterceptors(
118+
scheduleClientInterceptors, properties);
119+
List<WorkerInterceptor> chosenWorkerInterceptors =
120+
AutoConfigurationUtils.chooseWorkerInterceptors(workerInterceptors, properties);
104121
TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer =
105122
AutoConfigurationUtils.chooseTemporalCustomizerBean(
106123
workerFactoryCustomizerMap, WorkerFactoryOptions.Builder.class, properties);
@@ -124,6 +141,9 @@ public NamespaceTemplate rootNamespaceTemplate(
124141
properties,
125142
workflowServiceStubs,
126143
chosenDataConverter,
144+
chosenClientInterceptors,
145+
chosenScheduleClientInterceptors,
146+
chosenWorkerInterceptors,
127147
otTracer,
128148
testWorkflowEnvironment,
129149
workerFactoryCustomizer,

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/TestServerAutoConfiguration.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import io.temporal.client.WorkflowClientOptions;
2626
import io.temporal.client.schedules.ScheduleClientOptions;
2727
import io.temporal.common.converter.DataConverter;
28+
import io.temporal.common.interceptors.ScheduleClientInterceptor;
29+
import io.temporal.common.interceptors.WorkerInterceptor;
30+
import io.temporal.common.interceptors.WorkflowClientInterceptor;
2831
import io.temporal.spring.boot.TemporalOptionsCustomizer;
2932
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties;
3033
import io.temporal.spring.boot.autoconfigure.template.TestWorkflowEnvironmentAdapter;
@@ -33,6 +36,7 @@
3336
import io.temporal.testing.TestEnvironmentOptions;
3437
import io.temporal.testing.TestWorkflowEnvironment;
3538
import io.temporal.worker.WorkerFactoryOptions;
39+
import java.util.List;
3640
import java.util.Map;
3741
import javax.annotation.Nullable;
3842
import org.slf4j.Logger;
@@ -74,6 +78,11 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
7478
@Qualifier("mainDataConverter") @Autowired(required = false) @Nullable
7579
DataConverter mainDataConverter,
7680
@Autowired(required = false) @Nullable Tracer otTracer,
81+
@Autowired(required = false) @Nullable
82+
List<WorkflowClientInterceptor> workflowClientInterceptors,
83+
@Autowired(required = false) @Nullable
84+
List<ScheduleClientInterceptor> scheduleClientInterceptors,
85+
@Autowired(required = false) @Nullable List<WorkerInterceptor> workerInterceptors,
7786
@Autowired(required = false) @Nullable
7887
TemporalOptionsCustomizer<TestEnvironmentOptions.Builder> testEnvOptionsCustomizer,
7988
@Autowired(required = false) @Nullable
@@ -85,7 +94,15 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
8594
Map<String, TemporalOptionsCustomizer<ScheduleClientOptions.Builder>>
8695
scheduleCustomizerMap) {
8796
DataConverter chosenDataConverter =
88-
AutoConfigurationUtils.choseDataConverter(dataConverters, mainDataConverter, properties);
97+
AutoConfigurationUtils.chooseDataConverter(dataConverters, mainDataConverter, properties);
98+
List<WorkflowClientInterceptor> chosenClientInterceptors =
99+
AutoConfigurationUtils.chooseWorkflowClientInterceptors(
100+
workflowClientInterceptors, properties);
101+
List<ScheduleClientInterceptor> chosenScheduleClientInterceptors =
102+
AutoConfigurationUtils.chooseScheduleClientInterceptors(
103+
scheduleClientInterceptors, properties);
104+
List<WorkerInterceptor> chosenWorkerInterceptors =
105+
AutoConfigurationUtils.chooseWorkerInterceptors(workerInterceptors, properties);
89106

90107
TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer =
91108
AutoConfigurationUtils.chooseTemporalCustomizerBean(
@@ -103,6 +120,8 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
103120
new WorkflowClientOptionsTemplate(
104121
properties.getNamespace(),
105122
chosenDataConverter,
123+
chosenClientInterceptors,
124+
chosenScheduleClientInterceptors,
106125
otTracer,
107126
clientCustomizer,
108127
scheduleCustomizer)
@@ -113,7 +132,8 @@ public TestWorkflowEnvironment testWorkflowEnvironment(
113132
}
114133

115134
options.setWorkerFactoryOptions(
116-
new WorkerFactoryOptionsTemplate(properties, otTracer, workerFactoryCustomizer)
135+
new WorkerFactoryOptionsTemplate(
136+
properties, chosenWorkerInterceptors, otTracer, workerFactoryCustomizer)
117137
.createWorkerFactoryOptions());
118138

119139
if (testEnvOptionsCustomizer != null) {

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/template/ClientTemplate.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
import io.temporal.client.schedules.ScheduleClient;
2828
import io.temporal.client.schedules.ScheduleClientOptions;
2929
import io.temporal.common.converter.DataConverter;
30+
import io.temporal.common.interceptors.ScheduleClientInterceptor;
31+
import io.temporal.common.interceptors.WorkflowClientInterceptor;
3032
import io.temporal.serviceclient.WorkflowServiceStubs;
3133
import io.temporal.spring.boot.TemporalOptionsCustomizer;
34+
import java.util.List;
3235
import javax.annotation.Nonnull;
3336
import javax.annotation.Nullable;
3437

@@ -44,14 +47,22 @@ public class ClientTemplate {
4447
public ClientTemplate(
4548
@Nonnull String namespace,
4649
@Nullable DataConverter dataConverter,
50+
@Nullable List<WorkflowClientInterceptor> workflowClientInterceptors,
51+
@Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors,
4752
@Nullable Tracer tracer,
4853
@Nullable WorkflowServiceStubs workflowServiceStubs,
4954
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
5055
@Nullable TemporalOptionsCustomizer<WorkflowClientOptions.Builder> clientCustomizer,
5156
@Nullable TemporalOptionsCustomizer<ScheduleClientOptions.Builder> scheduleCustomer) {
5257
this.optionsTemplate =
5358
new WorkflowClientOptionsTemplate(
54-
namespace, dataConverter, tracer, clientCustomizer, scheduleCustomer);
59+
namespace,
60+
dataConverter,
61+
workflowClientInterceptors,
62+
scheduleClientInterceptors,
63+
tracer,
64+
clientCustomizer,
65+
scheduleCustomer);
5566
this.workflowServiceStubs = workflowServiceStubs;
5667
this.testWorkflowEnvironment = testWorkflowEnvironment;
5768
}

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/template/NamespaceTemplate.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,26 @@
2424
import io.temporal.client.WorkflowClientOptions;
2525
import io.temporal.client.schedules.ScheduleClientOptions;
2626
import io.temporal.common.converter.DataConverter;
27+
import io.temporal.common.interceptors.ScheduleClientInterceptor;
28+
import io.temporal.common.interceptors.WorkerInterceptor;
29+
import io.temporal.common.interceptors.WorkflowClientInterceptor;
2730
import io.temporal.serviceclient.WorkflowServiceStubs;
2831
import io.temporal.spring.boot.TemporalOptionsCustomizer;
2932
import io.temporal.spring.boot.autoconfigure.properties.NamespaceProperties;
3033
import io.temporal.worker.WorkerFactoryOptions;
3134
import io.temporal.worker.WorkerOptions;
3235
import io.temporal.worker.WorkflowImplementationOptions;
36+
import java.util.List;
3337
import javax.annotation.Nonnull;
3438
import javax.annotation.Nullable;
3539

3640
public class NamespaceTemplate {
3741
private final @Nonnull NamespaceProperties namespaceProperties;
3842
private final @Nonnull WorkflowServiceStubs workflowServiceStubs;
3943
private final @Nullable DataConverter dataConverter;
44+
private final @Nullable List<WorkflowClientInterceptor> workflowClientInterceptors;
45+
private final @Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors;
46+
private final @Nullable List<WorkerInterceptor> workerInterceptors;
4047
private final @Nullable Tracer tracer;
4148
private final @Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment;
4249

@@ -56,6 +63,9 @@ public NamespaceTemplate(
5663
@Nonnull NamespaceProperties namespaceProperties,
5764
@Nonnull WorkflowServiceStubs workflowServiceStubs,
5865
@Nullable DataConverter dataConverter,
66+
@Nullable List<WorkflowClientInterceptor> workflowClientInterceptors,
67+
@Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors,
68+
@Nullable List<WorkerInterceptor> workerInterceptors,
5969
@Nullable Tracer tracer,
6070
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
6171
@Nullable TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer,
@@ -68,6 +78,9 @@ public NamespaceTemplate(
6878
this.namespaceProperties = namespaceProperties;
6979
this.workflowServiceStubs = workflowServiceStubs;
7080
this.dataConverter = dataConverter;
81+
this.workflowClientInterceptors = workflowClientInterceptors;
82+
this.scheduleClientInterceptors = scheduleClientInterceptors;
83+
this.workerInterceptors = workerInterceptors;
7184
this.tracer = tracer;
7285
this.testWorkflowEnvironment = testWorkflowEnvironment;
7386

@@ -84,6 +97,8 @@ public ClientTemplate getClientTemplate() {
8497
new ClientTemplate(
8598
namespaceProperties.getNamespace(),
8699
dataConverter,
100+
workflowClientInterceptors,
101+
scheduleClientInterceptors,
87102
tracer,
88103
workflowServiceStubs,
89104
testWorkflowEnvironment,
@@ -99,6 +114,7 @@ public WorkersTemplate getWorkersTemplate() {
99114
new WorkersTemplate(
100115
namespaceProperties,
101116
getClientTemplate(),
117+
workerInterceptors,
102118
tracer,
103119
testWorkflowEnvironment,
104120
workerFactoryCustomizer,

temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/template/NonRootNamespaceTemplate.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
import io.temporal.client.WorkflowClientOptions;
2525
import io.temporal.client.schedules.ScheduleClientOptions;
2626
import io.temporal.common.converter.DataConverter;
27+
import io.temporal.common.interceptors.ScheduleClientInterceptor;
28+
import io.temporal.common.interceptors.WorkerInterceptor;
29+
import io.temporal.common.interceptors.WorkflowClientInterceptor;
2730
import io.temporal.serviceclient.WorkflowServiceStubs;
2831
import io.temporal.spring.boot.TemporalOptionsCustomizer;
2932
import io.temporal.spring.boot.autoconfigure.properties.NonRootNamespaceProperties;
3033
import io.temporal.worker.WorkerFactoryOptions;
3134
import io.temporal.worker.WorkerOptions;
3235
import io.temporal.worker.WorkflowImplementationOptions;
36+
import java.util.List;
3337
import javax.annotation.Nonnull;
3438
import javax.annotation.Nullable;
3539
import org.springframework.beans.factory.BeanFactory;
@@ -44,6 +48,9 @@ public NonRootNamespaceTemplate(
4448
@Nonnull NonRootNamespaceProperties namespaceProperties,
4549
@Nonnull WorkflowServiceStubs workflowServiceStubs,
4650
@Nullable DataConverter dataConverter,
51+
@Nullable List<WorkflowClientInterceptor> workflowClientInterceptors,
52+
@Nullable List<ScheduleClientInterceptor> scheduleClientInterceptors,
53+
@Nullable List<WorkerInterceptor> workerInterceptors,
4754
@Nullable Tracer tracer,
4855
@Nullable TestWorkflowEnvironmentAdapter testWorkflowEnvironment,
4956
@Nullable TemporalOptionsCustomizer<WorkerFactoryOptions.Builder> workerFactoryCustomizer,
@@ -57,6 +64,9 @@ public NonRootNamespaceTemplate(
5764
namespaceProperties,
5865
workflowServiceStubs,
5966
dataConverter,
67+
workflowClientInterceptors,
68+
scheduleClientInterceptors,
69+
workerInterceptors,
6070
tracer,
6171
testWorkflowEnvironment,
6272
workerFactoryCustomizer,

0 commit comments

Comments
 (0)