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 ...
随机推荐
- Sprint2的每日更新
按照以下过程进行 ProductBacklog:继续向下细化 Sprint 计划会议:确定此次冲刺要完成的目标 Sprint Backlog:新的冲刺要完成的内容 任务认领 Sprint周期 看板:一 ...
- 个人阅读&个人总结
个人阅读作业+总结 助教推荐的那些文章都是软件工程上的经典文章,阅读后感受到软件工程本身的深度,之前学习的软件工程都只是皮毛之中的皮毛而已.随着软件规模的越来越庞大,软件工程已经成为了软件开发中的必备 ...
- beta阶段博客合集
第一次博客 第二次博客 第三次博客 第四次博客 第五次博客
- JS单例模式在工作中的使用
为了尽可能的减少全局变量的污染,在写js的时候可以采用单例模式,形式如下: 比如有一个js叫demo.js,那么我们可以在js里这样写: var demo = {} 这样做的目的是将整个js当成一个对 ...
- 抽奖系统 random()
random() 方法可返回介于 0 ~ 1 之间的一个随机数. document.write(parseInt(10*Math.random())); //输出0-10之间的随机整数document ...
- Sametime SDK
1,Sametime Server A.Sametime includes many server applications, which collectively provide the capab ...
- P3919 【模板】可持久化数组(可持久化线段树/平衡树)
题目描述 如题,你需要维护这样的一个长度为 N 的数组,支持如下几种操作 在某个历史版本上修改某一个位置上的值 访问某个历史版本上的某一位置的值 此外,每进行一次操作(对于操作2,即为生成一个完全一 ...
- HBase介绍及简易安装
HBase简介 HBase是Apache Hadoop的数据库,能够对大型数据提供随机.实时的读写访问,是Google的BigTable的开源实现.HBase的目标是存储并处理大型的数据,更具体地说仅 ...
- 我的shell脚本
问题:在ip.lt文件中有600个IP,有3个文档模版,三个文档的名称结构都是“ip+一系列字符串”,要求:1.将600个IP分成3分,以三个模版为基础创建600个文档,名字结构与模版相同:2修改60 ...
- 洛谷 P4706 取石子 解题报告
P4706 取石子 题目描述 现在 Yopilla 和 yww 要开始玩游戏! 他们在一条直线上标记了 \(n\) 个点,从左往右依次标号为 \(1, 2, ..., n\) .然后在每个点上放置一些 ...