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的更多相关文章

  1. How to: Create a Windows Communication Foundation Client

    How to: Create a Windows Communication Foundation Client To create a Windows Communication Foundatio ...

  2. windows消息机制详解(转载)

    消息,就是指Windows发出的一个通知,告诉应用程序某个事情发生了.例如,单击鼠标.改变窗口尺寸.按下键盘上的一个键都会使Windows发送一个消息给应用程序.消息本身是作为一个记录传递给应用程序的 ...

  3. Class loading in JBoss AS 7--官方文档

    Class loading in AS7 is considerably different to previous versions of JBoss AS. Class loading is ba ...

  4. 后台管理系统之系统操作日志开发(Java实现)

    一,功能点 实现管理员操作数据的记录.效果如下 二,代码实现 基于注解的Aop日志记录 1.Log实体类 package com.ideal.manage.guest.bean.log; import ...

  5. SpringBoot中使用LoadTimeWeaving技术实现AOP功能

    目录 1. 关于LoadTimeWeaving 1.1 LTW与不同的切面织入时机 1.2 JDK实现LTW的原理 1.3 如何在Spring中实现LTW 2. Springboot中使用LTW实现A ...

  6. Foundations of RESTful Architecture

    Introduction The Representational State Transfer (REST) architectural style is not a technology you ...

  7. 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 ...

  8. 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 ...

  9. Aspect-Oriented Programming : Aspect-Oriented Programming with the RealProxy Class

    Aspect-Oriented Programming : Aspect-Oriented Programming with the RealProxy Class A well-architecte ...

随机推荐

  1. Prism6下的MEF:第一个Hello World

    最近看书比较多,正好对过去几年的软件开发做个总结.写这个的初衷只是为了简单的做一些记录. 前言 复杂的应用程序总是面临很多的页面之间的数据交互,怎样创建松耦合的程序一直是多数工程师所思考的问题.诸如依 ...

  2. 讲讲Windows10(UWP)下的Binding

    前言 貌似最近来问我XAML这块的东西的人挺多的.有时候看他们写XAML这块觉着也挺吃力的,所谓基础不牢,地动山摇.XAML这块虽说和HTML一样属于标记语言,但是世界观相对更加庞大一点. 今天讲讲X ...

  3. Scrum 项目2.0 3.0

    顺带 MY—HR 成员: 角色分配 学号 博客园 团队贡献分 丘惠敏 PM项目经理 201406114203 http://www.cnblogs.com/qiuhuimin/ 19 郭明茵 用户 2 ...

  4. ubuntu下安装软件的三种方法

    在ubuntu当中,安装应用程序常用的三种方法,分别是apt-get,dpkg安装deb和make install安装源码包三种. apt-get方法 使用apt-get install来安装应用程序 ...

  5. [转帖] dd 命令图解

    dd命令-->dd是disk dump的缩写,指定大小的块拷贝一个文件,同时进行指定的转换,起到一个初始化磁盘的作用  https://blog.csdn.net/jerry_1126/arti ...

  6. Hibernate性能优化之SessionFactory重用

    Hibernate优化的方式有很多,如缓存.延迟加载以及与SQL合理映射,通过对SessionFactory使用的优化是最基础的. SessionFactory负责创建Session实例,Sessio ...

  7. 使用flex布局调换两个按钮的位置

    组件用的时antd的Modal组件,里面的按钮需要调换一下位置 今天发现用flex布局非常方便,代码如下: display: flex; justify-content: center; flex-f ...

  8. 关于nginx的一点记录

    (1) 安装nginx官网下载:http://nginx.org下载适合Windows的安装包,是一个压缩包,直接解压就可以了. (2) 启动nginx有三种方式启动:a. 双击nginx.exe图标 ...

  9. Qss 样式表的尝试

    QLineEdit{ border:1px solid #137eb6; padding:2px; background-color:#F5F5F5; } QToolTip{ border:1px s ...

  10. 【开发工具IDE】eclipse的SVN提交忽略target等多余文件

    这个build失败的解决方案就是不要把你项目的 target目录放在src repository 里面,还有 .project 和 .classpath最好也别放到src repository 里. ...