Lagom, reactive framework(paris jug2017)

35
Lagom Reactive microservices framework Lagom Reactive microservices framework Fabrice Sznajderman - @fsznajderman 14 mars 2017 @lagom

Transcript of Lagom, reactive framework(paris jug2017)

Page 1: Lagom, reactive framework(paris jug2017)

LagomReactive microservices framework

LagomReactive microservices framework

Fabrice Sznajderman - @fsznajderman14 mars 2017 @lagom

Page 2: Lagom, reactive framework(paris jug2017)

Roadmap

● Microservices / Event Sourcing / CQRS

● Overview

● Principales fonctionnalités

● Live coding

● Next step

Page 3: Lagom, reactive framework(paris jug2017)

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

Page 4: Lagom, reactive framework(paris jug2017)

Core concepts

Microservices / Event Sourcing / CQRS

Page 5: Lagom, reactive framework(paris jug2017)

Microservices

Page 6: Lagom, reactive framework(paris jug2017)

Microservices

Page 7: Lagom, reactive framework(paris jug2017)

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

Page 8: Lagom, reactive framework(paris jug2017)

Microservices

Page 9: Lagom, reactive framework(paris jug2017)

Event Sourcing

Page 10: Lagom, reactive framework(paris jug2017)

Approche traditionnelle

Page 11: Lagom, reactive framework(paris jug2017)

Event sourcing

Page 12: Lagom, reactive framework(paris jug2017)

CQRS

Page 13: Lagom, reactive framework(paris jug2017)

CQRS

● Command● Query● Responsability● Segregation

Page 14: Lagom, reactive framework(paris jug2017)

Approche traditionelle

Page 15: Lagom, reactive framework(paris jug2017)

Write (Command) :Event log. Modèle simple.

Read (Query) : Dénormalisation, scalabillité, performance...

CQRS

Page 16: Lagom, reactive framework(paris jug2017)

CQRS

Page 17: Lagom, reactive framework(paris jug2017)

LagomOverview / Principales fonctionnalités / Live coding

Page 18: Lagom, reactive framework(paris jug2017)

Overview

Page 19: Lagom, reactive framework(paris jug2017)

● Construire un système de microservices

● Basé sur les principes réactifs

● Intégration dans l’environnement de développement

Overview - Objectifs

Page 20: Lagom, reactive framework(paris jug2017)

● Coeur du framework est écrit en Scala

● API en Java 8

● API en Scala 2.11.*

Overview - Quel langage ?

Page 21: Lagom, reactive framework(paris jug2017)

● 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

Page 22: Lagom, reactive framework(paris jug2017)

Principales fonctionnalités

Page 23: Lagom, reactive framework(paris jug2017)

● Description de l’API basée sur une interface

● Request / response synchrone

● Message asynchrone - Streaming

Fonctionnalités - Service API

Page 24: Lagom, reactive framework(paris jug2017)

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)); }}

Page 25: Lagom, reactive framework(paris jug2017)

● 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

Page 26: Lagom, reactive framework(paris jug2017)

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(); }}

Page 27: Lagom, reactive framework(paris jug2017)

● ConductR pour la production

● Scalabilité

● Déploiement

● Monitoring

Fonctionnalités - Environnement Production

Page 28: Lagom, reactive framework(paris jug2017)

● Consul / Zookeeper

● Treafik / HaProxy

● Docker

● Monitoring (traefik)

Fonctionnalités - Environnement Production (free)

Page 29: Lagom, reactive framework(paris jug2017)

● 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

Page 30: Lagom, reactive framework(paris jug2017)

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

Page 31: Lagom, reactive framework(paris jug2017)

Structure d’un projet - Overview

Page 32: Lagom, reactive framework(paris jug2017)

Live coding

Page 33: Lagom, reactive framework(paris jug2017)

● Hello World

● Calculator - ConductR

● Sloak - CQRS / Events Sourcing

● Déploiement sans conductR - Etat des lieux

Roadmap - Live coding

Page 34: Lagom, reactive framework(paris jug2017)

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

Page 35: Lagom, reactive framework(paris jug2017)

Merci!