Lagom
Reactive microservices framework
Lagom
Reactive microservices framework
Fabrice Sznajderman - @fsznajderman
24 novembre 2016 @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 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 - James Boner
http://www.oreilly.com/programming/free/reactive-microservices-architecture.html
Microservices
Event Sourcing
Approche traditionnelle
Approche traditionnelle
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
Lagom
Overview / 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
● Bientôt une version Scala
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 API
public 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
● 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
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
Merci!

Lagom, reactive framework(chtijug2016)

  • 1.
    Lagom Reactive microservices framework Lagom Reactivemicroservices framework Fabrice Sznajderman - @fsznajderman 24 novembre 2016 @lagom
  • 2.
    Roadmap ● Microservices /Event Sourcing / CQRS ● Overview ● Principales fonctionnalités ● Live coding ● Next step
  • 3.
    Qui vous parle? FabriceSznajderman ● Développeur Scala @Zenika ○ Formateur Java/Scala ● Contributeur (Lagom, JHipster, rapture) ● Bagger (Scala - Lagom - SBT) ● Co-organisateur ScalaIO
  • 4.
    Core concepts Microservices /Event Sourcing / CQRS
  • 5.
  • 6.
  • 7.
    Microservices Microservices-Based Architecture isa 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 - James Boner http://www.oreilly.com/programming/free/reactive-microservices-architecture.html
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    CQRS ● Command ● Query ●Responsability ● Segregation
  • 16.
  • 17.
    Write (Command) : Eventlog. Modèle simple. Read (Query) : Dénormalisation, scalabillité, performance... CQRS
  • 18.
  • 19.
    Lagom Overview / Principalesfonctionnalités / Live coding
  • 20.
  • 21.
    ● Construire unsystème de microservices ● Basé sur les principes réactifs ● Intégration dans l’environnement de développement Overview - Objectifs
  • 22.
    ● Coeur duframework est écrit en Scala ● API en Java 8 ● Bientôt une version Scala Overview - Quel langage ?
  • 23.
    ● 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
  • 24.
  • 25.
    ● Description del’API basée sur une interface ● Request / response synchrone ● Message asynchrone - Streaming Fonctionnalités - Service API
  • 26.
    Fonctionnalités - ServiceAPI 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)); } }
  • 27.
    ● Garde l’étatcourant en mémoire ● Capture et persiste tous les changements d’états (events) ● CQRS Read side (query & update) ● Clustering / sharding ● CassandraSession Fonctionnalités - Persistance API
  • 28.
    Fonctionnalités - PersistanceAPI public 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(); } }
  • 29.
    ● ConductR pourla production ● Scalabilité ● Déploiement ● Monitoring Fonctionnalités - Environnement Production
  • 30.
    ● Intégration dansl’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
  • 31.
    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
  • 32.
  • 33.
    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
  • 34.