7. 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
21. ● Construire un système de microservices
● Basé sur les principes réactifs
● Intégration dans l’environnement de développement
Overview - Objectifs
22. ● Coeur du framework est écrit en Scala
● API en Java 8
● Bientôt une version Scala
Overview - Quel langage ?
25. ● Description de l’API basée sur une interface
● Request / response synchrone
● Message asynchrone - Streaming
Fonctionnalités - Service API
26. 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));
}
}
27. ● 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
28. 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();
}
}
29. ● ConductR pour la production
● Scalabilité
● Déploiement
● Monitoring
Fonctionnalités - Environnement Production
30. ● 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
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