Skip to content

a simple plugin for automatic create feign fallback factory.

License

Notifications You must be signed in to change notification settings

moyada/feign-help

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feign Help

针对 Spring-Feign 开发环境下,编译生成二方包下 FeignFallbackFactory

Maven Central License MIT

安装

添加 feign-help maven 依赖到项目 模块pom.xml :

<dependency>
    <groupId>io.github.moyada</groupId>
    <artifactId>feign-help</artifactId>
    <version>1.0.2-RELEASE</version>
</dependency>

使用

引用 Feign 接口

public interface UserApi {

    @RequestMapping(value = "user/get", method = RequestMethod.GET)
    Result<UserDTO> getUser(@RequestParam("userId") Long userId);

    @RequestMapping(value = "user/create", method = RequestMethod.POST)
    Result<Boolean> createUser(@RequestBody UserDTO data);

    @RequestMapping(value = "user/delete", method = RequestMethod.DELETE)
    Result<Boolean> deleteUser(@RequestBody UserRequest data);
}

使用方构建 Feign Client

只需简单使用注解标记,经过编译过的class文件将会自动添加对应的 Fallback, FallbackFactory

@FallbackFactoryBuild
@FeignClient(name = "user", fallbackFactory = UserRemote.FallbackFactory.class)
public interface UserRemote extends UserApi {
}

经过编译后的 UserRemote.class 文件

@FeignClient(
    name = "user",
    fallbackFactory = UserRemote.FallbackFactory.class
)
public interface UserRemote extends UserApi {
    @Component
    public static class FallbackFactory implements feign.hystrix.FallbackFactory {
        public FallbackFactory() {
        }

        public UserRemote create(Throwable arg0) {
            return new UserRemote.Fallback();
        }
    }

    public static class Fallback implements UserRemote {
        public Fallback() {
        }

        public Result<UserDTO> getUser(@RequestParam("userId") Long userId) {
            return null;
        }

        public Result<Boolean> createUser(@RequestBody UserDTO data) {
            return null;
        }

        public Result<Boolean> deleteUser(@RequestBody UserRequest data) {
            return null;
        }
    }
}

Contributors

moyada moyada

About

a simple plugin for automatic create feign fallback factory.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages