Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
fs2 grpc chapter names
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-ciocirlan committed Oct 2, 2023
1 parent bdc7a6b commit 9828bce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions _posts/2023-10-02-grpc-in-scala-with-fs2-scalapb.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ At the time of writing this article, `gRPC` officially supports 11 programming l
One of the main use cases for `gRPC` is communication between internal microservices. In the following sections, we'll create a `gRPC` server and client that will process streams of orders sent from an online store.
We'll also learn how to write a `.proto` file which we'll use to generate necessary case classes and `traits` using the `Fs2Grpc` library and finally dig into `Scalapb` to generate custom types for our application.

## 2. Setting Up.
## 2. Setting Up

In our new Scala project, let's create a `plugins.sbt` file in the `project` folder with the following code:

Expand Down Expand Up @@ -155,7 +155,7 @@ Now we can head over to our terminal, navigate to our project directory and run

After compilation, we'll find two sets of generated files in `protobuf/target/scala-3.3.0/src_managed/main`, one under a `Fs2Grpc` folder that contains our `trait` while the rest are cases classes will be under a `Scalapb` folder. If we look at the top of each of these files, we'll find that they are all under the `com.rockthejvm.protos.orders` package namespace that we defined in our `orders.proto` file.

## 4. The gRPC server.
## 4. The gRPC server
Let's take a look at the `OrderFs2Grpc.scala` file generated by `Fs2Grpc`:

```scala
Expand Down Expand Up @@ -264,7 +264,7 @@ object Server {
.flatMap(x => runServer(x))
}
```
## 4. The gRPC client.
## 4. The gRPC client
Create `OrderClient.scala` in the following path, `src/main/scala/com/rockthejvm/client/OrderClient.scala` and add the following code.

```scala
Expand Down Expand Up @@ -566,7 +566,7 @@ object AppRoutes {
}
```

## 6. Index.html
## 6. The "web UI"
Create the `index.html` file in the following path, `src/main/resources/index.html`, this file is quite lengthy, we can copy the contents from this [link](https://github.com/hkateu/orderbuffer/blob/main/src/main/resources/index.html).
It consists of 3 forms each with the following format:

Expand Down Expand Up @@ -819,7 +819,7 @@ Once the form is filled and submitted, we should see a response similar to the f
![server response](../images/grpc/results.png)
## 8. Managing currency with Squants.
## 8. Managing Currency with Squants
Throughout the article we've been representing money as `Double`, we could improve our code by using the `Squants` library to manage currency values, specifically `Squants`' `Money` type.
Therefore the question arises, if the case classes are generated by `Scalapb`, how can we make it so that `Scalapb` generates `Squants`' `Money` type for `amount` and `total`? `Scalapb` provides a mechanism for customizing generated types convenient for such scenarios.
Expand Down

0 comments on commit 9828bce

Please sign in to comment.