高性能的Restful服务调用客户端库,完全兼容Spring MVC 注解,基于接口和注解自动代理客户端HTTP请求,支持服务发现,负载均衡,自动熔断,降级、重试。覆盖Feign + Hystrix + Ribbon + ApacheHttpClient的功能
新生项目,可与spring cloud/spring boot配套使用,帮助微服务架构更容易落地,解决服务间最后一公里的调用问题。 欢迎贡献想法和code~
github: https://github.com/darren-fu/RestyPass
// 使用@EnableRestyPass注解启用RestyPass
@SpringBootApplication
@EnableRestyPass(basePackages = {"df.open"})
@RestController
//@EnableDiscoveryClient
//启用spring cloud 服务发现则RestyPass自动使用spring的服务发现方式,
// 否则默认读取resty-server.yaml来获取服务实例
// 可自定义其它发现服务的方式,实现ServerContext接口并注入即可
public class TestClientApplication {
public static void main(String[] args) {
SpringApplication.run(TestClientApplication.class, args);
}
@Autowired
private ProxyService proxyService;
@RequestMapping(value = "nothing")
public String callNothing() {
proxyService.getNothing();
return "OK";
}
}
//使用接口和注解定义并配置调用客户端
//RestyService注解定义服务
@RestyService(serviceName = "server",
fallbackClass = ProxyServiceImpl.class,
retry = 1,
fallbackEnabled = true
)
@RequestMapping(value = "/resty")
public interface ProxyService extends ApplicationService {
// RestyMethod注解定义服务接口
@RestyMethod(retry = 2)
@RequestMapping(value = "/get_nothing", method = RequestMethod.GET, headers = "Client=RestyProxy", params = "Param1=val1")
void getNothing();
}
# resty-server.yaml
servers:
- serviceName: server
instances:
- host: localhost
port: 9201
- host: localhost
port: 9202
@RestController
@RequestMapping("/resty")
public class TestController {
@RequestMapping(value = "/get_nothing", method = RequestMethod.GET)
public void nothing() {
System.out.println("############nothing");
}
}
RestyPass is Open Source software released under the Apache 2.0 license.