SlideShare a Scribd company logo
1 of 64
Download to read offline
Implementing Cloud-Native
Architectural Patterns with
Micronaut
Naresha K

@naresha_k

https://blog.nareshak.com/
About me
Developer, Coach, Consultant
Founder & Organiser
Bangalore Groovy User Group
https://github.com/cncf/toc/blob/master/DEFINITION.md
https://www.redhat.com/en/topics/cloud-native-apps#
https://www.redhat.com/en/topics/cloud-native-apps#
Externalised Configuration
Configuration coupled with code
https://blog.nareshak.com/if-you-are-building-your-artifacts-per-environment-you-are-doing-it-wrong/
“Configuration should be
version controlled”
Configuration coupled with code
Externalising the configuration
@Controller("/hello")
public class HelloController {
@Value("${greeting.message}")
private String message;
@Get("/")
@Produces(MediaType.TEXT_PLAIN)
public String index() {
return message;
}
}
micronaut:
application:
name: hello-service
greeting:
message: Hello from Micronaut
java -Dmicronaut.environments=uat -jar
hello-service-0.1.jar
Configuration Injection
java -Dgreeting.message="Hello from External Config”
-jar hello-service-0.1.jar
java -Dmicronaut.config.files=“/tmp/external-config.yml"
-jar hello-service-0.1.jar
Is this not enough?
Config Server
Config
Server
Application
Application
Application
docker run -p 8500:8500 consul
bootstrap.yml
curl -X PUT -d @- localhost:8500/v1/kv/config/greet-service/greeting.message <<< "Hello from Consul"
~ curl http://localhost:8080/greet
Hello from Consul
Service Discovery
Cloud Infrastructure
Microservices
Service
Registry
Service
X
Service A
Service
Registry
Service
X
Service A
Register
Service
Registry
Service
X
Service A
Register
Service
Registry
Service
X
Service A
Get routing information
Service
Registry
Service
X
Service A
REST call
---
consul:
client:
registration:
enabled: true
defaultZone: "${CONSUL_HOST:localhost}:${CONSUL_PORT:8500}"
application.yml
sample-service ./gradlew run
> Task :run
05:12:07.121 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 1260ms. Server Running: http://localhost:8080
05:12:07.251 [nioEventLoopGroup-1-3] INFO i.m.d.registration.AutoRegistration - Registered service [sample-service] with Consul
http://localhost:8080/greet
@Controller("/hello")
class HelloController {
@Inject
GreetClient greetClient
@Get("/")
String index() {
greetClient.index()
}
}
Resilience /
Fault Tolerance
https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing
07:19:19.838 [pool-1-thread-2] ERROR i.m.r.intercept.RecoveryInterceptor - Type
[com.nareshak.demo.GreetClient$Intercepted] attempting to resolve fallback for unavailable service
[sample-service]
07:19:19.843 [pool-1-thread-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred:
No available services for ID: sample-service
io.micronaut.discovery.exceptions.NoAvailableServiceException: No available services for ID: sample-
service at
io.micronaut.http.client.loadbalance.AbstractRoundRobinLoadBalancer.getNextAvailable(AbstractRoundRo
binLoadBalancer.java:50)
Timeout
07:33:47.976 [pool-1-thread-3] ERROR i.m.r.intercept.RecoveryInterceptor - Type [com.nareshak.demo.GreetClient$Intercepted]
executed with error: Read Timeout
io.micronaut.http.client.exceptions.ReadTimeoutException: Read Timeout
Retry
@Retryable
String callExtService(){
}
@Retryable(attempts = "3", delay = "5s")
String callExtService(){
}
07:26:27.347 [pool-1-thread-2] ERROR i.m.r.intercept.RecoveryInterceptor - Type [com.nareshak.demo.GreetClient$Intercepted]
attempting to resolve fallback for unavailable service [sample-service]
07:26:37.355 [pool-1-thread-2] ERROR i.m.r.intercept.RecoveryInterceptor - Type [com.nareshak.demo.GreetClient$Intercepted]
attempting to resolve fallback for unavailable service [sample-service]
07:26:52.361 [pool-1-thread-2] ERROR i.m.r.intercept.RecoveryInterceptor - Type [com.nareshak.demo.GreetClient$Intercepted]
attempting to resolve fallback for unavailable service [sample-service]
07:27:12.373 [pool-1-thread-2] ERROR i.m.r.intercept.RecoveryInterceptor - Type [com.nareshak.demo.GreetClient$Intercepted]
attempting to resolve fallback for unavailable service [sample-service]
07:27:12.378 [pool-1-thread-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: No available services for
ID: sample-service
io.micronaut.discovery.exceptions.NoAvailableServiceException: No available services for ID: sample-service
at
io.micronaut.http.client.loadbalance.AbstractRoundRobinLoadBalancer.getNextAvailable(AbstractRoundRobinLoadBalancer.java:50)
Circuit Breakers
@CircuitBreaker
String callExtService(){
}
@CircuitBreaker(reset = "40s")
String callExtService(){
}
Fallback
@Fallback
class FallbackClient implements GreetClient{
@Override
String index() {
return "Default Message"
}
}
API Versioning
@Get(“/greet")
String index() {
"Hello"
}
@Get(“/greet")
Single<String> indexV2() {
Single.just("Hello V2")
}
@Get(“/greet")
@Version("1")
String index() {
"Hello"
}
@Get(“/greet")
@Version("2")
Single<String> indexV2() {
Single.just("Hello V2")
}
router:
versioning:
enabled: true
header:
enabled: true
names:
- 'X-API-VERSION'
- 'Accept-Version'
application.yml
~curl http://localhost:8080/greet -H "X-API-VERSION: 1"
Hello%
~ curl http://localhost:8080/greet -H "X-API-VERSION: 2"
Hello V2%
@Client("sample-service")
@Version("1")
interface GreetClient {
@Get("/greet")
String index()
@Version("2")
@Get("/greet")
Single<String> indexV2()
}
When you in are in cloud-native world, features like fault tolerance,
service discovery, externalised configuration are necessary
Micronaut makes it easier to implement these patterns with its built-in support
Conclusion
Thank You

More Related Content

Similar to Implementing Cloud-Native Architectural Patterns with Micronaut

important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
surendray
 

Similar to Implementing Cloud-Native Architectural Patterns with Micronaut (20)

Azure from scratch part 4
Azure from scratch part 4Azure from scratch part 4
Azure from scratch part 4
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Atlassian meets Kerberos
Atlassian meets KerberosAtlassian meets Kerberos
Atlassian meets Kerberos
 
Implementing Resilience with Micronaut
Implementing Resilience with MicronautImplementing Resilience with Micronaut
Implementing Resilience with Micronaut
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112Nats meetup oct 2016 docker 112
Nats meetup oct 2016 docker 112
 
MCE^3 - Kyle Fuller - End-to-end Building Web Services in-swift-mce-2016
MCE^3 - Kyle Fuller - End-to-end Building Web Services in-swift-mce-2016MCE^3 - Kyle Fuller - End-to-end Building Web Services in-swift-mce-2016
MCE^3 - Kyle Fuller - End-to-end Building Web Services in-swift-mce-2016
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Kruize-Autotune-July-Meetup.pdf
Kruize-Autotune-July-Meetup.pdfKruize-Autotune-July-Meetup.pdf
Kruize-Autotune-July-Meetup.pdf
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
Naked Performance With Clojure
Naked Performance With ClojureNaked Performance With Clojure
Naked Performance With Clojure
 
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKitAtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Re-Design with Elixir/OTP
Re-Design with Elixir/OTPRe-Design with Elixir/OTP
Re-Design with Elixir/OTP
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Microservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud PlatformMicroservices DevOps on Google Cloud Platform
Microservices DevOps on Google Cloud Platform
 
Sinatra and friends
Sinatra and friendsSinatra and friends
Sinatra and friends
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
 

More from Naresha K

More from Naresha K (20)

The Groovy Way of Testing with Spock
The Groovy Way of Testing with SpockThe Groovy Way of Testing with Spock
The Groovy Way of Testing with Spock
 
Evolving with Java - How to Remain Effective
Evolving with Java - How to Remain EffectiveEvolving with Java - How to Remain Effective
Evolving with Java - How to Remain Effective
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Take Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainersTake Control of your Integration Testing with TestContainers
Take Control of your Integration Testing with TestContainers
 
Favouring Composition - The Groovy Way
Favouring Composition - The Groovy WayFavouring Composition - The Groovy Way
Favouring Composition - The Groovy Way
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
What's in Groovy for Functional Programming
What's in Groovy for Functional ProgrammingWhat's in Groovy for Functional Programming
What's in Groovy for Functional Programming
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
 
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
 
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
 
Groovy - Why and Where?
Groovy  - Why and Where?Groovy  - Why and Where?
Groovy - Why and Where?
 
Leveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS LambdaLeveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS Lambda
 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring Patterns
 
Implementing Cloud-native Architectural Patterns with Micronaut
Implementing Cloud-native Architectural Patterns with MicronautImplementing Cloud-native Architectural Patterns with Micronaut
Implementing Cloud-native Architectural Patterns with Micronaut
 
Effective Java with Groovy
Effective Java with GroovyEffective Java with Groovy
Effective Java with Groovy
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and Effective
 
Effective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good PracticesEffective Java with Groovy - How Language can Influence Good Practices
Effective Java with Groovy - How Language can Influence Good Practices
 
Beyond Lambdas & Streams - Functional Fluency in Java
Beyond Lambdas & Streams - Functional Fluency in JavaBeyond Lambdas & Streams - Functional Fluency in Java
Beyond Lambdas & Streams - Functional Fluency in Java
 
GORM - The polyglot data access toolkit
GORM - The polyglot data access toolkitGORM - The polyglot data access toolkit
GORM - The polyglot data access toolkit
 
Rethinking HTTP Apps using Ratpack
Rethinking HTTP Apps using RatpackRethinking HTTP Apps using Ratpack
Rethinking HTTP Apps using Ratpack
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
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 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
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
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
 
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
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 

Implementing Cloud-Native Architectural Patterns with Micronaut