Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/moyada/feign-help

a simple plugin for automatic create feign fallback factory.
https://github.com/moyada/feign-help

feign feign-client java-annotation-processor maven spring

Last synced: 2 days ago
JSON representation

a simple plugin for automatic create feign fallback factory.

Awesome Lists containing this project

README

        

# Feign Help

针对 `Spring-Feign` 开发环境下,编译生成二方包下 `Feign` 的 `FallbackFactory`。

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.moyada/feign-help/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.moyada/feign-help)
![License MIT](https://img.shields.io/badge/MIT-342e38?style=flat-square&label=License)

## 安装

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

```

io.github.moyada
feign-help
1.0.2-RELEASE

```

## 使用

#### 引用 Feign 接口

```
public interface UserApi {

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

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

@RequestMapping(value = "user/delete", method = RequestMethod.DELETE)
Result 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 getUser(@RequestParam("userId") Long userId) {
return null;
}

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

public Result deleteUser(@RequestBody UserRequest data) {
return null;
}
}
}
```

## Contributors

| [![moyada](https://github.com/moyada.png?size=120)](https://github.com/r4phab) | [moyada](https://github.com/moyada) |
|:------------------------------------------------------------------------------:|--------------|