Skip to content

Commit

Permalink
Renamings (#115)
Browse files Browse the repository at this point in the history
* Removed design file that is no longer valid
* Renaming of packages:
  * sdk-vertx -> sdk-http-vertx
  * sdk-blocking -> sdk-java-blocking
* Improve READMEs
* Remove unused docs files from Antora
  • Loading branch information
slinkydeveloper authored Oct 11, 2023
1 parent 97773ee commit 529f59f
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 267 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ jobs:
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1

# Ideally we delete old packages after releasing new ones but this does not work for snapshot releases
- name: Delete old java-sdk packages
uses: actions/delete-package-versions@v3
with:
package-name: 'dev.restate.sdk.java-sdk'
min-versions-to-keep: 0
# We want to remove all the versions containing SNAPSHOT in the name
# See https://github.com/actions/delete-package-versions/issues/61
ignore-versions: '^.*(?<!SNAPSHOT)$'
token: ${{ secrets.GITHUB_TOKEN }}

- name: Build with Gradle & publish to GitHub packages repository
uses: gradle/gradle-build-action@v2
env:
Expand Down
124 changes: 122 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,123 @@
# sdk-java
# Restate JVM SDK

Restate SDK for Java
[Restate](https://restate.dev/) is a system for easily building resilient applications using _distributed durable async/await_. This repository contains the Restate SDK for writing services using JVM languages.

This SDK features:

- Implement Restate services using either:
- Java
- Kotlin coroutines
- Reuse the existing gRPC/Protobuf ecosystem to define service interfaces
- Deploy Restate services as:
- Non-blocking HTTP servers
- On AWS Lambda

Check [Restate GitHub](https://github.com/restatedev/) or the [docs](https://docs.restate.dev/) for further details.

## Using the SDK

To get started, check out a template project in https://github.com/restatedev/examples/tree/main/jvm, or look at the examples in the [examples](examples) directory.

The SDK is composed in modules that you can pick depending on the service you want to build:

- [sdk-java-blocking](sdk-java-blocking) contains the plain Java blocking interface.
- [sdk-kotlin](sdk-kotlin) contains the Kotlin coroutines based interface.
- [sdk-http-vertx](sdk-http-vertx) contains the HTTP server endpoint implementation, based on [Eclipse Vert.x](https://vertx.io).
- [sdk-lambda](sdk-lambda) contains the AWS Lambda endpoint implementation, based on the [official AWS SDK](https://docs.aws.amazon.com/lambda/latest/dg/lambda-java.html).

You need to set up a gRPC code-generator to generate the required Protobuf/gRPC classes.

For example, given the following contract:

```protobuf
service Counter {
option (dev.restate.ext.service_type) = KEYED;
rpc Add (AddRequest) returns (google.protobuf.Empty);
rpc Get (GetRequest) returns (GetResponse);
}
message GetRequest {
string counter_name = 1 [(dev.restate.ext.field) = KEY];
}
message GetResponse {
int64 value = 1;
}
message AddRequest {
string counter_name = 1 [(dev.restate.ext.field) = KEY];
int64 value = 2;
}
```

A Java implementation looks like the following:

```java
public class Counter extends CounterGrpc.CounterImplBase implements RestateBlockingService {

private static final StateKey<Long> TOTAL = StateKey.of("total", Long.class);

@Override
public void add(AddRequest request, StreamObserver<Empty> responseObserver) {
RestateContext ctx = restateContext();

long currentValue = ctx.get(TOTAL).orElse(0L);
long newValue = currentValue + request.getValue();
ctx.set(TOTAL, newValue);

responseObserver.onNext(Empty.getDefaultInstance());
responseObserver.onCompleted();
}

@Override
public void get(GetRequest request, StreamObserver<GetResponse> responseObserver) {
long currentValue = restateContext().get(TOTAL).orElse(0L);

responseObserver.onNext(GetResponse.newBuilder().setValue(currentValue).build());
responseObserver.onCompleted();
}
}
```

A kotlin implementation looks like the following:

```kotlin
class Counter(coroutineContext: CoroutineContext) :
CounterGrpcKt.CounterCoroutineImplBase(coroutineContext), RestateCoroutineService {

private val TOTAL = StateKey.of("total", Long::class.java)

override suspend fun add(request: AddRequest): Empty {
val currentValue = restateContext().get(TOTAL) ?: 0L
val newValue = currentValue + add

restateContext().set(TOTAL, newValue)

return currentValue to newValue
return Empty.getDefaultInstance()
}

override suspend fun get(request: GetRequest): GetResponse {
return getResponse { value = getCounter() }
}
}
```

## Contributing to the SDK

Prerequisites:

- JDK >= 11

To build the SDK:

```shell
./gradlew build
```

To run the tests:

```shell
./gradlew check
```
221 changes: 0 additions & 221 deletions development/packages.puml

This file was deleted.

1 change: 0 additions & 1 deletion docs/modules/java/pages/communication.adoc

This file was deleted.

1 change: 0 additions & 1 deletion docs/modules/java/pages/index.adoc

This file was deleted.

1 change: 0 additions & 1 deletion docs/modules/java/pages/state.adoc

This file was deleted.

4 changes: 4 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Examples

- [http](http): Example using `sdk-http-vertx` to deploy a Restate HTTP Service endpoint, with both Java and Kotlin service implementations.
- [lambda](lambda): Example using `sdk-lambda` to deploy a Restate Lambda endpoint, with both Java and Kotlin service implementations.
6 changes: 3 additions & 3 deletions examples/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ In order to run the Kotlin implementation, you have to specify the main class vi

## Invoking the counter service

If you want to invoke the counter service via [grpcurl](https://github.com/fullstorydev/grpcurl) you can leverage the automatically generated descriptor set:
If you want to invoke the counter service via [grpcurl](https://github.com/fullstorydev/grpcurl):

```shell
grpcurl -protoset examples/build/generated/source/proto/main/descriptor_set.desc -plaintext -d '{"counter_name": "my_counter"}' localhost:9090 counter.Counter/Get
grpcurl -plaintext -d '{"counter_name": "my_counter"}' localhost:9090 counter.Counter/Get
```

The command assumes that the Restate runtime is reachable under `localhost:9090`.
The command assumes that the Restate runtime is reachable under `localhost:9090`.
Loading

0 comments on commit 529f59f

Please sign in to comment.