Skip to content

Commit

Permalink
Move Tour of Restate Java to examples (#93)
Browse files Browse the repository at this point in the history
* Add Java Tour of Restate

* Add to git workflows

* Add to zip creation
  • Loading branch information
gvdongen authored Feb 5, 2024
1 parent 8adbb2c commit 40fceac
Show file tree
Hide file tree
Showing 38 changed files with 1,533 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
# When adding a new example make sure it's listed here
- name: Find and replace restateVersion in build.gradle.kts for java templates
if: github.event.inputs.sdkJavaVersion != ''
run: for jvmDir in hello-world-http hello-world-lambda food-ordering/app patterns; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' java/$jvmDir/build.gradle.kts; done
run: for jvmDir in hello-world-http hello-world-lambda food-ordering/app tour-of-restate patterns; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' java/$jvmDir/build.gradle.kts; done
- name: Find and replace restateVersion in build.gradle.kts for kotlin templates
if: github.event.inputs.sdkJavaVersion != ''
run: for jvmDir in hello-world-http hello-world-lambda; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' kotlin/$jvmDir/build.gradle.kts; done
Expand Down Expand Up @@ -90,6 +90,12 @@ jobs:
with:
arguments: check
build-root-directory: java/patterns
- name: Test java/tour-of-restate
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/tour-of-restate
- name: Test kotlin/hello-world-http
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
java-hello-world-http.zip
java-hello-world-lambda.zip
java-food-ordering.zip
java-tour-of-restate.zip
kotlin-hello-world-http.zip
kotlin-hello-world-lambda.zip
kotlin-hello-world-lambda-cdk.zip
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ jobs:
with:
arguments: check
build-root-directory: java/patterns
- name: Test java/tour-of-restate
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/tour-of-restate
- name: Test kotlin/hello-world-http
uses: gradle/gradle-build-action@v2
with:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Browse this repository to see how easy distributed applications development beco
| Kotlin | [Hello world on AWS Lambda](kotlin/hello-world-lambda) |
| Kotlin | [Hello world on AWS Lambda + CDK](kotlin/hello-world-lambda-cdk) |

## Tutorials
| Language | Name / Link |
|----------|-----------------------------------------|
| Java | [Tour of Restate](java/tour-of-restate) |

## Patterns

| Language | Name / Link |
Expand Down Expand Up @@ -119,3 +124,5 @@ Before releasing, trigger the "pre-release" workflow to update sdk versions. Thi
Once the repo is ready for the release, push a tag of the form `vX.Y.Z`.
This triggers a workflow that [creates a draft release](https://github.com/restatedev/examples/releases) on Github, which you need to approve to finalize it.
Please update the version tag referenced on the [Tour of Restate](https://github.com/restatedev/documentation/blob/main/docs/tour.mdx) documentation page.
5 changes: 5 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This directory contains Restate examples using the Java SDK.
| Java | [Hello World HTTP](hello-world-http) |
| Java | [Hello world on AWS Lambda](hello-world-lambda) |

## Tutorials
| Language | Name / Link |
|----------|-----------------------------------------|
| Java | [Tour of Restate](java/tour-of-restate) |

## Patterns

| Language | Name / Link |
Expand Down
3 changes: 3 additions & 0 deletions java/tour-of-restate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle
.idea
build
41 changes: 41 additions & 0 deletions java/tour-of-restate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# A Tour of Restate with Java

Restate is a system for easily building resilient applications using **distributed durable RPC & async/await**.

This example contains the code for the `Tour of Restate` tutorial, for the Java SDK.
This tutorial takes your through key Restate features by developing an end-to-end ticketing app.

❓ Learn more about Restate from the [Restate documentation](https://docs.restate.dev).


## Download the example

- Via the CLI:
```shell
restate example java-tour-of-restate && cd java-tour-of-restate
```

- Via git clone:
```shell
git clone git@github.com:restatedev/examples.git
cd examples/java/tour-of-restate
```

- Via `wget`:
```shell
wget https://github.com/restatedev/examples/releases/latest/download/java-tour-of-restate.zip && unzip java-tour-of-restate.zip -d java-tour-of-restate && rm java-tour-of-restate.zip
```

## Running the example

Have a look at the [Tour of Restate tutorial](https://docs.restate.dev/tour) in the documentation to build and run the application in this repository.

In short, you can run the different parts of the code via:

```typescript
./gradlew run
./gradlew -PmainClass=dev.restate.tour.part1.AppMain run
./gradlew -PmainClass=dev.restate.tour.part2.AppMain run
./gradlew -PmainClass=dev.restate.tour.part3.AppMain run
./gradlew -PmainClass=dev.restate.tour.part4.AppMain run
```
62 changes: 62 additions & 0 deletions java/tour-of-restate/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import com.google.protobuf.gradle.id

plugins {
java
application

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

repositories {
mavenCentral()
}

val restateSdkVersion = "0.7.0"

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

// 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")
}

// 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:$restateSdkVersion:all@jar" }
}

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

// Set main class
application {
if (project.hasProperty("mainClass")) {
mainClass.set(project.property("mainClass") as String);
} else {
mainClass.set("dev.restate.tour.app.AppMain")
}
}
Binary file not shown.
7 changes: 7 additions & 0 deletions java/tour-of-restate/gradle/wrapper/gradle-wrapper.properties
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

0 comments on commit 40fceac

Please sign in to comment.