trivadis techevent 2016 introduction to lagom - another microservice-based framework by thomas graf
TRANSCRIPT
BASLE BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA
HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH
Introduction to Lagomanother microservice-based framework
Thomas GrafConsultant
Agenda
Introduction to Lagom2 9/23/2016
1. What is Lagom?
Overview
Running in Produktion
2. Lagom Framework
Features
Under the hood / Future Roadmap
Lagom design philosophy / Lagom core concepts
3. Lagom API
Anatomy of a Lagom project
ServiceCall explained
4. Demo
Introduction to Lagom3 9/23/2016
What is Lagom?
Overview
Introduction to Lagom4 9/23/2016
Lightbend, formerly Typesafe
Open Source / most part in Scala
Swedish word [lah-gome]
– enough, sufficient, adequate, just right just the right amount
Running in Production
Introduction to Lagom5 9/23/2016
sbt-native packager is used to produce zip, MSI, RPM, Docker
Lightbend ConductR* (container orchestration tool)
– Free during development
Lightbend Reactive Platform
– Split Brain Resolver (for Akka cluster)
– Lightbend Monitoring
– Requires a Lightbend subscription
ConductR* / Reactive Plattform
Introduction to Lagom6 9/23/2016
source: http://thenewstack.io/lightbends-lagom-offers-microservice-framework-java-developers/
Service Locator / Gateway
Introduction to Lagom7 9/23/2016
Service Locator
– discovers services and allows to communicate
Service Gateway
– Querying different services
– No direct access to endpoint
– Acts as a proxy; services have a different port
Result: running on the same port and assigned constantly
Idea: ConductR* is scalable because of Service Gateway
Similar products like ConductR*
Introduction to Lagom8 9/23/2016
Cloud Foundry
Kubernetes / Vert.x
…
Introduction to Lagom9 9/23/2016
Lagom Framework
Features
Introduction to Lagom10 9/23/2016
Lagom is a framework for creating microservice-based systems. It offers four main
features:
Service API
Persistence API
Development environment
Production environment
(introduction well documented)
Principles
Introduction to Lagom11 9/23/2016
Each service owns its data
Only the service has direct access to the DB
Its advocated to use Event Sourcing (ES) and CQRS
– Out of the box / optimized
– Highly opinionated on that subject
ES / CQRS
Introduction to Lagom12 9/23/2016
Event Sourcing (ES)
– Capture all state’s changes as events
Command Query Responsibility Segregation (CQRS)
– separate models for write and read
Idea: substitute for transactions in distributed systems
1 2 3 n…
Benefits of ES / CQRS
Introduction to Lagom13 9/23/2016
Allows you to time travel
Audit log
Future business opportunities
No need for ORM
No database migration script, ever
Performance & Scalability
Testability & Debuggability
Under the hood
Introduction to Lagom14 9/23/2016
Current version 1.0.0
– Java API, but no Scala API yet
sbt build tool (developer) / Activator 1.3.10
Play 2.5
Akka 2.4 (clustering, streams, persistence)
Cassandra (default data store)
Jackson (JSON serialization)
Guice (Dependency Injection)
Architectural concepts: immutability, circuit breakers, Event Sourcing (ES) /
CQRS (Command Query Responsibility Segregation)
Future Roadmap
Introduction to Lagom15 9/23/2016
Maven support
Support for other cluster orchestration tools
– new project / module for Kubernetes
Swagger integration
– Which also removes binary coupling!
Support for writing integration tests
Message broker integration
Scala API
Lagom design philosophy
Introduction to Lagom16 9/23/2016
Asynchronous by default, both IO and communication
Reactive Microservice Architecture, report by Jonas Bonér
Distributed persistence
High productivity
Lagom core concepts
Introduction to Lagom17 9/23/2016
Tools and APIs
Good architecture
Microservices concepts and best practice
Introduction to Lagom18 9/23/2016
Lagom API
Anatomy of a Lagom project
Introduction to Lagom19 9/23/2016
sbt build
Scala 2.11 and JDK8
Each service definition is split into two sbt projects:
– API
– Implementation
ServiceCall explained
Introduction to Lagom20 9/23/2016
ServiceCall can be invoked when consuming a service:
– Request: type of incoming request message (e.g. String)
– Response: type of outgoing response message (e.g. String)
JSON is the default serialization format for request/response messages
There are two kinds of request/response messages:
– Strict
– Streamed
interface ServiceCall<Request, Response> {CompletionStage<Response> invoke(Request request);
}
Strict Messages
Introduction to Lagom21 9/23/2016
ServiceCall<FriendId, NotUsed> addFriend(String userId);
@Overridedefault Descriptor descriptor() {return named("friendservice").withCalls(
pathCall("/api/users/:userId/friends", this::addFriend),).withAutoAcl(true);
}
Strict messages are fully buffered into memory
– e.g. create a user after transaction information are not needed anymore
Streamed Messages
Introduction to Lagom22 9/23/2016
A streamed message is of type Source (an Akka streams API)
– e.g. chat stream message and forget; cached on client side
It allows asynchronous streaming and handling of messages
Lagom will select transport protocol (currently WebSockets)
ServiceCall<NotUsed, Source<Chirp, ?>> getLiveActivityStream(String userId);
@Overridedefault Descriptor descriptor() {
return named("activityservice").withCalls(pathCall("/api/activity/:userId/live", this::getLiveActivityStream)
).withAutoAcl(true);}
Event Sourcing: Write Side
Introduction to Lagom23 9/23/2016
Create your own Command and Event classes
– Command: system has to do, may trigger an event
– Event: system has done (past), is stored
Subclass PersistentEntity
– Define Command and Event handlers
– Can be accessed from anywhere in the cluster
Event Sourcing: Read Side
Introduction to Lagom24 9/23/2016
Tightly integrated with Cassandra
Create the query tables:
– Subclass CassandraReadSideProcessor
– Consumers events produced by the PersistentEntity and updates tables in
Cassandra optimized for queries
Retrieving data: Cassandra Query Language
– e.g., SELECT id, title FROM postsummary
Introduction to Lagom25 9/23/2016
Demo
Chirper
Introduction to Lagom26 9/23/2016
Friend: handels users and relation among them.
Chirp: allows to create and retrieve
chrips (i.e., messages).
ActivityStream: allows to retrieve
history or live chrips of a user
Frontend: Play + Javascript UI
Introduction to Lagom27 9/23/2016
Lagom: http://www.lagomframework.com/
Lagom Git: https://github.com/lagom/lagom
Lagom Chriper: https://github.com/lagom/activator-lagom-java-chirper
Report by Jonas Bonér, free book, Reactive Service Architecture:
http://www.oreilly.com/programming/free/reactive-microservices-architecture.html
Session Feedback – now
TechEvent September 201629 09.09.2016
Please use the Trivadis Events Mobile App to give session feedback
Use "My schedule" if you registered for this session
Otherwise use "Agenda" and the search function
If the mobile App does not work (or if you have a Windows Phone) use your Mobile
Browser
– URL: http://trivadis.quickmobileplatform.eu/
– Username: <your_loginname> (like svv)
– Password: sent by mail...