开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
2 Star 4 Fork 2

zhaojin/spring-cloud-openfeign-async

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
3.1.x
分支 (14)
标签 (75)
3.1.x
3.0.x
main
register-method-params-for-reflection
fix-pageable-processing-when-querymap-present
fix-okhttp-encoding-condition
property-based-url-native
protocols-fix-aot
aot-support
micrometerObservationsViaFeignCapabilities
2.2.x
gh-pages
2.1.x
2.0.x
v3.1.7
v4.0.2
v3.1.6
v4.0.1
v4.0.0
v4.0.0-RC3
v4.0.0-RC2
v3.1.5
v4.0.0-RC1
v4.0.0-M5
v3.1.4
v4.0.0-M4
v3.0.8
v3.0.7
v4.0.0-M3
v3.1.3
v3.1.2
v4.0.0-M2
v3.1.1
v4.0.0-M1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
贡献代码
同步代码
对比差异 通过 Pull Request 同步
同步更新到分支
通过 Pull Request 同步
将会在向当前分支创建一个 Pull
Request,合入后将完成同步
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0
1. 异步模块

1.1. 3.0/3.1版添加模块 spring-cloud-openfeign-core-asyn 以支持异步,3.0/3.1版本openfeign支持异步

1.2. 使用方法:

  • pom.xml引入(务必在spring-cloud-starter-openfeign之前):

 <dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-openfeign-core-asyn</artifactId>
 <version>3.0.8-SNAPSHOT</version>
 <scope>compile</scope>
 </dependency>
 <!-- 以及真异步通讯模块 -->
 <dependency>
 <groupId>io.github.openfeign</groupId>
 <artifactId>feign-hc5</artifactId>
 </dependency>
  • 注解:@EnableFeignClientsWithAsync() 启动openfeign

  • 配置添加(3.1版本不要配置 httpclient.hc5、okhttp、httpclient,否则可能启动失败):

 feign:
 client:
 #启动异步(默认是同步的)
 asyn-enabled: true
 httpclient:
 hc5-async:
 #启用hc5的真异步通讯(默认是基于线程的伪异步)
 enabled: true
  • 具体接口添加<CompletableFuture>即可,如下,如果是同步的一样可以用,只是纯同步

 @RequestMapping(value ="/system/sysParam/paramValueAndDelaySecond/{paramName}", method = RequestMethod.GET)
 CompletableFuture<Result<String>> paramValueAndDelaySecondAsyn(@PathVariable("paramName") String paramName, @RequestParam("seconds") Integer seconds);

1.3. 已支持http2 性能应该能更上一层楼(异步长连接)

  • 自建添加http2 client:

 @Bean
 public CloseableHttpAsyncClient httpAsyncClient5http2(FeignHttpClientProperties httpClientProperties) {
 log.info("CloseableHttpAsyncClient http2 1.0!");
 IOReactorConfig ioReactorConfig = IOReactorConfig.custom().setSoTimeout(Timeout.ofMilliseconds(250)) // 1.1
 .setSelectInterval(TimeValue.ofMilliseconds(50)) // 1.2
 .setSoTimeout(Timeout.of(httpClientProperties.getHc5().getSocketTimeout(),
 httpClientProperties.getHc5().getSocketTimeoutUnit()))
 .build();

 httpAsyncClient5 = HttpAsyncClients.customHttp2()
 .disableCookieManagement()
 .disableAutomaticRetries()
 .useSystemProperties()
 .setIOReactorConfig(ioReactorConfig)
 .setDefaultRequestConfig(RequestConfig.custom()
 .setRedirectsEnabled(httpClientProperties.isFollowRedirects())
 .setConnectTimeout(100, TimeUnit.MILLISECONDS)
 .build())
 .build();

 httpAsyncClient5.start();

 return httpAsyncClient5;
 }
  • 后期通过属性支持支持http2

1.4. 以及准备把异步模块完全抽离成独立项目

1.5. 打包:mvn clean install -Dpmd.skip=true -Dcheckstyle.skip=true

1.6. 注意事项

  • 异步导致的结果是发送也是异步(接口返回其实请求还未发送完)

  • RequestConfig 中 connectionRequestTimeout,影响异步发送超时(目前设置在connectTimeout,即设置ConnectTimeout即可)

  • 影响并发的吞吐量的maxConnPerRoute,maxConnTotal(http1),当设置为1的场景下,基本上就是一条条的发送接受(实际感受到的瞬发,但是结果是依次累加实际返回)

  • http2吞吐量不受maxConnPerRoute,maxConnTotal影响,但是使劲发可能会存在上游拥堵

1.7. spring-cloud-openfeign 其他模块以、功能、描述见:

README
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/RemoteControl/spring-cloud-openfeign.git
git@gitee.com:RemoteControl/spring-cloud-openfeign.git
RemoteControl
spring-cloud-openfeign
spring-cloud-openfeign-async
3.1.x
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /