feign的基础配置及修改日志输出类型
来源:互联网 发布:java me基础教程 编辑:程序博客网 时间:2024/06/05 17:12
Feign配置
#Hystrix支持,如果为true,hystrix库必须在classpath中feign.hystrix.enabled=false#请求和响应GZIP压缩支持feign.compression.request.enabled=truefeign.compression.response.enabled=true#支持压缩的mime typesfeign.compression.request.enabled=truefeign.compression.request.mime-types=text/xml,application/xml,application/jsonfeign.compression.request.min-request-size=2048# 日志支持logging.level.project.user.UserClient: DEBUG
自定义配置
自定义配置类不能定义在启动类和Composcan扫描到的类中,要不会被重复初始化,引起冲突
- 定义自定义配置类
package com.wy2.cloud.microservice.user.configuration;import feign.Contract;import feign.Logger;import org.springframework.context.annotation.Bean;/** * 系统名称 xx平台 * 工程名称 wy2-cloud * 创建时间 2017/9/13 11:46 * * @author admin * @since 1.8 */public class FeignClientConfiguration {/* @Bean public Contract feignContract(){ Contract.Default contract = new Contract.Default(); return contract; }*/ @Bean Logger.Level feignLoggerLevel(){ return Logger.Level.FULL; }}
- 2.配置FeignClient日志级别(消费服务的接口所在包,必须是debug)
logging: level: com: wy2: cloud: microservice: user: service: debug
- 3.消费接口注解中增加配置
@FeignClient(name=”${self.userServiceId}”,fallback = UserServiceHystrix.class,configuration ={FeignClientConfiguration.class})
package com.wy2.cloud.microservice.user.service;import com.wy2.cloud.microservice.pojo.user.UserLoginInput;import com.wy2.cloud.microservice.pojo.user.UserLoginResult;import com.wy2.cloud.microservice.user.configuration.FeignClientConfiguration;import com.wy2.cloud.microservice.user.hystrix.UserServiceHystrix;import com.wy2.cloud.pojo.security.User;import com.wy2.cloud.pojo.security.UserPermission;import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.http.MediaType;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import java.util.List;/** * 系统名称 xx平台 * 工程名称 wy2-cloud * 创建时间 2017/6/2 15:34 * ,configuration = FeignClientConfiguration.class * @author admin * @since 1.8 */@FeignClient(name="${self.userServiceId}",fallback = UserServiceHystrix.class,configuration ={FeignClientConfiguration.class})public interface UserService { @RequestMapping(method = RequestMethod.POST,value="/login", produces = MediaType.APPLICATION_JSON_VALUE,consumes = MediaType.APPLICATION_JSON_VALUE) public UserLoginResult login(UserLoginInput userLoginInput); @RequestMapping(method = RequestMethod.POST,value="/loadUserByUsername") public User loadUserByUsername(@RequestParam("userName") String userName); @RequestMapping(method = RequestMethod.POST,value="/getPermissions") public List<UserPermission> getPermissions();}
- 4.成功后出现如下日志:
2017-09-13 14:43:41.491 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] ---> POST http://service-user/login HTTP/1.12017-09-13 14:43:41.492 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] Accept: application/json2017-09-13 14:43:41.492 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] Content-Type: application/json2017-09-13 14:43:41.492 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] Content-Length: 382017-09-13 14:43:41.492 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] 2017-09-13 14:43:41.492 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] {"account":"dddd","password":"111111"}2017-09-13 14:43:41.492 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] ---> END HTTP (38-byte body)2017-09-13 14:43:41.502 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] <--- HTTP/1.1 200 (10ms)2017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] content-type: application/json;charset=UTF-82017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] date: Wed, 13 Sep 2017 06:43:41 GMT2017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] transfer-encoding: chunked2017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] x-application-context: service-user:dev:70102017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] 2017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] {"id":"81157080e6da4427a69a43b6fcb8a7fa","name":null,"email":"mengwzy@qq.com","createTime":1496374560000,"status":1,"account":"dddd","phone":null,"sex":null,"birthday":null}2017-09-13 14:43:41.503 [hystrix-service-user-3] DEBUG c.w.c.m.user.service.UserService - [UserService#login] <--- END HTTP (173-byte body)
Logger.Level支持
必须为每一个Feign Client配置来告诉Feign如何输出日志,可选:
NONE, No logging (DEFAULT).BASIC, Log only the request method and URL and the response status code and execution time.HEADERS, Log the basic information along with request and response headers.FULL, Log the headers, body, and metadata for both requests and responses.
FeignClient第一次请求报TimeOut问题解决方案
- 延长hystix的连接超时时间,默认时间是1秒
//在application配置文件中添加如下配置:hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds:5000
- 禁用hystix的超时时间
//在application配置文件中添加如下配置:hystrix.command.default.execution.timeout.enabled: false
- 禁用hystix
//在application配置文件添加如下配置信息:feign.hystrix.enabled: false
阅读全文
0 0
- feign的基础配置及修改日志输出类型
- Feign的覆写默认配置和Feign的日志
- kettle 的内存设置及输出日志的时间类型
- Feign的自定义配置
- photon 配置及日志输出
- Feign基础入门及特性讲解
- Log4j日志输出配置及Demo
- 配置mybatis的输出日志
- 修改IPtables的日志输出位置
- 修改c3p0默认后台的日志输出
- 【系统学习SpringBoot】SpringBoot配置logging日志及输出日志
- Log4j 独立输出日志文件,以及不启动服务器修改配置生效的例子
- 学习Spring Cloud第十一课(Feign的简介及基础使用)
- Spring cloud系列十一 @Feign集成的Hystrix进行个性化配置及集成原理
- 修改Apache配置日志输出,减轻访问压力
- 【SpringCloud】(九):Feign的自定义配置
- Spring Cloud 的 Feign 组件 自定义配置
- 在BSP 中修改LCD 类型及串口输出功能
- appium python api记录
- ORA-600 [KFDAUDEALLOC2] AND INSTANCE CRASH EVEN WITH THE FIX OF BUG 14467061 (文档 ID 1903273.1)
- 集合-LinkedList
- Course Schedule
- leetcode MYSQL数据库题目
- feign的基础配置及修改日志输出类型
- poj1475 Pushing Boxes
- 如何破解“千人千面”,深度解读用户画像
- short 和 int 类型的转换
- TabLayout+XlistView
- 数据结构面试知识点整理
- 程序猿之--对诗
- 关于WebStorm一些快捷键的应用
- 前端面试经