trivadis techevent 2016 introduction to lagom - another microservice-based framework by thomas graf
TRANSCRIPT
![Page 1: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/1.jpg)
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
![Page 2: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/2.jpg)
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
![Page 3: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/3.jpg)
Introduction to Lagom3 9/23/2016
What is Lagom?
![Page 4: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/4.jpg)
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
![Page 5: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/5.jpg)
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
![Page 6: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/6.jpg)
ConductR* / Reactive Plattform
Introduction to Lagom6 9/23/2016
source: http://thenewstack.io/lightbends-lagom-offers-microservice-framework-java-developers/
![Page 7: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/7.jpg)
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
![Page 8: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/8.jpg)
Similar products like ConductR*
Introduction to Lagom8 9/23/2016
Cloud Foundry
Kubernetes / Vert.x
…
![Page 9: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/9.jpg)
Introduction to Lagom9 9/23/2016
Lagom Framework
![Page 10: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/10.jpg)
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)
![Page 11: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/11.jpg)
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
![Page 12: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/12.jpg)
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…
![Page 13: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/13.jpg)
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
![Page 14: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/14.jpg)
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)
![Page 15: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/15.jpg)
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
![Page 16: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/16.jpg)
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
![Page 17: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/17.jpg)
Lagom core concepts
Introduction to Lagom17 9/23/2016
Tools and APIs
Good architecture
Microservices concepts and best practice
![Page 18: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/18.jpg)
Introduction to Lagom18 9/23/2016
Lagom API
![Page 19: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/19.jpg)
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
![Page 20: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/20.jpg)
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);
}
![Page 21: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/21.jpg)
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
![Page 22: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/22.jpg)
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);}
![Page 23: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/23.jpg)
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
![Page 24: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/24.jpg)
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
![Page 25: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/25.jpg)
Introduction to Lagom25 9/23/2016
Demo
![Page 26: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/26.jpg)
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
![Page 27: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/27.jpg)
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
![Page 29: Trivadis TechEvent 2016 Introduction to Lagom - another microservice-based framework by Thomas Graf](https://reader031.vdocuments.us/reader031/viewer/2022021502/5886201f1a28ab8f2c8b4e97/html5/thumbnails/29.jpg)
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...