Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feign can never compress request/response. #1580

Closed
eacdy opened this issue Dec 29, 2016 · 22 comments
Closed

Feign can never compress request/response. #1580

eacdy opened this issue Dec 29, 2016 · 22 comments
Assignees
Milestone

Comments

@eacdy
Copy link
Contributor

eacdy commented Dec 29, 2016

It seems that the feign's compression won't work. My version is Spring Cloud Camden SR3.

Here goes my configuration.

application.properties

feign.compression.response.enabled=true
feign.compression.request.enabled=true
feign.compression.request.mime-types=text/xml,application/xml,application/json
feign.compression.request.min-request-size=2048

I found the compression won't work. When I debuged the feign service, I found that the code can never be loaded. like the pic below.
1

Then I go into the code, in spring-cloud-netflix-core

@Configuration
@EnableConfigurationProperties(FeignClientEncodingProperties.class)
@ConditionalOnClass(Feign.class)
@ConditionalOnBean(ApacheHttpClient.class)
@ConditionalOnProperty(value = "feign.compression.request.enabled", matchIfMissing = false)
@AutoConfigureBefore(FeignAutoConfiguration.class)
public class FeignContentGzipEncodingAutoConfiguration {

    @Bean
    public FeignContentGzipEncodingInterceptor feignContentGzipEncodingInterceptor(FeignClientEncodingProperties properties) {
        return new FeignContentGzipEncodingInterceptor(properties);
    }
}

In this line:

@ConditionalOnBean(ApacheHttpClient.class)

this class ApacheHttpClient, is in the jar feign-httpclient .

but the dependency is even not in the classpath. Here goes my POM.XML

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>
  </dependencies>

  <!-- 引入spring cloud的依赖 -->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Camden.SR3</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

So, I added the denpency mannally.

    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-httpclient</artifactId>
    </dependency>

BUT even I did this, Feign's compression can never work.

My Question

  • What's wrong?
  • Is it a bug?
  • feign.compression.request.min-request-size=2048 Does it mean 2048 byte?
@eacdy
Copy link
Contributor Author

eacdy commented Dec 29, 2016

@jmnarloch @ryanjbaxter

@ryanjbaxter
Copy link
Contributor

The feign-httpclient dependency is included in spring-cloud-netflix, so you do not need to include it in your POM. Also notice that it is @ConditionalOnBean meaning the Spring Bean must be present. The bean is created here. However, FeignContentGzipEncodingAutoConfiguration is set to auto configure before FeignAutoConfiguration so the ApacheHttpClient bean will not have been created yet.

This might have worked before this change 959b007. Maybe @spencergibb can verify?

@spencergibb
Copy link
Member

@ryanjbaxter the pom line you pointed to is dependencyManagement not dependency so it is indeed optional and including feign-httpclient is correct. The deletion in 959b007 was a duplicate that is still in FeignAutoConfiguration

@ryanjbaxter
Copy link
Contributor

Right but I think the problem is that FeignContentGzipEncodingAutoConfiguration needs the ApacheHttpClient bean and is set to be configured before FeignAutoConfiguration which creates the ApacheHttpClient bean. There fore the ApacheHttpClient bean will not be there when FeignContentGzipEncodingAutoConfigurationruns.

When the bean was being created twice before (which I agree is a bug) the problem probably didnt exist....at least that is my theory.

@spencergibb
Copy link
Member

So the fix is FeignContentGzipEncodingAutoConfiguration needs @AutoConfigureAfter(FeignAutoConfiguration.class) then?

@spencergibb spencergibb reopened this Jan 9, 2017
@ryanjbaxter
Copy link
Contributor

Yes I think so. But I am also wondering why the condition on the ApacheHttpClient bean is even there to begin with. Maybe @jmnarloch could let us know why that condition is there, it is not obvious to me.

@eacdy
Copy link
Contributor Author

eacdy commented Jan 13, 2017

seems HAPPEN in Camden.SR4, too.

@ryanjbaxter
Copy link
Contributor

@jmnarloch bump, see my comment above, would love your insight.

@jpuigsegur
Copy link

jpuigsegur commented Mar 8, 2017

Hi, This is happening to us also (spring cloud 1.2.2)
Any advance on the final solution?
Suggested workaround meanwhile?

Thanks.

@ryanjbaxter
Copy link
Contributor

@jpuigsegur I was hoping @jmnarloch would comment on the issue, but at this point I think we can just make the change. I dont have a workaround at the moment, I think we can just make the fix I proposed

@ryanjbaxter ryanjbaxter added this to the 1.2.7.RELEASE milestone Mar 8, 2017
@ryanjbaxter ryanjbaxter self-assigned this Mar 8, 2017
@ryanjbaxter
Copy link
Contributor

@jpuigsegur and @eacdy could you please try the fix in this branch and see if it works for you? You can clone the branch, do .mvnw install, and then make sure you depend on Camden.BUILD-SNAPSHOT.

@pgonzalezgua
Copy link

Hello @ryanjbaxter,
I'm working with @jpuigsegur. This commit should solve the request compression. The same problem occurs with the response compression and I think that the same change should be done in the class FeignAcceptGzipEncodingAutoConfiguration.

Thank you for your time.

@ryanjbaxter
Copy link
Contributor

Thanks, made a change there as well. Let me know how it works.

@ryanjbaxter
Copy link
Contributor

@pgonzalezgua @jpuigsegur we are about to do a Camden SR release. I would like to get this in. Did you confirm that the changes are working as expected?

@jpuigsegur
Copy link

Hi, Yes the request compression is working for us with these changes.
Thanks!

@ryanjbaxter
Copy link
Contributor

This has been fixed in both the 1.2.x and master branches.

@davidmelia
Copy link

Hi,

@ryanjbaxter I cannot get this to work. If I create a Spring Boot 1.5.7.RELEASE (Dalston.SR4) Starter Project in eclipse with the following dependencies

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-feign</artifactId>
		</dependency>	
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>io.github.openfeign</groupId>
			<artifactId>feign-httpclient</artifactId>
		</dependency>		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

and add

feign.compression.request.enabled=true
feign.compression.response.enabled=true
feign.httpclient.enabled=true

then GZIP is not enabled

FeignAcceptGzipEncodingAutoConfiguration: {
notMatched: [
{
condition: "OnBeanCondition",
message: "@ConditionalOnBean (types: feign.httpclient.ApacheHttpClient; SearchStrategy: all) did not find any beans"
}
],
matched: [
{
condition: "OnClassCondition",
message: "@ConditionalOnClass found required class 'feign.Feign'; @ConditionalOnMissingClass did not find unwanted class"
},
{
condition: "OnPropertyCondition",
message: "@ConditionalOnProperty (feign.compression.response.enabled) matched"
}
]
},

The only way to get this to work is to add

	@Bean
	public ApacheHttpClient apacheHttpClient() {
		return new ApacheHttpClient();
	}

Thanks

@ingogriebsch
Copy link

ingogriebsch commented Nov 18, 2017

@ryanjbaxter @spencergibb We have more or less the same situation as @davidmelia
The auto configuration is not triggered at all because the ApacheHttpClient bean is not part of the application context at the moment the auto cfg's are triggering.

The way @davidmelia described is not working at all because if we are adding a ApacheHttpClient bean to the context the service is starting up, the auto cfg's are triggering and the header will be set but now the service discovery is not working anymore. Therefore we are in limbo a little bit and don't really know how to configure/use the compression feature.

We are running Spring Boot 1.5.7 and Dalston.SR4. The resolved Spring Cloud Netflix Core version is 1.3.5.RELEASE.

@ryanjbaxter
Copy link
Contributor

@gbtec-ingogriebsch I dont see why service discovery isnt working. I think you should open a new issue for this.

@ingogriebsch
Copy link

@ryanjbaxter In general I would still like to understand how one should configure his system to get compression used on Feign if using Spring Boot 1.5.x and Spring Cloud Dalston.SRX. If I understand it right it is not necessary to do what @davidmelia is trying to do. And I also would like to avoid configuring a ApacheHttpClient @bean if it is not really necessary. Therefore it would be really helpful if you could give some hint about how to do it.

The thing with the service discovery is a problem I got after I added a new @bean of type ApacheHttpClient to my context. Having this bean in the context is enabling the compression but if I try to execute the remote call to the other service which is registered at my local eureka I now get an exception the moment Feign is trying to reach the service. Without having a ApacheHttpClient @bean in the context the remote call is working but then I have no compression.

Before creating a new issue I would like to understand if it is intended to configure a ApacheHttpClient @bean to get the compression enabled.

I would really appreciate a little bit more detailed answer respectively explanation... :)

@ryanjbaxter
Copy link
Contributor

@gbtec-ingogriebsch no you should not have to configure a new ApacheHttpClient bean. Open a new issue with a sample that reproduces the problem and we can look into it.

@ingogriebsch
Copy link

ingogriebsch commented Nov 22, 2017

@ryanjbaxter I have created issue #2462 to clarify if there is a bug or if we are doing something wrong...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants