Skip to content

Commit

Permalink
Assorted changes for new Java SDK (#213)
Browse files Browse the repository at this point in the history
* [maven spring boot] Use the new spring boot integration

* Bump Java SDK to 1.2.0

* [maven template] Add maven wrapper

* [maven template] Add example test + how to run command

* [gradle template] Add example test + how to run command

* [spring boot] Add test example

* Various dependency bumps

* JPA Spring boot example now uses the new spring boot integration
  • Loading branch information
slinkydeveloper authored Nov 20, 2024
1 parent c5d3c89 commit 28ded7c
Show file tree
Hide file tree
Showing 39 changed files with 682 additions and 116 deletions.
4 changes: 2 additions & 2 deletions basics/basics-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
annotationProcessor("dev.restate:sdk-api-gen:$restateVersion")
Expand All @@ -28,7 +28,7 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.1")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}

// Set main class
Expand Down
6 changes: 3 additions & 3 deletions basics/basics-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
// Annotation processor
Expand All @@ -22,10 +22,10 @@ dependencies {
implementation("dev.restate:sdk-http-vertx:$restateVersion")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.23.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")

// Kotlinx serialization (optional)
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}

// Setup Java/Kotlin compiler target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
// Restate SDK
Expand All @@ -31,7 +31,7 @@ dependencies {
implementation("org.apache.kafka:kafka-clients:3.6.1")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}

// Set main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
// Kafka
Expand All @@ -24,7 +24,7 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

repositories { mavenCentral() }

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
// Restate SDK
Expand All @@ -18,7 +18,7 @@ dependencies {
implementation("org.apache.kafka:kafka-clients:3.6.1")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.23.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}

// Set main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

repositories { mavenCentral() }

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
// Kafka
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "1.0.0"
val restateVersion = "1.1.0"

kotlin {
jvmToolchain(11)
jvmToolchain(17)
}

dependencies {
Expand All @@ -24,7 +24,7 @@ dependencies {
implementation("dev.restate:sdk-api-kotlin:$restateVersion")
implementation("dev.restate:sdk-http-vertx:$restateVersion")

implementation("org.apache.logging.log4j:log4j-core:2.23.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}

application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kotlin {

jvm()

jvmToolchain(11)
jvmToolchain(17)

sourceSets {
commonMain.dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
annotationProcessor("dev.restate:sdk-api-gen:$restateVersion")
Expand All @@ -31,7 +31,7 @@ dependencies {
implementation("com.google.code.gson:gson:2.10.1")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}

// Set main class
Expand Down
8 changes: 3 additions & 5 deletions patterns-use-cases/integrations/java-spring/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
group = "dev.restate.examples"
version = "0.0.1-SNAPSHOT"

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

java {
toolchain {
Expand All @@ -31,15 +31,13 @@ dependencies {
implementation("org.springframework.boot", "spring-boot-starter-data-jpa")

// Restate SDK
implementation("dev.restate:sdk-api:$restateVersion")
implementation("dev.restate:sdk-http-vertx:$restateVersion")
// To use Jackson to read/write state entries (optional)
implementation("dev.restate:sdk-spring-boot-starter:$restateVersion")
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

implementation("org.postgresql", "postgresql")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}

// Set main class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.restate.examples;

import dev.restate.sdk.springboot.EnableRestate;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableRestate
public class AppMain {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
import dev.restate.sdk.common.Serde;
import dev.restate.sdk.common.TerminalException;
import dev.restate.sdk.serde.jackson.JacksonSerdes;
import dev.restate.sdk.springboot.RestateVirtualObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@VirtualObject
@RestateVirtualObject
public class ProductService {

@Autowired private ProductRepository productRepository;
private static final Serde<Product> productSerde = JacksonSerdes.of(Product.class);

private Serde<Product> productSerde = JacksonSerdes.of(Product.class);
private final ProductRepository productRepository;

public ProductService(ProductRepository productRepository) {
this.productRepository = productRepository;
}

@Handler
public Product getProductInformation(ObjectContext ctx) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
annotationProcessor("dev.restate:sdk-api-gen:$restateVersion")
Expand Down
4 changes: 2 additions & 2 deletions patterns-use-cases/sagas/sagas-java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
annotationProcessor("dev.restate:sdk-api-gen:$restateVersion")
Expand All @@ -21,5 +21,5 @@ dependencies {
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
}
6 changes: 3 additions & 3 deletions patterns-use-cases/sagas/sagas-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
// Annotation processor
Expand All @@ -22,10 +22,10 @@ dependencies {
implementation("dev.restate:sdk-http-vertx:$restateVersion")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.23.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")

// Kotlinx serialization (optional)
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}

// Setup Java/Kotlin compiler target
Expand Down
6 changes: 6 additions & 0 deletions templates/java-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
Sample project configuration of a Restate service using the Java SDK and HTTP server.

Have a look at the [Java Quickstart guide](https://docs.restate.dev/get_started/quickstart?sdk=java) for more information on how to use this project.

To run:

```shell
./gradlew run
```
12 changes: 10 additions & 2 deletions templates/java-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
mavenCentral()
}

val restateVersion = "1.1.1"
val restateVersion = "1.2.0"

dependencies {
annotationProcessor("dev.restate:sdk-api-gen:$restateVersion")
Expand All @@ -21,10 +21,18 @@ dependencies {
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
implementation("org.apache.logging.log4j:log4j-core:2.24.1")

testImplementation(platform("org.junit:junit-bom:5.11.3"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("dev.restate:sdk-testing:$restateVersion")
}

// Set main class
application {
mainClass.set("my.example.Greeter")
}

tasks.named<Test>("test") {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Greeter {

@Handler
public String greet(Context ctx, String greeting) {
return greeting;
return "Hello " + greeting;
}

public static void main(String[] args) {
Expand Down
34 changes: 34 additions & 0 deletions templates/java-gradle/src/test/java/my/example/GreeterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 my.example;

import dev.restate.sdk.client.Client;
import dev.restate.sdk.testing.BindService;
import dev.restate.sdk.testing.RestateClient;
import dev.restate.sdk.testing.RestateTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import static org.junit.jupiter.api.Assertions.assertEquals;

@RestateTest
class GreeterTest {

@BindService
private final Greeter greeter = new Greeter();

@Test
@Timeout(value = 10)
void testGreet(@RestateClient Client ingressClient) {
var client = GreeterClient.fromClient(ingressClient);

String response = client.greet("Francesco");
assertEquals(response, "Hello Francesco");
}
}
2 changes: 1 addition & 1 deletion templates/java-maven-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<quarkus.platform.version>3.15.1</quarkus.platform.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.3.1</surefire-plugin.version>
<restate.version>1.1.1</restate.version>
<restate.version>1.2.0</restate.version>
</properties>

<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion templates/java-maven-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Have a look at the [Java Quickstart guide](https://docs.restate.dev/get_started/
To start the service, simply run:

```shell
$ mvn spring-boot:run
$ mvn compile spring-boot:run
```
Loading

0 comments on commit 28ded7c

Please sign in to comment.