前几天在一个QQ技术群里,有人推荐了x7框架,pull下来试试,有些特点。
1. x7-reyc很feign框架的编程模型一样, 底层是resilience4j. 但比较灵活,完全脱离了spring cloud, 更适合k8s。附上例子:
@ReyClient(value = "127.0.0.1:8868", circuitBreaker = "", retry = true, fallback = TestFallback.class)
public interface TestServiceRemote {
/**
* 参数io.xream.x7.reyc.Url, 优先配置的http://127.0.0.1:8868/xxx/recy/test
*/
@RequestMapping(value = "/xxx/reyc/test")
Boolean test(CatRO ro, Url url);
@RequestMapping(value = "/xxx/reyc/test")
Boolean testFallBack(CatRO ro);
@RequestMapping(value = "/xxx/time/test", method = RequestMethod.GET)
Boolean testTimeJack();
}
public class TestFallback {
public void testFallBack(CatRO ro){
/*
* send to kafka
*/
System.out.println("fallBack");
}
public void test(CatRO ro, Url url){
/*
* send to kafka
*/
System.out.println("fallBack with Url");
}
}
已经完全脱离spring cloud, 如果不用istio等service mesh框架,x7-reyc是个很好的选择。
2. x7-repository, 这是个简单的orm框架,不明白作者为什么另写一个orm框架,看官网的例子,这个orm框架比较简单,但不是很全面,例子如下:
CriteriaBuilder.ResultMappedBuilder builder = CriteriaBuilder.buildResultMapped(CatTest.class,ro);
builder.distinct("catTest.dogId").distinct("catTest.catFriendName")
.reduce(Reduce.ReduceType.COUNT,"catTest.id")
.reduce(Reduce.ReduceType.SUM, "catTest.id")
.groupBy("catTest.dogId")
.groupBy("catTest.catFriendName")
.paged().page(1).rows(2).sort("catTest.dogId",Direction.DESC);
String sourceScript = "catTest inner join dagTest on catTest.dogId = dogTest.id";
Criteria.ResultMappedCriteria resultMapped = builder.get();
resultMapped.setSourceScript(sourceScript);
Page<Map<String,Object>> page = repository.find(resultMapped);
用起来简单,但不适合复杂的SQL. 更多的例子还是去github上找, github地址: https://github.com/x-ream/x7
从github上pull下demo,发现整个框架依赖spring boot, 这个让人感觉不痛快,要是项目没用spring boot,就根本用不了x7框架。从源码来看,写得比较粗糙,但就是比较好用。这个就不想和其他框架做比较了,要是有人感兴趣,可以以前讨论。
原文:https://www.cnblogs.com/kkio/p/10820200.html