x-ream / rey

RestTemplate + resilience4j + opentracing for k8s

Home Page:http://rey.xream.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rey

http://rey.xream.io

license maven Gitter

GLIMPSE

   rey
         @EnableReyClient           @ReyClient
         @EnableFallback            @Fallback
         
         @Resource private ReyTemplate reyTemplate;
    
   rey-spring-boot-starter
   
   rey-seata-spring-boot-starter
    <dependency>
         <groupId>io.xream.rey</groupId>
         <artifactId>rey-spring-boot-starter</artifactId>
         ....
    </dependency>

NOTES

   1. @Fallback not dependent on remote call, can add fallback on any class
   2. @ReyClient, call remote service, if get exception, will respond exception message with
       status 222, while actual status in message body
   3. If deploy many copies of a set of microservices, how to route to the service?
            public class FooRouter implements GroupRouter{
                 public String replaceHolder(){
                      return "#xxx#";
                 }
                 public String replaceValue(Object obj) {
                      // See the demo: CatServiceGroupRouterForK8S.java
                      // Anyway, coding to ensure all the data only in the dbs connected by the target services
                      // each set of services connect diffent db and cache, one set include: storage, db, cache, 
                      // and your program 
                      // all in docker, all in k8s, set/k8s namespace
                 }
            }
            import org.springframework.web.bind.annotation.RequestMapping;
            
            @ReyClient(value = "http://${app.foo}/xxx", groupRouter = FooRouter.class)
            public interface barRemote {
                @RequestMapping("/test")
                String test();
            }      
        config:
        # when write/read db, sharding db can't support more TPS
        # we set the k8s namespace: prod_0, prod_1, prod_2 ....
        # k8s ingress to front service(no connection to DB), front service call service-demo
        # by this way, one set of services' TPS is 10000, deploy 10 sets, TPS become almost 100000
        service.demo=service-demo.prod#xxx#

CODING ERROR

   1. annotation Fallback And CircuitBreaker(resilience4j) on the same class:
            @RestController
            @RequestMapping("/soo")
            @CircuitBreaker(name = "soo")
            @Fallback(fallback = SooFallback2.class, ignoreExceptions = {
                    IllegalArgumentException.class,
                    ReyBizException.class
                    })
            public class SooController {
                // ...
            }
   2.  annotation Fallback on class, while CircuitBreaker(resilience4j) on a method of the class:
            @RestController
            @RequestMapping("/soo")
            @Fallback(fallback = SooFallback2.class, ignoreExceptions = {
                    IllegalArgumentException.class,
                    ReyBizException.class
                    })
            public class SooController {
            
                @CircuitBreaker(name = "soo")
                @RequestMapping("/aaa")
                public String aaaaa() {
                    return null;
                }
            }

About

RestTemplate + resilience4j + opentracing for k8s

http://rey.xream.io

License:Apache License 2.0


Languages

Language:Java 100.0%