Solon

feign-solon-plugin

v2.7.3 </> markdown
<dependency>
    <groupId>org.noear</groupId>
    <artifactId>feign-solon-plugin</artifactId>
</dependency>

1、描述

分布式扩展插件。基于 feign 适配的 声明式 http 客户端插件。此插件,也可用于调用 Spring Cloud Rpc 接口。

2、使用示例

Feign 可以纯代码构建,也可以基于注解构建;可以基于具体地址请求,也可基于服务名请求(需要发现服务插件支持)。

本例,选一种更适合微服务风格的。声明接口:

@FeignClient(name = "user-service", path = "/users/", configuration = JacksonConfig.class)
public interface RemoteService {

    @RequestLine("GET get1?name={name}")
    String getOwner(@Param(value = "name") String name);

    @RequestLine("GET get2?name={name}")
    User get2(String name);
}

增加服务发现配置

#如果没有配置服务,可用本地发现配置
solon.cloud.local:
  discovery:
    service:
      user-service:
        - "http://127.0.0.1:8081"

可以用这个声明接口了

@Controller
public class DemoController {
    @Inject
    RemoteService remoteService;

    @Mapping("test")
    public String test() {
        String result = remoteService.getOwner("scott");

        return result;
    }
}

启动服务

@EnableFeignClient
public class DemoApp {
    public static void main(String[] args) {
        Solon.start(DemoApp.class, args);
    }
}

3、代码演示

https://gitee.com/noear/solon-examples/tree/main/7.Solon-Remoting-Rpc/demo7021-feign