Is it possible to create @Around Aspect for feign.Client
https://github.com/spring-cloud/spring-cloud-openfeign/issues/59
看到github 有人问这个问题,做了个示例:
import org.apache.commons.io.IOUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient;
import org.springframework.stereotype.Component;
import feign.Request;
import feign.Response; import java.io.StringWriter; @Aspect
@Component
public class FeignClientAspect { private static final Logger LOGGER = LoggerFactory.getLogger(FeignClientAspect.class); @Pointcut("execution(* org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClient.*(..))")
public void feignClientPointcut() {
} @org.aspectj.lang.annotation.Around("feignClientPointcut()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { LOGGER.info("feignclient begin");
long start = System.currentTimeMillis();
Object object = joinPoint.getTarget(); if (!(object instanceof LoadBalancerFeignClient)) {
LOGGER.info("feignclient not LoadBalancerFeignClient");
return joinPoint.proceed();
}
Object[] args = joinPoint.getArgs();
for (Object obj : args) {
if (obj instanceof Request) {
Request request = (Request) obj;
LOGGER.info("feignclient request url:{}", request.url());
}
}
Object result = joinPoint.proceed();
if (result instanceof Response) {
Response response = (Response) result; StringWriter writer = new StringWriter();
IOUtils.copy(response.body().asInputStream(), writer, "UTF-8");
String theString = writer.toString(); LOGGER.info("feignclient response body:{}", theString);
}
LOGGER.info("feignclient end ,耗时:{}", (System.currentTimeMillis() - start));
return result;
}
}
通过Aspect ,我们能拿到 FeignClient 请求和响应信息,可以做性能、异常上报。
https://www.cnblogs.com/zhangjianbin/p/9245023.html
Is it possible to create @Around Aspect for feign.Client的更多相关文章
- How to: Create a Windows Communication Foundation Client
How to: Create a Windows Communication Foundation Client To create a Windows Communication Foundatio ...
- windows消息机制详解(转载)
消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...
- Class loading in JBoss AS 7--官方文档
Class loading in AS7 is considerably different to previous versions of JBoss AS. Class loading is ba ...
- 后台管理系统之系统操作日志开发(Java实现)
一,功能点 实现管理员操作数据的记录.效果如下 二,代码实现 基于注解的Aop日志记录 1.Log实体类 package com.ideal.manage.guest.bean.log; import ...
- SpringBoot中使用LoadTimeWeaving技术实现AOP功能
目录 1. 关于LoadTimeWeaving 1.1 LTW与不同的切面织入时机 1.2 JDK实现LTW的原理 1.3 如何在Spring中实现LTW 2. Springboot中使用LTW实现A ...
- Foundations of RESTful Architecture
Introduction The Representational State Transfer (REST) architectural style is not a technology you ...
- Why GraphQL is Taking Over APIs
A few years ago, I managed a team at DocuSign that was tasked with re-writing the main DocuSign web ...
- IOS之constraints
anyway, you can do this with auto layout. You can do it entirely in IB as of Xcode 5.1. Let's start ...
- Aspect-Oriented Programming : Aspect-Oriented Programming with the RealProxy Class
Aspect-Oriented Programming : Aspect-Oriented Programming with the RealProxy Class A well-architecte ...
随机推荐
- angularJS1笔记-(20)-模块化加载机制seajs
SeaJS是一个遵循CMD规范的JavaScript模块加载框架,可以实现JavaScript的模块化开发及加载机制. 与jQuery等JavaScript框架不同,SeaJS不会扩展封装语言特性,而 ...
- [BUAA_SE_2017]个人作业-Week1
个人作业-Week1 疑问 教材中说,PM在衡量需求时需要方方面面的能力与研究.可是,当下许多互联网IT公司只承担外包业务,即客户给什么需求就实现什么需求,甚至可能不要求其它先进的功能.此时,开发团队 ...
- PAT 甲级 1112 Stucked Keyboard
https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 On a broken keyboard, ...
- webservice(一) 概念
Web service:是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分 ...
- NeuralEnhance: 提高图像分辨率的深度学习模型
NeuralEnhance是使用深度学习训练的提高图像分辨率的模型,使用Python开发,项目地址:https://github.com/alexjc/neural-enhance. 貌似很多电影都有 ...
- Shopping Bands Rank & SBR
Shopping Bands Rank SBR https://www.guiderank.org/index.html Nike Air Zoom Pegasus 34 http://www.shi ...
- ZooKeeper-基础介绍
What is ZooKeeper? ZooKeeper为分布式应用设计的高性能(使用在大的分布式系统).高可用(防止单点失败).严格地有序访问(客户端可以实现复杂的同步原语)的协同服务. ZooKe ...
- jQuery Mobile页面跳转后未加载外部JS原因分析及解决
在使用jQuery Mobile进行Web开发中,当页面跳转时(pageA => pageB),在pageB中引用的JS并未成功运行.因为,JQM并为将整个页面加载到当前的dom中,仅将data ...
- 【BZOJ5334】数学计算(线段树)
[BZOJ5334]数学计算(线段树) 题面 BZOJ 洛谷 题解 简单的线段树模板题??? 咕咕咕. #include<iostream> #include<cstdio> ...
- fzyzojP3782 -组合数问题
这个ai<=2000有点意思 启发我们用O(W^2)的算法 FFT不存在,对应关系过紧 考虑组合意义转化建模,再进行分离 (除以2不需要逆元不懂为啥,但是算个逆元总不费事) 由于终点可能在起点的 ...