-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial Spring Boot implementation
- Loading branch information
1 parent
abb3cb1
commit a03a78e
Showing
33 changed files
with
1,381 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ target | |
.gradle | ||
/build | ||
/*/build | ||
/out | ||
**/out | ||
/lib | ||
dummy | ||
$buildDir | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
description = '''Spring Boot AutoConfigure for Temporal Java SDK''' | ||
|
||
dependencies { | ||
api(platform("org.springframework.boot:spring-boot-dependencies:$springBootVersion")) | ||
|
||
api project(':temporal-sdk') | ||
compileOnly project(':temporal-testing') | ||
|
||
implementation "org.springframework.boot:spring-boot" | ||
implementation "org.springframework.boot:spring-boot-autoconfigure" | ||
|
||
// this dependency is not mandatory for the module to work, but it provides a better IDE experience developing the module | ||
// it's needed to auto-generate configuration metadata. See for more details: | ||
// https://docs.spring.io/spring-boot/docs/2.4.0/reference/html/appendix-configuration-metadata.html#configuration-metadata-annotation-processor | ||
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:$springBootVersion" | ||
|
||
testImplementation project(':temporal-testing') | ||
|
||
testImplementation "org.mockito:mockito-core:${mockitoVersion}" | ||
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: "${logbackVersion}" | ||
|
||
testImplementation "org.springframework.boot:spring-boot-starter-test" | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
testLogging { | ||
events("passed", "skipped", "failed") | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...l-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/ActivityImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.spring.boot; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface ActivityImpl { | ||
String[] taskQueues(); | ||
} |
32 changes: 32 additions & 0 deletions
32
...l-spring-boot-autoconfigure-alpha/src/main/java/io/temporal/spring/boot/WorkflowImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.spring.boot; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface WorkflowImpl { | ||
String[] taskQueues(); | ||
} |
90 changes: 90 additions & 0 deletions
90
...re-alpha/src/main/java/io/temporal/spring/boot/autoconfigure/ClientAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.spring.boot.autoconfigure; | ||
|
||
import io.temporal.client.WorkflowClient; | ||
import io.temporal.client.WorkflowClientOptions; | ||
import io.temporal.serviceclient.WorkflowServiceStubs; | ||
import io.temporal.serviceclient.WorkflowServiceStubsOptions; | ||
import io.temporal.spring.boot.autoconfigure.properties.ClientProperties; | ||
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties; | ||
import io.temporal.testing.TestWorkflowEnvironment; | ||
import javax.annotation.Nullable; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.support.BeanDefinitionValidationException; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** Provides a client based on `spring.temporal.client` section */ | ||
@Configuration | ||
@EnableConfigurationProperties(TemporalProperties.class) | ||
@ConditionalOnClass(name = "io.temporal.client.WorkflowClient") | ||
@ConditionalOnProperty(prefix = "spring.temporal", name = "client.target") | ||
public class ClientAutoConfiguration { | ||
|
||
@Bean(name = "temporalWorkflowClient") | ||
@ConditionalOnMissingBean(name = "temporalWorkflowClient") | ||
public WorkflowClient client( | ||
TemporalProperties temporalProperties, | ||
@Qualifier("temporalTestWorkflowEnvironment") @Autowired(required = false) @Nullable | ||
TestWorkflowEnvironment testWorkflowEnvironment) { | ||
ClientProperties clientProperties = temporalProperties.getClient(); | ||
WorkflowServiceStubs workflowServiceStubs; | ||
switch (temporalProperties.getClient().getTarget().toLowerCase()) { | ||
case ClientProperties.TARGET_IN_PROCESS_TEST_SERVER: | ||
if (testWorkflowEnvironment == null) { | ||
throw new BeanDefinitionValidationException( | ||
"Test workflow environment is not available. " | ||
+ "Please make sure that you have enabled the 'temporal-test' module " | ||
+ "and configured `spring.temporal.testServer.enabled: true`."); | ||
} | ||
return testWorkflowEnvironment.getWorkflowClient(); | ||
case ClientProperties.TARGET_LOCAL_SERVICE: | ||
workflowServiceStubs = WorkflowServiceStubs.newLocalServiceStubs(); | ||
break; | ||
default: | ||
WorkflowServiceStubsOptions.Builder stubsOptionsBuilder = | ||
WorkflowServiceStubsOptions.newBuilder(); | ||
|
||
if (clientProperties.getTarget() != null) { | ||
stubsOptionsBuilder.setTarget(clientProperties.getTarget()); | ||
} | ||
|
||
workflowServiceStubs = | ||
WorkflowServiceStubs.newServiceStubs( | ||
stubsOptionsBuilder.validateAndBuildWithDefaults()); | ||
} | ||
|
||
WorkflowClientOptions.Builder clientOptionsBuilder = WorkflowClientOptions.newBuilder(); | ||
|
||
if (clientProperties.getNamespace() != null) { | ||
clientOptionsBuilder.setNamespace(clientProperties.getNamespace()); | ||
} | ||
|
||
return WorkflowClient.newInstance( | ||
workflowServiceStubs, clientOptionsBuilder.validateAndBuildWithDefaults()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...lpha/src/main/java/io/temporal/spring/boot/autoconfigure/TestServerAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.spring.boot.autoconfigure; | ||
|
||
import io.temporal.spring.boot.autoconfigure.properties.TemporalProperties; | ||
import io.temporal.testing.TestWorkflowEnvironment; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** Provides a client based on `spring.temporal.testServer` section */ | ||
@Configuration | ||
@EnableConfigurationProperties(TemporalProperties.class) | ||
@ConditionalOnClass(name = "io.temporal.testing.TestWorkflowEnvironment") | ||
@ConditionalOnProperty( | ||
prefix = "spring.temporal", | ||
name = "testServer.enabled", | ||
havingValue = "true") | ||
public class TestServerAutoConfiguration { | ||
@Bean(name = "temporalTestWorkflowEnvironment", destroyMethod = "close") | ||
public TestWorkflowEnvironment testServer() { | ||
return TestWorkflowEnvironment.newInstance(); | ||
} | ||
} |
Oops, something went wrong.