Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ jobs:
command: |
cd samples/valueentity-counter
echo "Running mvn with SDK version: '$SDK_VERSION'"
mvn -Dakkaserverless-sdk.version=$SDK_VERSION verify -Pit
mvn -Dakkaserverless-sdk.version=$SDK_VERSION verify -Pit
- run:
name: Run integration tests for Counter Replicated Entity sample
command: |
cd samples/replicatedentity-counter
echo "Running mvn with SDK version: '$SDK_VERSION'"
mvn -Dakkaserverless-sdk.version=$SDK_VERSION verify -Pit
- save_sbt_cache

publish:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ src_managed
storage
tags
target
dependency-reduced-pom.xml
78 changes: 78 additions & 0 deletions samples/replicatedentity-counter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Implementing a Counter as a Replicated Entity

## Building and running unit tests

To compile and test the code from the command line, use

```shell
mvn verify
```

## Running the integration tests

The integration test sources are in the `src/it/java` directory.

NOTE: As this is not part of the standard Maven setup, you might need to add it as test source directory in your IDE. (IntelliJ: right klick on the directory -> "Mark directory as" | "Test sources root")

Maven is configured to run tests from it when using the `it` profile.

```shell
mvn verify -Pit
```

The integration test uses Docker via [TestContainers](https://www.testcontainers.org/) to set up the Akka Serverless environment before calling the gRPC API.

## Running Locally

In order to run your application locally, you must run the Akka Serverless proxy. The included `docker compose` file contains the configuration required to run the proxy for a locally running application.
It also contains the configuration to start a local Google Pub/Sub emulator that the Akka Serverless proxy will connect to.
To start the proxy, run the following command from this directory:


```shell
docker compose up
```

> On Linux this requires Docker 20.10 or later (https://github.com/moby/moby/pull/40007),
> or for a `USER_FUNCTION_HOST` environment variable to be set manually.

```shell
docker compose -f docker-compose.yml -f docker-compose.linux.yml up
```

To start the application locally, the `exec-maven-plugin` is used. Use the following command:

```shell
mvn compile exec:java
```

For further details see [Running a service locally](https://developer.lightbend.com/docs/akka-serverless/developing/running-service-locally.html) in the documentation.

## Exercise the service

With both the proxy and your application running, any defined endpoints should be available at `http://localhost:9000`. In addition to the defined gRPC interface, each method has a corresponding HTTP endpoint. Unless configured otherwise (see [Transcoding HTTP](https://developer.lightbend.com/docs/akka-serverless/java/proto.html#_transcoding_http)), this endpoint accepts POST requests at the path `/[package].[entity name]/[method]`. For example, using `curl`:

```shell
curl -XPOST -H "Content-Type: application/json" localhost:9000/com.example.CounterService/GetCurrentCounter -d '{"counterId": "foo"}'
```

Or, given [`grpcurl`](https://github.com/fullstorydev/grpcurl):

```shell
grpcurl -plaintext -d '{"counterId": "foo"}' localhost:9000 com.example.CounterService/GetCurrentCounter
```

## Deploying

To deploy your service, install the `akkasls` CLI as documented in
[Setting up a local development environment](https://developer.lightbend.com/docs/akka-serverless/getting-started/set-up-development-env.html)
and configure a Docker Registry to upload your docker image to.

You will need to update the `dockerImage` property in the `pom.xml` and refer to
[Configuring registries](https://developer.lightbend.com/docs/akka-serverless/deploying/registries.html)
for more information on how to make your docker image available to Akka Serverless.

Finally, you can use the [Akka Serverless Console](https://console.akkaserverless.com)
to create an Akka Serverless project and then deploy your service into it either by using `mvn deploy`,
through the `akkasls` CLI or via the web interface. When using `mvn deploy`, Maven will also
conveniently package and publish your docker image prior to deployment.
5 changes: 5 additions & 0 deletions samples/replicatedentity-counter/docker-compose.linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "3"
services:
akka-serverless-proxy:
extra_hosts:
- "host.docker.internal:host-gateway"
15 changes: 15 additions & 0 deletions samples/replicatedentity-counter/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.9
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
environment:
USER_FUNCTION_HOST: ${USER_FUNCTION_HOST:-host.docker.internal}
USER_FUNCTION_PORT: ${USER_FUNCTION_PORT:-8080}
gcloud-pubsub-emulator:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:341.0.0
command: gcloud beta emulators pubsub start --project=test --host-port=0.0.0.0:8085
ports:
- 8085:8085
Loading