Chapter 15

  1. How do you map the endpoint with the query parameter to a REST call?
def answer(parameter: Int): ServiceCall[NotUsed, Done]

override def
descriptor: Descriptor = {
import Service._
named("Answer").withCalls(
restCall(Method.POST, "/answer?parameter", answer _)
)
}
  1. What is the recommended serialization format for persistent entities?

Lagom's recommended serialization format is JSON.

  1. Can you explain why clustering is required in order to use persistence in Lagom?

Lagom's persistence is implemented on top of Akka persistence. Akka requires each persistent actor to have a unique persistence ID. In a microservice landscape, each service is supposed to have multiple instances at the same time. Without clustering, there will be multiple persistent actors with the same ID storing events into the same database, which will corrupt data. By utilizing clustering and cluster sharding, Akka makes sure there is only one persistent actor in the cluster across all instances of the service.

  1. Describe one possible data model that could be used to make the Manager to the persistent entity.
trait ManagerCommand
final case class AddCookies(count: Int) extends ManagerCommand with ReplyType[Int]
final case class RemoveCookies(count: Int) extends ManagerCommand with ReplyType[Int]

trait ManagerEvent
final case class NumberOfCookiesChanged(count: Int) extends ManagerEvent with AggregateEvent[NumberOfCookiesChanged] {
override def aggregateTag: AggregateEventTag[NumberOfCookiesChanged] = AggregateEventTag[NumberOfCookiesChanged]("NumberOfCookiesChanged")
}
sealed trait ManagerState {
def cookies: Int
}
final case class MixingState(cookies: Int) extends ManagerState
  1. Outline an alternative way to implement the Baker service.

The Baker service could also be implemented message passing style similar to the Chef service.

  1. Can you identify a design bug in the current implementation of the Chef?

The Chef does not trigger mixing for unbalanced mixing events after recovery.

  1. The Manager implementation stores a number of cookies in memory and this number will be lost at the moment the service restarts. Can you name another reason why it is a bad idea to hold the number of cookies in a local variable?

In a production environment, there will be multiple instances of the service running. Each of them will have its own internal state.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.186.46