-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial Spring Boot implementation #1305
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ target | |
.gradle | ||
/build | ||
/*/build | ||
/out | ||
**/out | ||
/lib | ||
dummy | ||
$buildDir | ||
|
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") | ||
} | ||
} |
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(); | ||
} |
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(); | ||
} |
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume configure for other options can come later? E.g. can I "inject" (or whatever spring calls it these days) an interceptor or data converter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "More configuration and deep integration with Spring DI will be coming in subsequent PRs for the Spring Boot story." The purpose of this PR is to provide a correct structure that will initialize things in the correct order and with reasonable logic. You can't configure almost anything not absolutely essential here yet. |
||
|
||
if (clientProperties.getNamespace() != null) { | ||
clientOptionsBuilder.setNamespace(clientProperties.getNamespace()); | ||
} | ||
|
||
return WorkflowClient.newInstance( | ||
workflowServiceStubs, clientOptionsBuilder.validateAndBuildWithDefaults()); | ||
} | ||
} |
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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between this and me explicitly providing
localhost:7233
? Can the const just be that and we don't have acase
for it? Or is it that important to reuse the stub instance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is none, but we have WorkflowServerStub.newLocalStubs, so I think it would be right to mirror it here.
The main argument for this is that it's much friendlier for new users to don't even worry about which port Temporal occupies by default.