While designing your service it is useful to read designing services.
This project has a bare-bones skeleton service ready to go, but in order to adapt and extend it it may be useful to read up on developing services and in particular the JVM section.
You can use sbt to build your project,
which will also take care of generating code based on the .proto
definitions:
sbt compile
In order to run your application locally, you must run the Kalix proxy. The included docker-compose.yml
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 Kalix 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 (moby/moby#40007), or for a
USER_FUNCTION_HOST
environment variable to be set manually.
To start the application locally, start it from your IDE or use:
sbt run
Using grpcurl
:
> grpcurl -d '{"counterId": "foo", "value": 20 }' -plaintext localhost:9000 kalix.demo.CounterService/Increase
> grpcurl -d '{"counterId": "bar", "value": 8 }' -plaintext localhost:9000 kalix.demo.CounterService/Increase
grpcurl -d '{ "value": 10 }' -plaintext localhost:9000 kalix.demo.views.CountersByValue/GetCounters
Note: The failure is to be expected if you have not yet provided an implementation of
GetCurrentCounter
in your entity.
To deploy your service, install the kalix
CLI as documented in
Setting up a local development environment
and configure a Docker Registry to upload your Docker image to.
You will need to set your docker.username
as a system property:
sbt -Ddocker.username=mary docker:publish
Refer to Configuring registries for more information on how to make your Docker image available to Kalix.
You can now deploy your service through the kalix CLI:
$ kalix auth login
If this is your first time using Kalix, this will let you register an account, create your first project and set it as the default.
Now:
$ kalix services deploy \
my-service \
my-container-uri/container-name:tag-name
Once the service has been successfully started (this may take a while), you can create an ad-hoc proxy to call it from your local machine:
$ kalix services proxy my-service
Listening on 127.0.0.1:8080
Or expose it to the Internet:
kalix service expose my-service