This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Application { | |
public static void main(String[] args) { | |
CarFactory carFactory = new CarFactory(); | |
Scanner sc= new Scanner(System.in); | |
System.out.print("Enter a car"); | |
String str= sc.nextLine(); | |
Car car = carFactory.getCar(str); | |
car.setColor(); | |
car.getColor(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CarFactory { | |
public Car getCar(String carType){ | |
if(carType == null) { | |
return null; | |
} | |
if(carType.equalsIgnoreCase("Hyundai")) { | |
return new Hyundai(); | |
} | |
else if(carType.equalsIgnoreCase("Maruti")) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tata extends Car{ | |
@Override | |
public void setColor() { | |
color = "Tata color is Grey"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Maruti extends Car{ | |
@Override | |
public void setColor() { | |
color = "Maruti car color is Red"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hyundai extends Car{ | |
@Override | |
public void setColor() { | |
color = "Hyundai car color is black"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Car { | |
protected String color; | |
public abstract void setColor(); | |
public void getColor() { | |
System.out.println("car color:"+ color); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class UserRegistrationResilience4j { | |
@Bulkhead(name = "bulkheadService1", fallbackMethod = "bulkHeadFallback") | |
public String registerSeller(SellerDto sellerDto) throws InterruptedException { | |
String response = restTemplate.postForObject("/addSeller", sellerDto, String.class); | |
return response; | |
} | |
public String bulkHeadFallback(SellerDto sellerDto, Throwable t) { | |
logger.error("Inside bulkHeadFallback, cause - {}", t.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
public class UserRegistrationController { | |
@PostMapping("/register/seller") | |
public String registerAsSeller(@RequestBody SellerDto sellerDto) throws InterruptedException { | |
String registerSeller = null; | |
for (int i = 0; i < 100; i++) { | |
long start = System.currentTimeMillis(); | |
new Thread(() -> { | |
try { | |
userRegistrationResilience4j.registerSeller(sellerDto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resilience4j.bulkhead: | |
instances: | |
bulkheadService1: | |
maxWaitDuration: 1000ms | |
maxConcurrentCall: 2 | |
resilience4j.thread-pool-bulkhead: | |
instances: | |
bulkheadService1: | |
maxThreadPoolSize: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class UserRegistrationResilience4j { | |
@CircuitBreaker(name = "service1", fallbackMethod = "fallbackForRegisterSeller") | |
public String registerSeller(SellerDto sellerDto) { | |
String response = restTemplate.postForObject("/addSeller", sellerDto, String.class); | |
return response; | |
} | |
public String fallbackForRegisterSeller(SellerDto sellerDto, Throwable t) { |
NewerOlder