probable-garbanzo
"What a wonderful phrase!"
OK... maybe not as catchy as Hakuna Matata. But this is a little project to explore some concepts using Scala.
About the project
In order to enhance my knowledge of Scala, I am trying to implement a simple setup to find prime numbers, making use of different technologies including gRPC/protobuf.
Project structure
There are five main components to the project:
prime-number-server
: a small server which can tell you the next prime number which is greater than an input integer.proxy-service
: a small server which acts as a proxy toprime-number-server
, returning a stream (over HTTP 1.1) of primes up to a given limit.protobuf
: protobuf contract for gRPC communication between the two servers- Integration tests: some simple test case scenarios, exercising the two servers together
- Documentation: notes and documentation about the project
How to run
This is a Scala project, intended to be built with SBT. I assume you already have a working Scala development environment. If not, let me google that for you...
Run local servers
Both servers can be launched from sbt.
prime-number-server
# run prime-number-server with default options
sbt service/run
# configure available options
PRIME_SERVICE_HOST="service" \ # address to bind to
PRIME_SERVICE_PORT: 9876 \ # port to bind to
sbt service/run
proxy-service
# run proxy-service with default options
sbt proxy/run
With the default options, the proxy server can be reached at http://localhost:8080/prime/123 (replace 123
with the desired target).
# configure available options
PRIME_SERVICE_HOST="service" \ # address to contact prime-number-server
PRIME_SERVICE_PORT: 9876 \ # port to contact prime-number-server
PRIME_PROXY_HOST: "proxy" \ # address to bind to
PRIME_PROXY_PORT: 8765 \ # port to bind to
sbt proxy/run
Docker
It is possible to build docker images for both servers:
# just prime-number-server
sbt service/docker/publishLocal
# just proxy-service
sbt proxy/docker/publishLocal
# both components (shorthand for the two above commands)
sbt dockerBuild
Once the images have been built, they can be deployed to any Docker-based environment. A convenience Docker Compose config is provided in the project.
# bring up docker network...
docker-compose up
# ...and bring it down again
docker-compose down
As a convenient shorthand, an SBT task has been defined to build both containers and then bring up the docker network:
# build docker images and bring up docker network
sbt dockerRun