Head to Wiki for detailed design docs.
-
Install SBT
On linux/windows based systems, you can use SDKMAN software development kit manager for convenient installation and usage of multiple versions.
-
Install Docker
Follow docker installation guide here.
-
Install Minikube/Kubectl
Use following convenience script to install both minikube and kubectl.
$ ./deploy/scripts/setup-minikube-for-linux.sh
Protobuf files are maintained in a separate sbt project to avoid maintaining them in both client and server.
$ cd prime-protobuf
$ sbt +publishLocal
Note: The project can be cross-compiled to multiple Scala versions. Should you choose to compile it into a Scala version of your choice, don't forget to update build.sbt
with desired Scala version.
$ sbt prime-generator/docker:publishLocal
$ sbt prime-proxy/docker:publishLocal
Note: Make sure to point local docker daemon to minikube internal docker registry to make the docker images available inside minikube cluster. Use following command.
$ eval $(minikube -p minikube docker-env)
$ kubectl apply -f deploy/k8s/prime-generator.yml
$ kubectl apply -f deploy/k8s/prime-proxy.yml
$ sbt prime-generator/test
$ sbt prime-proxy/test
$ sbt test
The end-to-end integration tests are available under prime-proxy/src/it
.
$ sbt it:test
Note: While running end to end integration tests make sure to export minikube ip address as environment variable PRIME_PROXY_INTERFACE
as shown below:
$ export PRIME_PROXY_INTERFACE=$(minikube ip)
The prime number generator service is available over following REST APIs.
The following API returns a stream of comma-separated prime numbers up until a given number.
$ curl $(minikube ip)/prime/23
Note: This is achieved by making use of source streaming support in akka http. See docs. The implementation makes use of custom CsvEntityStreamingSupport
.
The following API returns a string of comma-separated list of prime numbers up until a given number.
$ curl $(minikube ip)/prime/23/seq
Note: There is a hard-limit of 10000
prime numbers is set to avoid OOM.
The following API returns a stream of prime numbers up until a given number separated by new line.
$ curl $(minikube ip)/prime/23/csv-stream
Note: This is achieved by making use of source streaming support in akka http. See docs. The implementation makes use of default CsvEntityStreamingSupport
.
An alternative API returns prime numbers as SSE events. There is no hard limit set for this API.
$ curl $(minikube ip)/prime/23/sse