WF Reactive System (2)
In previous post (available here.) we gave a try to Lagom and reactive microservices. We started by creating a sample Weather forecast App with three reactive microservices. Starting by the preparation and setup of tools needed, and the creation of service API and its implementation for the producer service that will deal with request that User will generate from a future UI (We’ll have the chance of play with Play framework).
In this part, we’ll create a consumer API and its implementation.
Part IV: Consumer API
- Open the project in the IDE and create a copy of the producer module and rename it as wf-consumer-api.
- Add this module to build.sbt.
- Go to model and refactor (rename):
- WFMessage to WeatherForecasting.
- Modify the Service API:
- Remove topic
- Change descriptor name to «wfconsumer».
- Define functions to:
- Get Top Ten Weather Forecasts.
- Get one (the first) Weather Forecast. (findOneWFData)
- Get the latest Weather Forecast. (latestWF)
- Define the rest endpoints URI in descriptor to our consumer.
- Get for (findTopTenWFData)
- Get for (latestWF)
- Get for (latestWF)
- Remove the withTopics and withAutoAcl options of descriptor.
Part V: Implementing the Consumer Services
- Create model package and create the case class WeatherForecasting.
- Create companion object for Json serialization format.
- Modify the consumer’s WFCommand
- Extend ReplyType[T] (previously [Done])
- Create SaveNewWF case class and its companion object.
- Delete WF case class and its companion object.
- Rename WFSerializerRegistry to WFConsumerSerializerRegistry
- Add class to WFSerializerRegistry.
- EventTag does not require modification.
- Modify WFEvent. Refactor WFChanged to WFSaved and change its signature to receive a WeatherForecast object as parameter.
- Remove onReadOnlyCommand
- In onEvent change case and add message for detail of message.
- Modify WFEntity to implement saving messages to handle onCommand and on Event operations for all WFEvents. It is very important to note that this Entity manages components of CQRS/ES architecture.
- Modify WFLoader.
- Rename it to WFConsumerLoader
- Override load and loadDEvMode.
- Change abstract class WFConsumerApplication
- Add lazy vals for binding WFService client wfService and message repository (WFRepository).
- Override jsonSerializerRegistry.
- Add persistentEntityRegistry
- Add readSide.register(wire[WFEventProcessor])
- Implement WFRepository.
- Create package repositories.
- Create private [impl] class WFRepository its constructor receives CassandraSession.
- Implement method for data fetching according to rest endpoints:
- fetchWFData: to retrieve 10 elements
- fetchOneWFData: to retrieve one (first) register.
- Implement Consumer Service
- Create class WFConsumerServiceImpl.
- Override findTopTenWFData and findOneWFData
- change Loader in resources/application.conf
- Add binds to build.sbt.
In the next post, we’ll create a simple frontend for our Reactive System.
Trackbacks / Pingbacks