Implementing Resilience with
Micronaut
Naresha K

@naresha_k

https://blog.nareshak.com/
About me
Developer, Architect &
Tech Excellence Coach
Founder & Organiser
Bangalore Groovy User
Group
• The Network is Reliable

• Latency is Zero

• Bandwidth is Infinite

• The Network is Secure

• Topology Doesn’t Change

• There is One Administrator

• Transport Cost is Zero

• The Network is Homogeneous
https://web.archive.org/web/20171107014323/http://blog.fogcreek.com/eight-fallacies-of-distributed-computing-tech-talk/
Fallacies of distributed computing
Timeout
package com.nareshak.demo
import io.micronaut.http.annotation.Get
import io.micronaut.http.client.annotation.Client
@Client(value = "http://localhost:8081/")
interface PresentationClient {
@Get("/{presentationId}")
PresentationInfo getPresentationInfo(Long presentationId)
}
micronaut:
http:
client:
read-timeout: 5s
application.yml
Retry
@Retryable(attempts = "5", delay = "2s", multiplier = "2.0")
PresentationInfo getPresentation() {
}
package com.nareshak.demo
import io.micronaut.http.annotation.Get
import io.micronaut.http.client.annotation.Client
import io.micronaut.retry.annotation.Retryable
@Client(value = "http://localhost:8081/")
@Retryable(attempts = "5", delay = "2s", multiplier = "2.01")
interface PresentationClient {
@Get("/{presentationId}")
PresentationInfo getPresentationInfo(Long presentationId)
}
Circuit Braker
package com.nareshak.demo
import io.micronaut.http.client.annotation.Client
import io.micronaut.retry.annotation.CircuitBreaker
@Client(value = "http://localhost:8081/")
@CircuitBreaker(reset = "60s", attempts = "1")
interface PresentationClient extends PresentationOps {
}
Fallback
package com.nareshak.demo
import io.micronaut.retry.annotation.Fallback
@Fallback
class PresentationClientFallback implements PresentationOps {
@Override
PresentationInfo getPresentationInfo(Long presentationId) {
new PresentationInfo(title: “TBD")
}
}
References
• https://github.com/naresha/agileindia2020resiliencemincronaut

• https://micronaut.io/
Thank You

Implementing Resilience with Micronaut