Skip to content

Commit

Permalink
Create java/patterns and add compensations pattern
Browse files Browse the repository at this point in the history
This fixes #52.
  • Loading branch information
tillrohrmann committed Jan 23, 2024
1 parent 786b971 commit c7c99fb
Show file tree
Hide file tree
Showing 14 changed files with 791 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 @@ -53,7 +53,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; 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 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 All @@ -80,6 +80,12 @@ jobs:
with:
arguments: check
build-root-directory: java/food-ordering/app
- name: Test java/patterns
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/patterns
- name: Test kotlin/hello-world-http
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
with:
arguments: check
build-root-directory: java/food-ordering/app
- name: Test java/patterns
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/patterns
- name: Test kotlin/hello-world-http
uses: gradle/gradle-build-action@v2
with:
Expand Down
15 changes: 15 additions & 0 deletions java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Java examples

This directory contains Restate examples using the Java SDK.

## Common patterns

- A collection of [common patterns](patterns) you encounter when developing distributed applications.

## Starter examples

- [Hello World](hello-world-http): A simple example of a Restate service.
- [Hello World - AWS Lambda](hello-world-lambda): A simple example of how you can run a Restate service on AWS Lambda.

## Applications
- [Food ordering](food-ordering): See how to integrate Restate with external services using Awakeables and side effects.
35 changes: 35 additions & 0 deletions java/patterns/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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

# Unignore the gradle wrapper
!gradle/wrapper/gradle-wrapper.jar
11 changes: 11 additions & 0 deletions java/patterns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Restate Sample Patterns

A collections of useful patterns in distributed applications, and how to
implement them with [Restate](https://github.com/restatedev/restate).
This is a continuously evolving list.

All patterns are described in one file and have a comment block at the top that explains them.

### List of Patterns

- [**Compensations**](src/main/java/dev/restate/patterns/Compensations.java)
71 changes: 71 additions & 0 deletions java/patterns/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import com.google.protobuf.gradle.id

plugins {
java
application

id("com.google.protobuf") version "0.9.1"
id("com.diffplug.spotless") version "6.24.0"
}

repositories {
mavenCentral()
}

val restateVersion = "0.7.0"

dependencies {
// 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-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-testing:$restateVersion")
}

configure<com.diffplug.gradle.spotless.SpotlessExtension> {
java {
targetExclude("build/generated/**/*.java")

googleJavaFormat()
}
}

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

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

// Configure test platform
tasks.withType<Test> {
useJUnitPlatform()
}
Binary file added java/patterns/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions java/patterns/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 c7c99fb

Please sign in to comment.