SlideShare une entreprise Scribd logo
1  sur  21
Introduction to Lagom
Framework
By :-
Deepak Mehra
Software Consultant
KNOLDUS SOFTWARE LLP
By :-
Deepak Mehra
Software Consultant
KNOLDUS SOFTWARE LLP
Agenda
● Monolithic Application vs Microservices
● What is Lagom Framework?
● Exploring Lagom
● CQRS AND EVENT SOURCING
● Testing in Lagom
● Demo
Monolithic vs MicroService
MicroServices
Benefits
● Separate development and deployment. One service
can be developed, built and tested without affecting other
services or the entire application.
● Scaling and resilience. In a microservices architecture, you
can scale only those services that need it, rather than the whole
application.
● Independent tech stacks. Because each component is
separate from all other components, services can use their own
technology stacks without having to alter the way the other
services or the entire application are built.
Implement Microservice using
various framework
● JAX-RS
● KumuluzEE
● Spring Boot
● AWS Lambda
What is Lagom Framework?
Lagom - The Reactive
Microservices Framework
Lagom is a new open source framework for architecting microservices. Lagom helps
you build microservices as systems — Reactive systems, to be precise — so that your
microservices are elastic, resilient and scalable from within.
Lagom is built on top of Play, and its goal is more specific than Play. In particular, it
adds an API for describing/implementing services and a CQRS-based persistence API
on top of the APIs Play already has.
Lagom - The Reactive
Microservices Framework
Design Philosophy
Lagom’s design rests on the following principles:
●
Message-Driven and Asynchronous: Built upon Akka Stream for asynchronous streaming
and the JDK8 CompletionStage API.
● Distributed persistence: Lagom favours distributed persistence patterns using Event
Sourcing with Command Query Responsibility Segregation (CQRS).
● Developer productivity: Starting all microservices with a single command, code hot
reloading and expressive service interface declarations are some examples of Lagom’s high
emphasis on developer productivity.
Lagom - The Reactive
Microservices Framework
Build Blocks
The Lagom framework acts as an abstraction layer upon several Lightbend frameworks
and consists of the following core technologies and frameworks:
● Scala
● Java
● Play Framework
● Akka and Akka Persistence
● SBT
● Cassandra
● Guice
● ConductR
Lagom - The Reactive
Microservices Framework
GETTING STARTED WITH LAGOM
Prerequisites for using Lagom with Maven include:
● JDK 8
● Maven 3.3 or higher
Creating a new Lagom application is as simple as using the following command:
mvn archetype:generate -DarchetypeGroupId=com.lightbend.lagom -DarchetypeArtifactId=maven-
archetype-lagom-java -DarchetypeVersion=1.3.4
Maven prompts you for:
groupId — typically something like com.example.
artifactId — becomes the top-level folder name, for example, my-first-project.
version — the version for your project, press Enter to accept the default.
package — defaults to the same value as the groupId
Lagom - The Reactive
Microservices Framework
Now execute command mvn lagom:runAll
This command starts a Cassandra server, service locator and service gateway. Each of our
microservices is started in parallel while also registering them in the service locator. Note that the
ports are assigned to each microservice by an algorithm and are consistent even on different
machines. The possibility to assign a specific port is available though.
Similar to Play Framework, Lagom also supports code hot reloading allowing you to make changes
in the code and immediately seeing these changes live without having to restart anything. A
feature we’re very fond of. In general, a restart is only required when adding a new microservice
API and implementation module in the project.
Lagom - The Reactive
Microservices Framework
ANATOMY OF A LAGOM PROJECT
helloworld-api → Microservice API submodule
└ src/main/java → Java source code interfaces with model objects
helloworld-impl → Microservice implementation submodule
└ logs → Logs of the microservice
└ src/main/java → Java source code implementation of the API submodule
└ src/main/resources → Contains the microservice application config
└ src/test/java → Java source code unit tests
logs → Logs of the Lagom system
Lagom - The Reactive
Microservices Framework
Example of a MicroService
In order to write a new microservice you create a new API and implementation project. In the API project you define
the interface of your microservice:
public interface HelloService extends Service {
ServiceCall<String, NotUsed, String> hello();
ServiceCall<String, GreetingMessage, String> useGreeting();
@Override
default Descriptor descriptor() {
return named("helloservice").with(
restCall(Method.GET, "/api/hello/:id", hello()),
restCall(Method.POST, "/api/hello/:id", useGreeting())
).withAutoAcl(true);
}
}
Lagom - The Reactive
Microservices Framework
In the implementation submodule we implement our API’s interface.
public class HelloServiceImpl implements HelloService {
@Override
public ServiceCall<String, NotUsed, String> hello() {
return (id, request) -> {
CompletableFuture.completedFuture("Hello, " + id);
};
}
@Override
public ServiceCall<String, GreetingMessage, String> useGreeting() {
return (id, request) -> {
CompletableFuture.completedFuture(request.message + id);
};
}
}
Lagom - The Reactive
Microservices Framework
public class HelloServiceModule extends AbstractModule implements
ServiceGuiceSupport {
@Override
protected void configure() {
bindServices(serviceBinding(HelloService.class, HelloServiceImpl.class));
}
}
CQRS AND ES
Event sourcing and CQRS (Command Query Responsibility Segregation) are fundamental
concepts behind Lagom’s support for services that store information.
Why Event Sourcing?
If a service stores information, a core principle is that each service should own its data and it
is only the service itself that should have direct access to the database. Other services must
use the Service API to interact with the data. There must be no sharing of databases across
different services since that would result in a too tight coupling between the services.
To achieve this, Lagom’s persistence module advocates the use of event sourcing and
CQRS (Command Query Responsibility Segregation).
Testing in Lagom
@BeforeClass
public static void setUp() {
server = ServiceTest.startServer(ServiceTest.defaultSetup());
}
@AfterClass
public static void tearDown() {
if (server != null) {
server.stop();
server = null;
}
}
Testing in Lagom
@Test
public void shouldRespondHello() throws Exception {
// given
HelloService service = server.client(HelloService.class);
// when
String hello = service.hello().invoke("Yannick",
NotUsed.getInstance()).toCompletableFuture().get(5, SECONDS);
// then
assertEquals("Hello, Yannick", hello);
}
Demo
References
● http://www.slashroot.in/difference-between-monolith
● https://www.lagomframework.com
● https://ordina-jworks.github.io/microservices/2016/0
Thank You

Contenu connexe

Tendances

Tendances (20)

Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - Plansoft
 
Spring cloud for microservices architecture
Spring cloud for microservices architectureSpring cloud for microservices architecture
Spring cloud for microservices architecture
 
Java EE Microservices
Java EE MicroservicesJava EE Microservices
Java EE Microservices
 
MuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLB
MuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLBMuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLB
MuleSoft Surat Live Demonstration Virtual Meetup#1 - Anypoint VPC VPN and DLB
 
'How to build your first micro frontend in a matter of minutes' by Vladlen Fe...
'How to build your first micro frontend in a matter of minutes' by Vladlen Fe...'How to build your first micro frontend in a matter of minutes' by Vladlen Fe...
'How to build your first micro frontend in a matter of minutes' by Vladlen Fe...
 
Baltimore july2021 final
Baltimore july2021 finalBaltimore july2021 final
Baltimore july2021 final
 
Custom MuleSoft connector using Java SDK
Custom MuleSoft connector using Java SDKCustom MuleSoft connector using Java SDK
Custom MuleSoft connector using Java SDK
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with java
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Javantura v4 - Support SpringBoot application development lifecycle using Ora...
Javantura v4 - Support SpringBoot application development lifecycle using Ora...Javantura v4 - Support SpringBoot application development lifecycle using Ora...
Javantura v4 - Support SpringBoot application development lifecycle using Ora...
 
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
 
MuleSoft meetup__houston #13
MuleSoft meetup__houston #13MuleSoft meetup__houston #13
MuleSoft meetup__houston #13
 
Warsaw MuleSoft Meetup #6 - CI/CD
Warsaw MuleSoft Meetup  #6 - CI/CDWarsaw MuleSoft Meetup  #6 - CI/CD
Warsaw MuleSoft Meetup #6 - CI/CD
 
MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...
MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...
MuleSoft Surat Virtual Meetup#6 - MuleSoft API Led Connectivity, SEDA and MUn...
 
Moscow MuleSoft meetup May 2021
Moscow MuleSoft meetup May 2021Moscow MuleSoft meetup May 2021
Moscow MuleSoft meetup May 2021
 
Securing microservices continuous delivery using grafeas and kritis
Securing microservices continuous delivery using grafeas and kritisSecuring microservices continuous delivery using grafeas and kritis
Securing microservices continuous delivery using grafeas and kritis
 
Intro to spring cloud &microservices by Eugene Hanikblum
Intro to spring cloud &microservices by Eugene HanikblumIntro to spring cloud &microservices by Eugene Hanikblum
Intro to spring cloud &microservices by Eugene Hanikblum
 
Riyadh Meetup4- Sonarqube for Mule 4 Code review
Riyadh Meetup4- Sonarqube for Mule 4 Code reviewRiyadh Meetup4- Sonarqube for Mule 4 Code review
Riyadh Meetup4- Sonarqube for Mule 4 Code review
 
MuleSoft_Meetup_#6_Chandigarh_April_2021
MuleSoft_Meetup_#6_Chandigarh_April_2021MuleSoft_Meetup_#6_Chandigarh_April_2021
MuleSoft_Meetup_#6_Chandigarh_April_2021
 
Flux is incubating + the road ahead
Flux is incubating + the road aheadFlux is incubating + the road ahead
Flux is incubating + the road ahead
 

Similaire à Introduction to Lagom Framework

Similaire à Introduction to Lagom Framework (20)

Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice framework
 
A Go-Through With Lagom Application
A Go-Through With Lagom ApplicationA Go-Through With Lagom Application
A Go-Through With Lagom Application
 
Intoduction to lagom framework
Intoduction to lagom frameworkIntoduction to lagom framework
Intoduction to lagom framework
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
All About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksAll About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice Frameworks
 
Global Logic sMash Overview And Experiences
Global Logic   sMash  Overview And  ExperiencesGlobal Logic   sMash  Overview And  Experiences
Global Logic sMash Overview And Experiences
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
Microservice Workshop Hands On
Microservice Workshop Hands On Microservice Workshop Hands On
Microservice Workshop Hands On
 
Developing microservices with Java and applying Spring security framework and...
Developing microservices with Java and applying Spring security framework and...Developing microservices with Java and applying Spring security framework and...
Developing microservices with Java and applying Spring security framework and...
 
Spring boot microservice metrics monitoring
Spring boot   microservice metrics monitoringSpring boot   microservice metrics monitoring
Spring boot microservice metrics monitoring
 
Spring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics MonitoringSpring Boot - Microservice Metrics Monitoring
Spring Boot - Microservice Metrics Monitoring
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applications
 
Ultimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on KubernetesUltimate Guide to Microservice Architecture on Kubernetes
Ultimate Guide to Microservice Architecture on Kubernetes
 
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
MuleSoft Surat Virtual Meetup#6 - MuleSoft Project Template Using Maven Arche...
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Cloud APIs Overview Tucker
Cloud APIs Overview   TuckerCloud APIs Overview   Tucker
Cloud APIs Overview Tucker
 
Java Development on Bluemix
Java Development on BluemixJava Development on Bluemix
Java Development on Bluemix
 
Build12 factorappusingmp
Build12 factorappusingmpBuild12 factorappusingmp
Build12 factorappusingmp
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
 
Microservices with kubernetes @190316
Microservices with kubernetes @190316Microservices with kubernetes @190316
Microservices with kubernetes @190316
 

Plus de Knoldus Inc.

Plus de Knoldus Inc. (20)

Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 

Dernier

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Dernier (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 

Introduction to Lagom Framework

  • 1. Introduction to Lagom Framework By :- Deepak Mehra Software Consultant KNOLDUS SOFTWARE LLP By :- Deepak Mehra Software Consultant KNOLDUS SOFTWARE LLP
  • 2. Agenda ● Monolithic Application vs Microservices ● What is Lagom Framework? ● Exploring Lagom ● CQRS AND EVENT SOURCING ● Testing in Lagom ● Demo
  • 4. MicroServices Benefits ● Separate development and deployment. One service can be developed, built and tested without affecting other services or the entire application. ● Scaling and resilience. In a microservices architecture, you can scale only those services that need it, rather than the whole application. ● Independent tech stacks. Because each component is separate from all other components, services can use their own technology stacks without having to alter the way the other services or the entire application are built.
  • 5. Implement Microservice using various framework ● JAX-RS ● KumuluzEE ● Spring Boot ● AWS Lambda
  • 6. What is Lagom Framework?
  • 7. Lagom - The Reactive Microservices Framework Lagom is a new open source framework for architecting microservices. Lagom helps you build microservices as systems — Reactive systems, to be precise — so that your microservices are elastic, resilient and scalable from within. Lagom is built on top of Play, and its goal is more specific than Play. In particular, it adds an API for describing/implementing services and a CQRS-based persistence API on top of the APIs Play already has.
  • 8. Lagom - The Reactive Microservices Framework Design Philosophy Lagom’s design rests on the following principles: ● Message-Driven and Asynchronous: Built upon Akka Stream for asynchronous streaming and the JDK8 CompletionStage API. ● Distributed persistence: Lagom favours distributed persistence patterns using Event Sourcing with Command Query Responsibility Segregation (CQRS). ● Developer productivity: Starting all microservices with a single command, code hot reloading and expressive service interface declarations are some examples of Lagom’s high emphasis on developer productivity.
  • 9. Lagom - The Reactive Microservices Framework Build Blocks The Lagom framework acts as an abstraction layer upon several Lightbend frameworks and consists of the following core technologies and frameworks: ● Scala ● Java ● Play Framework ● Akka and Akka Persistence ● SBT ● Cassandra ● Guice ● ConductR
  • 10. Lagom - The Reactive Microservices Framework GETTING STARTED WITH LAGOM Prerequisites for using Lagom with Maven include: ● JDK 8 ● Maven 3.3 or higher Creating a new Lagom application is as simple as using the following command: mvn archetype:generate -DarchetypeGroupId=com.lightbend.lagom -DarchetypeArtifactId=maven- archetype-lagom-java -DarchetypeVersion=1.3.4 Maven prompts you for: groupId — typically something like com.example. artifactId — becomes the top-level folder name, for example, my-first-project. version — the version for your project, press Enter to accept the default. package — defaults to the same value as the groupId
  • 11. Lagom - The Reactive Microservices Framework Now execute command mvn lagom:runAll This command starts a Cassandra server, service locator and service gateway. Each of our microservices is started in parallel while also registering them in the service locator. Note that the ports are assigned to each microservice by an algorithm and are consistent even on different machines. The possibility to assign a specific port is available though. Similar to Play Framework, Lagom also supports code hot reloading allowing you to make changes in the code and immediately seeing these changes live without having to restart anything. A feature we’re very fond of. In general, a restart is only required when adding a new microservice API and implementation module in the project.
  • 12. Lagom - The Reactive Microservices Framework ANATOMY OF A LAGOM PROJECT helloworld-api → Microservice API submodule └ src/main/java → Java source code interfaces with model objects helloworld-impl → Microservice implementation submodule └ logs → Logs of the microservice └ src/main/java → Java source code implementation of the API submodule └ src/main/resources → Contains the microservice application config └ src/test/java → Java source code unit tests logs → Logs of the Lagom system
  • 13. Lagom - The Reactive Microservices Framework Example of a MicroService In order to write a new microservice you create a new API and implementation project. In the API project you define the interface of your microservice: public interface HelloService extends Service { ServiceCall<String, NotUsed, String> hello(); ServiceCall<String, GreetingMessage, String> useGreeting(); @Override default Descriptor descriptor() { return named("helloservice").with( restCall(Method.GET, "/api/hello/:id", hello()), restCall(Method.POST, "/api/hello/:id", useGreeting()) ).withAutoAcl(true); } }
  • 14. Lagom - The Reactive Microservices Framework In the implementation submodule we implement our API’s interface. public class HelloServiceImpl implements HelloService { @Override public ServiceCall<String, NotUsed, String> hello() { return (id, request) -> { CompletableFuture.completedFuture("Hello, " + id); }; } @Override public ServiceCall<String, GreetingMessage, String> useGreeting() { return (id, request) -> { CompletableFuture.completedFuture(request.message + id); }; } }
  • 15. Lagom - The Reactive Microservices Framework public class HelloServiceModule extends AbstractModule implements ServiceGuiceSupport { @Override protected void configure() { bindServices(serviceBinding(HelloService.class, HelloServiceImpl.class)); } }
  • 16. CQRS AND ES Event sourcing and CQRS (Command Query Responsibility Segregation) are fundamental concepts behind Lagom’s support for services that store information. Why Event Sourcing? If a service stores information, a core principle is that each service should own its data and it is only the service itself that should have direct access to the database. Other services must use the Service API to interact with the data. There must be no sharing of databases across different services since that would result in a too tight coupling between the services. To achieve this, Lagom’s persistence module advocates the use of event sourcing and CQRS (Command Query Responsibility Segregation).
  • 17. Testing in Lagom @BeforeClass public static void setUp() { server = ServiceTest.startServer(ServiceTest.defaultSetup()); } @AfterClass public static void tearDown() { if (server != null) { server.stop(); server = null; } }
  • 18. Testing in Lagom @Test public void shouldRespondHello() throws Exception { // given HelloService service = server.client(HelloService.class); // when String hello = service.hello().invoke("Yannick", NotUsed.getInstance()).toCompletableFuture().get(5, SECONDS); // then assertEquals("Hello, Yannick", hello); }
  • 19. Demo