Post on 05-Apr-2017
LagomReactive microservices framework
LagomReactive microservices framework
Fabrice Sznajderman - @fsznajderman14 mars 2017 @lagom
Roadmap
● Microservices / Event Sourcing / CQRS
● Overview
● Principales fonctionnalités
● Live coding
● Next step
Qui vous parle?
Fabrice Sznajderman
● Développeur Scala @Zenika○ Formateur Java/Scala
● Contributeur (Lagom, JHipster, rapture)
● Bagger (Scala - Lagom - SBT)
● Co-organisateur conférence ScalaIO
Core concepts
Microservices / Event Sourcing / CQRS
Microservices
Microservices
Microservices
Microservices-Based Architecture is a simple concept: it advocates creating a system from a collection of small, isolated services, each of which owns their data, and is independently isolated, scalable and resilient to failure. Services integrate with other services in order to form a cohesive system that’s far more flexible than the typical enterprise systems we build today.
Reactive Microservices Architecture: Design Principles for Distributed Systems - jonas Boner http://www.oreilly.com/programming/free/reactive-microservices-architecture.html
Microservices
Event Sourcing
Approche traditionnelle
Event sourcing
CQRS
CQRS
● Command● Query● Responsability● Segregation
Approche traditionelle
Write (Command) :Event log. Modèle simple.
Read (Query) : Dénormalisation, scalabillité, performance...
CQRS
CQRS
LagomOverview / Principales fonctionnalités / Live coding
Overview
● Construire un système de microservices
● Basé sur les principes réactifs
● Intégration dans l’environnement de développement
Overview - Objectifs
● Coeur du framework est écrit en Scala
● API en Java 8
● API en Scala 2.11.*
Overview - Quel langage ?
● Java 8 & Scala● (Immutables)● SBT / Maven● Jackson● Cassandra / JDBC*● Message broker* (Kafka)● Play framework● Akka : persistence, pub/Sub, cluster● Akka Stream
Overview - Composants techniques
*depuis la version 1.2.0
Principales fonctionnalités
● Description de l’API basée sur une interface
● Request / response synchrone
● Message asynchrone - Streaming
Fonctionnalités - Service API
Fonctionnalités - Service API
public interface HelloWorldService extends Service {
ServiceCall<NotUsed, String> hi(String name);
@Override default Descriptor descriptor() { return named("helloWorld").withCalls(restCall(Method.GET, "/hello/:name", this::hi)); }}
● Garde l’état courant en mémoire
● Capture et persiste tous les changements d’états (events)
● CQRS Read side (query & update)
● Clustering / sharding
● CassandraSession
Fonctionnalités - Persistance API
Fonctionnalités - Persistance APIpublic class UserEntity extends PersistentEntity<UserCommand, UserEvent, UsersState> { @Override public Behavior initialBehavior(Optional<UsersState> snapshotState) { BehaviorBuilder b = newBehaviorBuilder( snapshotState.orElse(new UsersState(UsersList.builder().build(), "now")));
b.setCommandHandler( UserCommand.SignIn.class, (cmd, ctx) -> ctx.thenPersist(new UserSigned(cmd.name), evt -> ctx.reply(Done.getInstance())));
b.setEventHandler( UserSigned.class, evt -> { /*get information from event and update state*/ final UsersList newState = /*current update state*/; return new UsersState(newState, LocalDateTime.now().toString()); });
b.setReadOnlyCommandHandler(UserCommand.ListUsers.class, (cmd, ctx) -> ctx.reply(state().users.getUsers())); return b.build(); }}
● ConductR pour la production
● Scalabilité
● Déploiement
● Monitoring
Fonctionnalités - Environnement Production
● Consul / Zookeeper
● Treafik / HaProxy
● Docker
● Monitoring (traefik)
Fonctionnalités - Environnement Production (free)
● Intégration dans l’IDE
● Plusieurs services fournis par défaut
● Rechargement du code à chaud
● Une seule commande pour démarrer le système
Fonctionnalités - Environnement de développement
Structure d’un projet - Démarrage du système
● Une commande pour lancer le système : ○ sbt runAll / mvn runAll
● Plusieurs services activés au démarrage : ○ Cassandra
○ Service locator
○ Service gateway
○ Tous les services déclarés
Structure d’un projet - Overview
Live coding
● Hello World
● Calculator - ConductR
● Sloak - CQRS / Events Sourcing
● Déploiement sans conductR - Etat des lieux
Roadmap - Live coding
Next step
● [Documentation] http://www.lagomframework.com
● [Gitter] https://gitter.im/lagom/lagom
● [Github] https://github.com/lagom/lagom
● [Plugin] https://github.com/Fabszn/scaffolding-plugin-lagom
● [Communauté] https://github.com/Lagom-community
Merci!