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 ...
随机推荐
- windows下的C++ socket服务器(1)
windows下的一个C++ socket服务器,用到了C++11的相关内容,现在还不是很完善,以后会不断改进的! #include <winsock2.h>//1 以后会用这种方式对特定 ...
- FineReport基本使用
FineReport官方开发文档链接:http://help.finereport.com 1.FineReport是帆软软件有限公司自主研发的一款企业级web报表软件产品.FineReport报表软 ...
- awk4.0对数组value排序
有朋友问了一个问题,要求对下面这段文本进行处理: http://www.baidu.com/2.html http://www.baidu.com/2.html http://www.baidu.co ...
- 学习mysql触发器遇到的问题
在 mysql.exe 下面运行的.如果是的话, 可能是需要加一个 定义 DELIMITER // 意思是告诉 mysql , 遇到 // 符号以后, 才认为语句结束了. 否则 mysql 遇到 分号 ...
- js本地储存userData实例
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- PHP中测试in_array、isset、array_key_exists性能
测试in_array.isset.array_key_exists性能.自己写的简易测试代码: ini_set('display_errors',true); error_reporting(E_AL ...
- Django 2.0 学习(20):Django 中间件详解
Django 中间件详解 Django中间件 在Django中,中间件(middleware)其实就是一个类,在请求到来和结束后,Django会根据自己的规则在合适的时机执行中间件中相应的方法. 1. ...
- MT【135】条件线性化
已知\(x,y>0,\dfrac{1}{x}+\dfrac{2}{y}=1\),求\(\dfrac{1}{x+1}+\dfrac{2}{y+1}\)的最大值_____ 解答:令\(a=\dfra ...
- 【刷题】洛谷 P3950 部落冲突
题目背景 在一个叫做Travian的世界里,生活着各个大大小小的部落.其中最为强大的是罗马.高卢和日耳曼.他们之间为了争夺资源和土地,进行了无数次的战斗.期间诞生了众多家喻户晓的英雄人物,也留下了许多 ...
- 一个非典型的Linux路由配置方案
上周帮人解决了一个问题,这个问题绝对是非典型性的,采用了非常规的方法.虽然最终的方案非常不符合常规,非常不通用,充满了各种藏得很深的技巧或者说是trick,但是这个问题却是一个学习Linux路由的绝好 ...