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 ...
随机推荐
- IPV6 简单验证
1. 网络路由器的分类 .通常将网络中直接面向用户连接或访问网络的部分称为接入层,接入层目的是允许终端用户连接到网络,因此接入层交换机具有低成本和高端口密度特性: .将位于接入层和核心层之间的部分称为 ...
- java 数据结构与算法---链表
原理来自百度百科 一.链表的定义 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的.链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运 ...
- sourcetree git合并问题
在使用sourcetree做多功能合并(合并不提交)的时候,有时按钮是灰色的,直接点击右上角命令行模式 git merge <branch1> --no-commit 转载请注明博客出处: ...
- Mysql 5.7 报错 3534 错误
需要先 执行 mysqld --initialize 然后 mysqld --install 最后 net start mysql 即可启动服务 如果不执行第一步 则会报错
- C# QR二维码DEMO
QR二维码 二维码的一种 相关类库 ThoughtWorks.QRCode 第三方类库 DEMO功能 Encode 生成二维码图片 Encoding 编码 Correction Level 等级 Ve ...
- SD/MMC相关寄存器的介绍
1.SD卡内部架构 在熟悉SD/MMC相关寄存器之前,我们先来看看SD卡的内部架构是怎么样的,如下图所示: 2.SD/MMC相关寄存器的介绍 从上图中总结出:SD卡内部有7个寄存器. 一.OCR,CI ...
- 【JQuery】JQuery属性
一.前言 接着上一章的内容,继续本章的学习. 二.内容 $().jquery 返回的字符串包含jquery的版本号 jQuery.fx.interval 改变以毫秒计的动画运行速率 j ...
- 【转】__ATTRIBUTE__ 你知多少
__ATTRIBUTE__ 你知多少? GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属性(Function Attribute ).变量属性(V ...
- 洛谷 P1939 【模板】矩阵加速(数列) 解题报告
P1939 [模板]矩阵加速(数列) 题目描述 a[1]=a[2]=a[3]=1 a[x]=a[x-3]+a[x-1] (x>3) 求a数列的第n项对1000000007(10^9+7)取余的值 ...
- linux内核分析 第七周读书笔记
第七章 链接 1.链接是将各种代码和数据部分收集起来并组合成为一个单一文件的过程,这个文件可被加载到存储器并执行. 2.链接可以执行于编译时,加载时,运行时. 7.1编译器驱动程序 1.大多数编译系统 ...