Skip to content
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

sdk-java templates #42

Closed
wants to merge 11 commits into from
Closed
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
41 changes: 40 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,44 @@ on:
branches: [ main ]

jobs:
build:
build-jvm:
# prevent from running on forks
if: github.repository_owner == 'restatedev'
runs-on: ubuntu-latest
strategy:
matrix:
jvm-version: [ 17 ]

steps:
- uses: actions/checkout@v3

- name: Use JVM ${{ matrix.jvm-version }}
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: ${{ matrix.jvm-version }}

- name: Test jvm/java-blocking-http
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: jvm/java-blocking-http
- name: Test jvm/java-blocking-lambda
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: jvm/java-blocking-lambda
- name: Test jvm/kotlin-http
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: jvm/kotlin-http
- name: Test jvm/kotlin-lambda
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: jvm/kotlin-lambda
build-ts:
# prevent from running on forks
if: github.repository_owner == 'restatedev'
runs-on: ubuntu-latest
Expand All @@ -17,11 +54,13 @@ jobs:

steps:
- uses: actions/checkout@v3

- uses: bufbuild/buf-setup-action@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'

- run: npm ci --prefix typescript
- run: npm run --prefix typescript -ws verify
32 changes: 32 additions & 0 deletions jvm/java-blocking-http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

.idea
*.iml
29 changes: 29 additions & 0 deletions jvm/java-blocking-http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Blocking HTTP example

Sample project configuration of a Restate service using the Java blocking interface and HTTP server. It contains:

* [`build.gradle.kts`](build.gradle.kts)
* [Service interface definition `greeter.proto`](src/main/proto/greeter.proto)
* [Service class implementation `Greeter`](src/main/java/dev/restate/sdk/examples/Greeter.java)
* [Test `GreeterTest`](src/test/java/dev/restate/sdk/examples/GreeterTest.java)
* [Logging configuration](src/main/resources/log4j2.properties)

## Running the example

You can run the Java greeter service via:

```shell
./gradlew run
```

Or from the IDE UI.

## Running the tests

You can run the tests either via:

```shell
./gradlew check
```

Or from the IDE UI.
70 changes: 70 additions & 0 deletions jvm/java-blocking-http/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import com.google.protobuf.gradle.id

plugins {
java
application

id("com.google.protobuf") version "0.9.1"
}

repositories {
mavenCentral()
// OSSRH Snapshots repo
// TODO remove it once we have the proper release
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") }
slinkydeveloper marked this conversation as resolved.
Show resolved Hide resolved
}

val restateVersion = "0.0.1-SNAPSHOT"

dependencies {
// Restate SDK
implementation("dev.restate:sdk-java-blocking:$restateVersion")
implementation("dev.restate:sdk-http-vertx:$restateVersion")
// To use Jackson to read/write state entries (optional)
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

// Protobuf and grpc dependencies
implementation("com.google.protobuf:protobuf-java:3.24.3")
implementation("io.grpc:grpc-stub:1.58.0")
implementation("io.grpc:grpc-protobuf:1.58.0")
// This is needed to compile the @Generated annotation forced by the grpc compiler
// See https://github.com/grpc/grpc-java/issues/9153
compileOnly("org.apache.tomcat:annotations-api:6.0.53")

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

// Testing (optional)
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("dev.restate:sdk-test:$restateVersion")
}

// Configure protoc plugin
protobuf {
protoc { artifact = "com.google.protobuf:protoc:3.24.3" }

// We need both grpc and restate codegen(s) because the restate codegen depends on the grpc one
plugins {
id("grpc") { artifact = "io.grpc:protoc-gen-grpc-java:1.58.0" }
id("restate") { artifact = "dev.restate:protoc-gen-restate-java-blocking:$restateVersion:all@jar" }
}

generateProtoTasks {
all().forEach {
it.plugins {
id("grpc")
id("restate")
}
}
}
}

// Configure test platform
tasks.withType<Test> {
useJUnitPlatform()
}

// Set main class
application {
mainClass.set("dev.restate.sdk.examples.Greeter")
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading