Skip to content

Commit

Permalink
Adapt documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Chapuis authored and jchapuis committed Jul 14, 2023
1 parent 43b751f commit 1712750
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions documentation/src/main/paradox/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Endless example application is a small API for managing imaginary bookings for p
## API
It has a simple CRUD API for bookings and vehicles:

@@snip [ExampleApp](/example/src/main/scala/endless/example/ExampleApp.scala) { #api }
@@snip [ExampleApp](/example/src/main/scala/endless/example/app/HttpServer.scala) { #api }

## Scaffolding
The application is assembled via calls to @scaladoc[deployEntity](endless.runtime.akka.deploy.Deployer.deployEntity) (for bookings) and @scaladoc[deployDurableEntity](endless.runtime.akka.deploy.Deployer.deployDurableEntity) (for vehicles) (see @ref:[runtime](runtime.md) for more details)
The application is assembled via calls to @scaladoc[deployEntity](endless.runtime.pekko.deploy.Deployer.deployEntity) (for bookings) and @scaladoc[deployDurableEntity](endless.runtime.pekko.deploy.Deployer.deployDurableEntity) (for vehicles) (see @ref:[runtime](runtime.md) for more details)

@@snip [ExampleApp](/example/src/main/scala/endless/example/ExampleApp.scala) { #main }
Akka and Pekko runtimes essentially have the same API, so we'll use Pekko for the example:

@@snip [PekkoApp](/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala) { #main }

## Algebras
You might have spotted the two algebra types in the snippet above:
Expand Down Expand Up @@ -72,4 +74,4 @@ Command protocol can be also easily be covered with synchronous round-trip tests

@@snip [BookingCommandProtocolSuite](/example/src/test/scala/endless/example/protocol/BookingCommandProtocolSuite.scala) { #example }

Component and integration tests using akka testkit are also advisable and work as usual, see @github[ExampleAppSuite](/example/src/test/scala/endless/example/ExampleAppSuite.scala).
Component and integration tests using Akka or Pekko testkit are also advisable and work as usual, see @github[PekkoExampleAppSuite](/example/src/test/scala/endless/example/PekkoExampleAppSuite.scala).
8 changes: 4 additions & 4 deletions documentation/src/main/paradox/runtime.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Akka runtime
# Akka and Pekko runtimes

Once required interpreters and typeclass instances have been defined, deploying an entity with Akka boils down to a single call to @scaladoc[deployEntity](endless.runtime.akka.deploy.Deployer). This requires an actor system and the cluster sharding extension in implicit scope, bundled in the type @scaladoc[AkkaCluster](endless.runtime.akka.deploy.AkkaCluster). The recommended pattern is to use the built-in @scaladoc[managedResource](endless.runtime.akka.deploy.AkkaCluster.managedResource) helper method to obtain an instance of this class, which wraps actor system creation and shutdown with a cats effect @link:[Resource](https://typelevel.org/cats-effect/docs/std/resource) { open=new }.
Once required interpreters and typeclass instances have been defined, deploying an entity with Akka or Pekko boils down to a single call to @scaladoc[deployEntity](endless.runtime.akka.deploy.Deployer). This requires an actor system and the cluster sharding extension in implicit scope, bundled in the type @scaladoc[AkkaCluster](endless.runtime.akka.deploy.AkkaCluster). The recommended pattern is to use the built-in @scaladoc[managedResource](endless.runtime.akka.deploy.AkkaCluster.managedResource) helper method to obtain an instance of this class, which wraps actor system creation and shutdown with a cats effect @link:[Resource](https://typelevel.org/cats-effect/docs/std/resource) { open=new }.

## `deployEntity`
This function brings everything together and delivers a cats effect @link:[Resource](https://typelevel.org/cats-effect/docs/std/resource) { open=new } with the repository instance in context `F` bundled with the ref to the shard region actor returned by the call to Akka's @link:[ClusterSharding.init](https://doc.akka.io/docs/akka/current/typed/cluster-sharding.html#basic-example) { open=new }.

The following snippet is the scaffolding for the library's sample application, a simple API to manage bookings:
The following snippet is the scaffolding for the library's sample application (in its Pekko form), a simple API to manage vehicles and bookings:

@@snip [ExampleApp](/example/src/main/scala/endless/example/ExampleApp.scala) { #main }
@@snip [ExampleApp](/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala) { #main }

`deployEntity` is parameterized with the context `F` and the various involved types: `S` for entity state, `E` for events, `ID` for entity ID and `Alg` & `RepositoryAlg` for entity and repository algebras respectively (both higher-kinded type constructors).

Expand Down
4 changes: 2 additions & 2 deletions example/src/main/scala/endless/example/app/HttpServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ object HttpServer {

final case class BookingPatch(origin: Option[LatLon], destination: Option[LatLon])

// #api
def apply(
port: Int,
bookingRepository: BookingRepositoryAlg[IO],
Expand All @@ -37,6 +36,7 @@ object HttpServer {
): Resource[IO, Server] =
Resource
.pure(
// #api
HttpRoutes
.of[IO] {
case req @ POST -> Root / "booking" => postBooking(bookingRepository, req)
Expand All @@ -63,13 +63,13 @@ object HttpServer {
}
.orNotFound
)
// #api
.flatMap(service =>
BlazeServerBuilder[IO]
.bindHttp(port, "localhost")
.withHttpApp(service)
.resource
)
// #api

private def postBooking(bookingRepository: BookingRepositoryAlg[IO], req: Request[IO]) =
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ object PekkoApp extends Bookings with Vehicles with Availabilities {
}).void
)

// #main
private def createPekkoApp(port: Int)(actorSystem: ActorSystem[Nothing]): Resource[IO, Server] = {
implicit val askTimeout: Timeout = Timeout(10.seconds)

// #main
Resource
.eval(Slf4jLogger.create[IO])
.flatMap { implicit logger: Logger[IO] =>
Expand Down Expand Up @@ -111,6 +111,6 @@ object PekkoApp extends Bookings with Vehicles with Availabilities {
}
}
}
// #main
}
// #main
}

0 comments on commit 1712750

Please sign in to comment.