-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Spring Boot starter (#393)
- Loading branch information
1 parent
0f20059
commit b881b04
Showing
12 changed files
with
512 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
plugins { | ||
`java-conventions` | ||
`java-library` | ||
`test-jar-conventions` | ||
`library-publishing-conventions` | ||
id("io.spring.dependency-management") version "1.1.6" | ||
} | ||
|
||
description = "Restate SDK Spring Boot starter" | ||
|
||
val springBootVersion = "3.3.5" | ||
|
||
java { toolchain { languageVersion = JavaLanguageVersion.of(17) } } | ||
|
||
dependencies { | ||
compileOnly(coreLibs.jspecify) | ||
|
||
api(project(":sdk-common")) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
api(project(":sdk-api")) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
api(project(":sdk-serde-jackson")) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
|
||
implementation(project(":sdk-http-vertx")) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
implementation(project(":sdk-request-identity")) | ||
implementation(platform(vertxLibs.vertx.bom)) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
implementation(vertxLibs.vertx.core) { | ||
// Let spring bring jackson in | ||
exclude(group = "com.fasterxml.jackson") | ||
exclude(group = "com.fasterxml.jackson.core") | ||
exclude(group = "com.fasterxml.jackson.datatype") | ||
} | ||
|
||
implementation("org.springframework.boot:spring-boot-starter:$springBootVersion") | ||
|
||
// Spring is going to bring jackson in with this | ||
implementation("org.springframework.boot:spring-boot-starter-json:$springBootVersion") | ||
|
||
// We need these for the deployment manifest | ||
testImplementation(project(":sdk-core")) | ||
testImplementation(platform(jacksonLibs.jackson.bom)) | ||
testImplementation(jacksonLibs.jackson.annotations) | ||
testImplementation(jacksonLibs.jackson.databind) | ||
|
||
testAnnotationProcessor(project(":sdk-api-gen")) | ||
testImplementation(project(":sdk-serde-jackson")) | ||
|
||
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion") | ||
} | ||
|
||
tasks.withType<JavaCompile> { options.compilerArgs.add("-parameters") } |
26 changes: 26 additions & 0 deletions
26
sdk-spring-boot-starter/src/main/java/dev/restate/sdk/springboot/EnableRestate.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,26 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot; | ||
|
||
import java.lang.annotation.*; | ||
import org.springframework.context.annotation.Import; | ||
|
||
/** | ||
* Add this annotation in your application class next to the {@link | ||
* org.springframework.boot.autoconfigure.SpringBootApplication} annotation to enable the Restate | ||
* Spring features. | ||
* | ||
* @see RestateComponent | ||
* @see RestateClientAutoConfiguration | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Import({RestateHttpEndpointBean.class, RestateClientAutoConfiguration.class}) | ||
public @interface EnableRestate {} |
35 changes: 35 additions & 0 deletions
35
...boot-starter/src/main/java/dev/restate/sdk/springboot/RestateClientAutoConfiguration.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,35 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot; | ||
|
||
import dev.restate.sdk.client.Client; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Configuration for Restate's {@link Client}, to send requests to Restate services. | ||
* | ||
* @see RestateClientProperties | ||
*/ | ||
@Configuration | ||
@EnableConfigurationProperties(RestateClientProperties.class) | ||
public class RestateClientAutoConfiguration { | ||
|
||
@Bean | ||
public Client client(RestateClientProperties restateClientProperties) { | ||
Map<String, String> headers = restateClientProperties.getHeaders(); | ||
if (headers == null) { | ||
headers = Collections.emptyMap(); | ||
} | ||
return Client.connect(restateClientProperties.getBaseUri(), headers); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...spring-boot-starter/src/main/java/dev/restate/sdk/springboot/RestateClientProperties.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,38 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot; | ||
|
||
import java.util.Map; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
import org.springframework.boot.context.properties.bind.DefaultValue; | ||
|
||
@ConfigurationProperties(prefix = "restate.client") | ||
public class RestateClientProperties { | ||
|
||
private final String baseUri; | ||
private final Map<String, String> headers; | ||
|
||
@ConstructorBinding | ||
public RestateClientProperties( | ||
@DefaultValue(value = "http://localhost:8080") String baseUri, Map<String, String> headers) { | ||
this.baseUri = baseUri; | ||
this.headers = headers; | ||
} | ||
|
||
/** Base uri of the Restate client, e.g. {@code http://localhost:8080}. */ | ||
public String getBaseUri() { | ||
return baseUri; | ||
} | ||
|
||
/** Headers added to each request sent to Restate. */ | ||
public Map<String, String> getHeaders() { | ||
return headers; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
sdk-spring-boot-starter/src/main/java/dev/restate/sdk/springboot/RestateComponent.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,26 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot; | ||
|
||
import java.lang.annotation.*; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Add this annotation to a class annotated with Restate's {@link | ||
* dev.restate.sdk.annotation.Service} or {@link dev.restate.sdk.annotation.VirtualObject} or {@link | ||
* dev.restate.sdk.annotation.Workflow} to bind them to the Restate HTTP Endpoint. | ||
* | ||
* <p>You can configure the Restate HTTP Endpoint using {@link RestateEndpointProperties} and {@link | ||
* RestateEndpointHttpServerProperties}. | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Component | ||
public @interface RestateComponent {} |
30 changes: 30 additions & 0 deletions
30
...starter/src/main/java/dev/restate/sdk/springboot/RestateEndpointHttpServerProperties.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,30 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
import org.springframework.boot.context.properties.bind.DefaultValue; | ||
import org.springframework.boot.context.properties.bind.Name; | ||
|
||
@ConfigurationProperties(prefix = "restate.sdk.http") | ||
public class RestateEndpointHttpServerProperties { | ||
|
||
private final int port; | ||
|
||
@ConstructorBinding | ||
public RestateEndpointHttpServerProperties(@Name("port") @DefaultValue(value = "9080") int port) { | ||
this.port = port; | ||
} | ||
|
||
/** Port to expose the HTTP server. */ | ||
public int getPort() { | ||
return port; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...ring-boot-starter/src/main/java/dev/restate/sdk/springboot/RestateEndpointProperties.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,43 @@ | ||
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
// | ||
// This file is part of the Restate Java SDK, | ||
// which is released under the MIT license. | ||
// | ||
// You can find a copy of the license in file LICENSE in the root | ||
// directory of this repository or package, or at | ||
// https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
package dev.restate.sdk.springboot; | ||
|
||
import dev.restate.sdk.auth.RequestIdentityVerifier; | ||
import dev.restate.sdk.http.vertx.RestateHttpEndpointBuilder; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.bind.ConstructorBinding; | ||
import org.springframework.boot.context.properties.bind.DefaultValue; | ||
|
||
@ConfigurationProperties(prefix = "restate.sdk") | ||
public class RestateEndpointProperties { | ||
|
||
private final boolean enablePreviewContext; | ||
private final String identityKey; | ||
|
||
@ConstructorBinding | ||
public RestateEndpointProperties( | ||
@DefaultValue(value = "false") boolean enablePreviewContext, String identityKey) { | ||
this.enablePreviewContext = enablePreviewContext; | ||
this.identityKey = identityKey; | ||
} | ||
|
||
/** | ||
* @see RestateHttpEndpointBuilder#enablePreviewContext() | ||
*/ | ||
public boolean isEnablePreviewContext() { | ||
return enablePreviewContext; | ||
} | ||
|
||
/** | ||
* @see RestateHttpEndpointBuilder#withRequestIdentityVerifier(RequestIdentityVerifier) | ||
*/ | ||
public String getIdentityKey() { | ||
return identityKey; | ||
} | ||
} |
Oops, something went wrong.