-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceControllerImpl.java
25 lines (20 loc) · 1007 Bytes
/
ServiceControllerImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.software.architecture.availability.circuitbreakerpattern.controllers;
import com.software.architecture.availability.circuitbreakerpattern.services.Service;
import io.github.resilience4j.circuitbreaker.CallNotPermittedException;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ServiceControllerImpl implements ServiceController {
@Autowired
Service service;
@CircuitBreaker(name= "CustomCircuitBreaker", fallbackMethod = "fallback")
@Override
public String serviceCall(String parameter) {
throw new IllegalArgumentException("Service's error");
// return service.process(parameter);
}
private String fallback(CallNotPermittedException exception) {
return "Service Failing - Fallback: " + exception.getMessage() + "\n Preventing bottlenecks: try later";
}
}