Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shivam-880/prime-grpc-scala-akka
Project to demonstrate implementation of gRPC services in Scala using Akka gRPC.
https://github.com/shivam-880/prime-grpc-scala-akka
akka-grpc akka-http grpc scala
Last synced: 7 days ago
JSON representation
Project to demonstrate implementation of gRPC services in Scala using Akka gRPC.
- Host: GitHub
- URL: https://github.com/shivam-880/prime-grpc-scala-akka
- Owner: shivam-880
- Created: 2021-07-19T18:13:01.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-27T11:48:42.000Z (over 3 years ago)
- Last Synced: 2024-10-15T10:05:18.815Z (22 days ago)
- Topics: akka-grpc, akka-http, grpc, scala
- Language: Scala
- Homepage:
- Size: 103 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# prime-grpc-scala-akka
Head to [Wiki](https://github.com/iamsmkr/prime-grpc-scala-akka/wiki) for detailed design docs.
## Install Dependencies
1. Install SBTOn linux/windows based systems, you can use [SDKMAN](https://sdkman.io/) software development kit manager for convenient installation and usage of multiple versions.
2. Install Docker
Follow docker installation guide [here](https://docs.docker.com/engine/install/).
3. Install Minikube/Kubectl
Use following convenience script to install both minikube and kubectl.
```sh
$ ./deploy/scripts/setup-minikube-for-linux.sh
```## Build
#### 1. Publish Protobuf Sources
Protobuf files are maintained in a separate sbt project to avoid maintaining them in both client and server.
```sh
$ 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.
#### 2. Publish Docker Images
```sh
$ 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.
```sh
$ eval $(minikube -p minikube docker-env)
```## Deploy
```sh
$ kubectl apply -f deploy/k8s/prime-generator.yml
$ kubectl apply -f deploy/k8s/prime-proxy.yml
```## Test
#### 1. Unit Tests
```sh
$ sbt prime-generator/test
$ sbt prime-proxy/test
$ sbt test
```#### 2. Integration Tests
The end-to-end integration tests are available under `prime-proxy/src/it`.
```sh
$ 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)
```## Usage
The prime number generator service is available over following REST APIs.#### 1. Comma-Separated Stream
The following API returns a stream of comma-separated prime numbers up until a given number.
```sh
$ curl $(minikube ip)/prime/23
```**Note**: This is achieved by making use of source streaming support in akka http. See [docs](https://docs.huihoo.com/akka/akka-http/10.0.7/scala/http/routing-dsl/source-streaming-support.html#simple-csv-streaming-example). The implementation makes use of custom `CsvEntityStreamingSupport`.
#### 2. Comma-Separated Seq
The following API returns a string of comma-separated list of prime numbers up until a given number.
```sh
$ curl $(minikube ip)/prime/23/seq
```**Note**: There is a hard-limit of `10000` prime numbers is set to avoid OOM.
#### 3. Newline-Separated Stream
The following API returns a stream of prime numbers up until a given number separated by new line.
```sh
$ curl $(minikube ip)/prime/23/csv-stream
```**Note**: This is achieved by making use of source streaming support in akka http. See [docs](https://docs.huihoo.com/akka/akka-http/10.0.7/scala/http/routing-dsl/source-streaming-support.html#simple-csv-streaming-example). The implementation makes use of default `CsvEntityStreamingSupport`.
#### 4. SeverSentEvents
An alternative API returns prime numbers as SSE events. There is no hard limit set for this API.
```sh
$ curl $(minikube ip)/prime/23/sse
```