5

在k8s中用原生Feign替换SpringCloud - Jie

 8 months ago
source link: https://www.jdon.com/61441.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在k8s中用原生Feign替换SpringCloud - Jie - 极道

当我们不使用 Istio/Linkerd 这样的 Service Mesh 服务时,建议单独使用 SpringBoot 和 k8s 来构建服务。
相反,我们不建议同时使用 SpringCloud 和 k8s。
两者之间有很多功能重叠,随着云原生的趋势,我们应该将一些基础工作留给像 k8s 这样的服务。
让我们更加专注于业务开发,从而降低开发成本。
但是我们想使用像spring-cloud-feign中一些声明性调用,很方便。
所以我开发了这个库,它类似于spring-cloud- feign,但不依赖SpringCloud的复杂依赖:
源码:https ://github.com/crossoverJie/feign-plus

这看起来很像 SpringCloud,它具有以下特点:

  • 请求/响应/异常日志记录。
  • 自定义拦截器。
  • 千分尺支持。
  • 异常传递。

用编写Feign客户端annotation,如下所示:

我们可以提供一个接口:

@RequestMapping("/v1/demo")
@FeignPlusClient(name = "demo", url = "${feign.demo.url}", port = "${feign.demo.port}")
public interface DemoApi {
    @GetMapping("/id")
    String sayHello(@RequestParam(value = "id") Long id);

@GetMapping("/id/{id}")
    String id(@PathVariable(value = "id") Long id);

@PostMapping("/create")
    Order create(@RequestBody OrderCreateReq req);

@GetMapping("/query")
    Order query(@SpringQueryMap OrderQueryDTO dto);
}

现在我们可以像平常SpringBoot一样使用它了:

@SpringBootApplication
@EnableFeignPlusClients(basePackages = "com.example.provider.api")
@RestController
public class DemoApplication {

@Resource
    private DemoApi demoApi;

@GetMapping(value = "/hello")
    public String hello() {
        demoApi.id(12L);
        demoApi.sayHello(34L);
        demoApi.create(new OrderCreateReq("100"));
        demoApi.query(new OrderQueryDTO("999", "zhangsan"));
        return "hello";
    }

public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

 


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK