14.Spring-Cloud-Feign requested compressed configuration and logging configuration

   Compression configuration request

    Spring Cloud feign support request and response GZIP compression, to reduce the loss of performance communication, mainly in the spring-cloud-netflix-core.jar file.

The default request and the corresponding compression is disabled from
org.springframework.cloud.netflix.feign.encoding.FeignContentGzipEncodingAutoConfiguration request class can be seen compression is disabled
Source:
@ConditionalOnProperty (value = "feign.compression.request.enabled" , = matchIfMissing to false)
org.springframework.cloud.netflix.feign.encoding.FeignAcceptGzipEncodingAutoConfiguration.class class can be seen is disabled in response to a compression
source code:

@ConditionalOnProperty(value = "feign.compression.response.enabled", matchIfMissing = false)

org.springframework.cloud.netflix.feign.encoding.FeignClientEncodingProperties arranged some default class attributes encoding
source:
@ConfigurationProperties ( "feign.compression.request")
public class FeignClientEncodingProperties {
    / **
     * Supported of The List of MIME types.
     * /
    Private String [] = the mimeTypes new new String [] { "text / XML", "file application / XML", "file application / JSON"};
    / **
     * Content of The Minimum threshold size.
     * /
    Private minRequestSize int = 2048;

}

Custom request the compression application.properties

feign.compression.request.enabled=true
feign.compression.response.enabled=true
#默认配置
feign.compression.request.mine-types=text/xml,application/xml,application/json 
#默认配置
feign.compression.request.min-request-size=2048
 

Logging Configuration

When building @FeignClient comment modified client service, will have to create a feign.Logger example is a client, you can use the DEBUG log object model to analyze the details of the request of Feign. DETAILED disposed application.properties configuration:

. Logging.level <FeignClient> = DEBUG open Feign specified client logs in DEBUG mode;

Full Path <FeignClient> to the interface definition client Feign

如:
logging.level.com.niugang.service.HelloService=DEBUG

Just add the above configuration can not achieve output of DEBUG log in to the client because Feign default logger.level object definition to none level information in the calling process feign it will not be recorded.

feign level log
  / **
   * Controls The Level of the logging.
   * /
  public enum {Level
    / **
     * No the logging. no logging
     * /
    NONE,
    / **
* method only records and requests URL, and the response status code, and execution time.
     The only the Log Request Method * and the URL code and The Status Response Time and Execution.
     * /
    The BASIC,
    / **
* record basic information request and response headers.
     The Basic Information Along the Log * with Request and Response headers.
     * /
    HEADERS,
    / **
* record the request and response headers, text and metadata
     * the Log The headers, body, and Metadata for both Requests and Responses.
     * /
    FULL

  }

Creating a way: on the startup class configuration

@SpringBootApplication 
@EnableDiscoveryClient 
// scanning declares them feign interface of the client (by @FeignClient) 
@EnableFeignClients
 public  class the Application { 
@Bean 
Logger.Level feignLoggerLevel () { 
return Logger.Level.FULL; 
} 
public  static  void main (String [] args) { 
SpringApplication.run (the Application. class , args); 
} 
}

 

 


test

   输入:http://localhost:9001/feign-consumer1/zhangsan

   Input: HTTP: // localhost: 9001 / Feign-consumer2 / zhangsan / 15,094,031,789

Create a way: custom configuration class

 

1. Create a special configuration class

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import feign.Logger;
@Configuration
public class FeignLoggerConfig {
@Bean
Logger.Level feignLoggerLevel(){
return Logger.Level.FULL;
}
}

 

2. binding on the service call interface

// value: calling name services
// fallback: Configuration Service downgraded the class
// configuration: customized client custom @configuration. It may comprise rewriting @Bean defined fragments of the client

@FeignClient(value="service-provide",fallback=ServiceProvideFallBack.class,configuration=FeignLoggerConfig.class)

Configuration and test results on the effect of the same class start

                                                                               Micro-channel public number: 

                                               

                                                                             JAVA program ape growth path

                          Resource sharing, recording program ape growing little by little. Focus on Java, Spring, SpringBoot, SpringCloud, distributed, slightly services. 

Guess you like

Origin www.cnblogs.com/niugang0920/p/12193286.html