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
74 changes: 74 additions & 0 deletions sdk-spring-boot-starter/build.gradle.kts
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") }
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 {}
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);
}
}
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;
}
}
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 {}
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;
}
}
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;
}
}
Loading
Loading