A simple server which communicates via gRPC.
Note: in the examples below, the ports 9999
and 8888
can be replaced with any appropriate port, but the hostnames (localhost
when running locally, 0.0.0.0
when running within a Docker container) should not be changed.
- Scala 3.1.3
- sbt 1.7.1
- Java 17.0.3
and also
docker
- protobuf
akka-http
json4s
andupickle
scalactic
andscalatest
with
sbt compile
sbt test
sbt run
sbt assembly
Note that run
accepts host (-h
/--host
) and port (-p
/--port
) command-line arguments.
From the terminal
$ sbt "run -p=9999 -h=localhost"
From inside the sbt
shell
sbt> run -p=9999 -h=localhost
This configuration can also be overridden by editing application.conf
or by defining the $CLIF_HOST
and $CLIF_PORT
environment variables.
- make sure you're in the project root (
/cli-flashcards
) directory - make sure
$CLIF_HOST
and$CLIF_PORT
are set appropriately sbt run -h=$CLIF_HOST -p=$CLIF_PORT
- then, in another terminal, to list all available categories of flashcards
$ grpcurl -plaintext -import-path ./src/main/protobuf -proto flashcards.proto $CLIF_HOST:$CLIF_PORT cli_flashcards.FlashcardService/Categories
- and to list all flashcards in a category
$ grpcurl -d '{"name": "example"}' -plaintext -import-path ./src/main/protobuf -proto flashcards.proto $CLIF_HOST:$CLIF_PORT cli_flashcards.FlashcardService/Flashcards
Publish a fat jar with sbt assembly
and then run with Java 17+
$ java -jar path/to/cli-flashcards-x.y.z.jar
Usually, this is
$ java -jar target/scala-3.1.3/cli-flashcards-x.y.z.jar
add host
and port
flags after the jar name, like
$ java -jar target/scala-3.1.3/cli-flashcards-x.y.z.jar -h=localhost -p=9999
In the root directory (where the Dockerfile
is) run
$ docker build -t cli-flashcards:x.y.z .
then, run with
$ docker run -it -p $CLIF_PORT:8888 cli-flashcards:my-tag -h=0.0.0.0 -p=8888
and interact with
$ grpcurl -plaintext -import-path ./src/main/protobuf -proto flashcards.proto localhost:$CLIF_PORT cli_flashcards.FlashcardService/Categories
or
$ grpcurl -d '{"name": "example"}' -plaintext -import-path ./src/main/protobuf -proto flashcards.proto localhost:$CLIF_PORT cli_flashcards.FlashcardService/Flashcards
Note that we docker run
using 0.0.0.0
, but we grpcurl
using localhost