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
2 changes: 1 addition & 1 deletion samples/java-valueentity-customer-registry/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Views documentation example
# Customer Registry example (using a Value Entity)

This example includes the code snippets that are used in the Views documentation.

Expand Down
76 changes: 76 additions & 0 deletions samples/scala-valueentity-customer-registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Customer Registry example (using a Value Entity)


## Building and running unit tests

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

```shell
sbt test
```



## 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:

```
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.

To start the application locally, use the following command:

```
sbt run
```

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://docs.lbcs.dev/js-services/proto.html#_transcoding_http)), this endpoint accepts POST requests at the path `/[package].[entity name]/[method]`. For example, using `curl`:

* Create a customer with:
```
grpcurl --plaintext -d '{"customer_id": "wip", "email": "[email protected]", "name": "Very Important", "address": {"street": "Road 1", "city": "The Capital"}}' localhost:9000 customer.api.CustomerService/Create
```
* Retrieve the customer:
```
grpcurl --plaintext -d '{"customer_id": "wip"}' localhost:9000 customer.api.CustomerService/GetCustomer
```
* Query by name:
```
grpcurl --plaintext -d '{"customer_name": "Very Important"}' localhost:9000 customer.view.CustomerByName/GetCustomers
```
* Change name:
```
grpcurl --plaintext -d '{"customer_id": "wip", "new_name": "Most Important"}' localhost:9000 customer.api.CustomerService/ChangeName
```
* Change address:
```
grpcurl --plaintext -d '{"customer_id": "wip", "new_address": {"street": "Street 1", "city": "The City"}}' localhost:9000 customer.api.CustomerService/ChangeAddress
```

## 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/setting-up/)
and configure a Docker Registry to upload your docker image to.

You will need to set the `docker.username` system property when starting sbt to be able to publish the image, for example `sbt -Ddocker.username=myuser docker:publish`.

If you are publishing to a different registry than docker hub, you will also need to specify what registry using the system property `docker.registry`.

Refer to
[Configuring registries](https://developer.lightbend.com/docs/akka-serverless/projects/container-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
through the `akkasls` CLI or via the web interface.
18 changes: 18 additions & 0 deletions samples/scala-valueentity-customer-registry/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"
services:
akka-serverless-proxy:
image: gcr.io/akkaserverless-public/akkaserverless-proxy:0.7.0-beta.19
command: -Dconfig.resource=dev-mode.conf -Dakkaserverless.proxy.eventing.support=google-pubsub-emulator
ports:
- "9000:9000"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
USER_FUNCTION_HOST: ${USER_FUNCTION_HOST:-host.docker.internal}
USER_FUNCTION_PORT: ${USER_FUNCTION_PORT:-8080}
PUBSUB_EMULATOR_HOST: gcloud-pubsub-emulator
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