These are chat archives for spring-cloud/spring-cloud

19th
Feb 2016
Pedro Vilaça
@pmvilaca
Feb 19 2016 14:39
hey guys
I’m facing some problems while trying to use a FeignClient on a new project
it should be enough to add @EnableFeignClients to the configuration class
having spring-cloud-starter-feign dependency declared and it should work, right?
but I’m getting some errors in the ArchaiusAutoConfiguration
looking at the AutoConfiguration class, it’ll be loaded because the Classes that are used to control if it should run or not are in the classpath because the starter pom has a lot of dependencies
Caused by: java.lang.NoClassDefFoundError: com/netflix/config/DeploymentContext$ContextKey
    at org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration.configureArchaius(ArchaiusAutoConfiguration.java:133) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration.configurableEnvironmentConfiguration(ArchaiusAutoConfiguration.java:88) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration$$EnhancerBySpringCGLIB$$6c2c114d.CGLIB$configurableEnvironmentConfiguration$1(<generated>) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration$$EnhancerBySpringCGLIB$$6c2c114d$$FastClassBySpringCGLIB$$72e5a2b2.invoke(<generated>) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318) ~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration$$EnhancerBySpringCGLIB$$6c2c114d.configurableEnvironmentConfiguration(<generated>) ~[spring-cloud-netflix-core-1.1.0.M3.jar:1.1.0.M3]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_31]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_31]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    ... 31 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.netflix.config.DeploymentContext$ContextKey
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_31]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_31]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_31]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_31]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_31]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_31]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_31]
    ... 43 common frames omitted
shouldn’t we be able to just enable feign clients without being forced to disable some AutoConfiguration classes?
Spencer Gibb
@spencergibb
Feb 19 2016 14:45
Yes, file an issue and steps to reproduce.
Pedro Vilaça
@pmvilaca
Feb 19 2016 14:53
thanks @spencergibb
Pedro Vilaça
@pmvilaca
Feb 19 2016 14:59
@spencergibb btw.. isn’t it possible to have an interface for a feignclient that mix feign annotations and spring mvc annotations in order to allow the client to be used by a spring client or anothar application that creates the feignclient manually?
example:
@FeignClient("ingestClient")
public interface IngestClient {

    @RequestMapping(value = "/series/{series}/ingest", method = RequestMethod.POST)
    @RequestLine("POST /series/{series}/ingest")
    @Headers("Content-Type: application/json")
    void injestDataPoints(@Param("series") @PathVariable Series series,
                          @RequestBody List<DataPoint> dataPoints);
}
Spencer Gibb
@spencergibb
Feb 19 2016 15:00
No idea
Pedro Vilaça
@pmvilaca
Feb 19 2016 15:01
I’m getting an exception because spring doesn’t have any argument processor for @Param
and it throws an exception during the startup
Spencer Gibb
@spencergibb
Feb 19 2016 15:02
It's not something we have thought about
Pedro Vilaça
@pmvilaca
Feb 19 2016 15:03
my use case is..
I’ve a spark job that is sending some data for a service that is using spring
and we’ve a job that is running using spring and that also need to send some data to the service
as a quick fix I’ll create two interfaces
but ideally it would be nice to have a better way to do it
Matt Benson
@mbenson
Feb 19 2016 17:38
@pmvilaca if you override the Feign Contract bean you should be able to do whatever you want
Pedro Vilaça
@pmvilaca
Feb 19 2016 17:39
@mbenson like, using the spring annotations instead of the Feign annotations?
that is what you’re suggesting?
Matt Benson
@mbenson
Feb 19 2016 17:40
spring-cloud Feign support already implements support for Spring MVC using a SpringMvcContract bean. If you need to support some hybrid form, or even something completely arbitrary, overriding that bean should let you. You may be doing more reinvention than reuse, though
Pedro Vilaça
@pmvilaca
Feb 19 2016 17:41
got it.. I think that it doesn’t worth the effort
Matt Benson
@mbenson
Feb 19 2016 17:42
actually, a hybrid form might "just work." Looks like the first thing the custom contract does is call the super impl
Pedro Vilaça
@pmvilaca
Feb 19 2016 17:42
it’s a very specific use case
pradeepkusingh
@pradeepkusingh
Feb 19 2016 17:46
@dsyer , @spencergibb - I have a quick question team : We have 1 app which existis in cloud and one legacy environment. I want to use strangulation pattern to slowly move traffic from legacy to Cloud..and I am trying to put this logic in zuul filter, need your help is you have any sample or existing example which I can use to achive same.
pradeepkusingh
@pradeepkusingh
Feb 19 2016 17:55
so we have same app in PCF and legacy environment,
Pedro Vilaça
@pmvilaca
Feb 19 2016 18:40
using feign, if I want to tune the ribbon configuration I need to create a configuration class for each ribbon client?
If ribbon is available it will be used to load balance the backend requests, and the load balancer can be configured using a @RibbonClient with the same name (i.e. value) as the feign client.
(from @FeignClient annotation)
pradeepkusingh
@pradeepkusingh
Feb 19 2016 18:45
@spencergibb : Hi Spencer in Zuul filter to router to eureka I am putting ctx.set("serviceId", appServiceId); , what about URLs not eureka service id , if I want to forward the request to one URL what should I put in zuul context ?
Spencer Gibb
@spencergibb
Feb 19 2016 18:58
@pradeepkusingh look at SimpleHostRoutingFilter
@pmvilaca there is an attribute on @EnableFeignClients for a default configuration
if you don’t want to configure each one individually
Pedro Vilaça
@pmvilaca
Feb 19 2016 19:01
thanks @spencergibb
so, just by adding <clientName>.ribbon.<property> isn’t enough, right?
Spencer Gibb
@spencergibb
Feb 19 2016 19:02
It depends on what your doing, really.
Pedro Vilaça
@pmvilaca
Feb 19 2016 19:03
I was trying to define the listOfServers for a client
@FeignClient(value = "ingestClient")
public interface IngestClientSpring extends IngestClient {`
ingestClient.ribbon.listOfServers=influxer-dev.xxx.com
ingestClient.ribbon.Port=8080
Spencer Gibb
@spencergibb
Feb 19 2016 19:03
that won’t work since the default server list impl is for eureka
assuming eureka is on the classpath
Pedro Vilaça
@pmvilaca
Feb 19 2016 19:05
it isn’t on the classpath but I thought that it would work because listOfServers is present on CommonClientConfigKey
from spring cloud feign docs:
In the @FeignClient annotation the String value ("stores" above) is an arbitrary client name, which is used to create a Ribbon load balancer (see below for details of Ribbon support).
spring cloud ribbon docs:
You can configure some bits of a Ribbon client using external properties in <client>.ribbon.*, which is no different than using the Netflix APIs natively, except that you can use Spring Boot configuration files.
Spencer Gibb
@spencergibb
Feb 19 2016 19:06
yeah, IF eureka isn’t on the classpath a ConfigurationBasedServerList is the default.
Pedro Vilaça
@pmvilaca
Feb 19 2016 19:09
@spencergibb the code is passing on that class
but the properties aren’t being loaded
so I’m getting the defaults
Utility class that can load the List of Servers from a Configuration (i.e properties available via Archaius).
only via Archaius?
Spencer Gibb
@spencergibb
Feb 19 2016 19:17
Nope, we bridge archaius. If it's skipping that class, eureka is on the class path
I'd really need to see a failing project
Pedro Vilaça
@pmvilaca
Feb 19 2016 19:22
@spencergibb the class isn’t skipped.. it’s just the value that isn’t being loaded from the application.properties
but I’ll take a look in detail and I’ll try to create an example project
Spencer Gibb
@spencergibb
Feb 19 2016 19:25
thanks!
If you can recreate it, it’s a bug and should be fixed
Spencer Gibb
@spencergibb
Feb 19 2016 19:55
pradeepkusingh
@pradeepkusingh
Feb 19 2016 20:49
@spencergibb : Thanks :)
Matt Benson
@mbenson
Feb 19 2016 21:33
@spencergibb was any thought ever given to implementing Feign Expanders on the Spring MVC Contract?
it strikes me that it might be straightforward to map over an available Converter from a given parameter type to String
Spencer Gibb
@spencergibb
Feb 19 2016 21:34
nope, I think there is an issue filed for that
PR’s welcome!
Matt Benson
@mbenson
Feb 19 2016 21:52
what's the basic approach to backward compatibility for ctor signatures, etc., in spring-cloud(-netflix)?
Spencer Gibb
@spencergibb
Feb 19 2016 21:52
Add new constructors, leave existing ones
call the new ones with default params passed
Matt Benson
@mbenson
Feb 19 2016 21:54
hmm, not sure what that would be in the case of the ConversionService... maybe it would be better to just let Spring autowire a field on the SpringMvcContract bean?
Spencer Gibb
@spencergibb
Feb 19 2016 21:54
nope, no autowiring fields
we only do autowiring of fields in @Configuration classes
Matt Benson
@mbenson
Feb 19 2016 21:55
I mean, I guess I could just make the behavior dependent on the ConversionService having been passed in to the new constructor
or I could pass a new DefaultConversionService
from the old ctor
Spencer Gibb
@spencergibb
Feb 19 2016 21:57
I’ll review it in a PR, it’s hard to understand what you’re trying to do without seeing code.
Matt Benson
@mbenson
Feb 19 2016 21:57
kk
Matt Benson
@mbenson
Feb 19 2016 23:21
well, I seem to have hit a roadblock. Feign assumes that Expanders will be specified via its annotations as expandable parameters, but I was hoping to be able to simple delegate the expansion to a String conversion from the ConversionService. That would require, however, that the ConversionService be made statically available to an instantiable class. A ThreadLocal might work, but I'm not sure it is appropriate. Any ideas?
Spencer Gibb
@spencergibb
Feb 19 2016 23:25
If you’re using feign’s @Param that doesn’t surprise me.
Matt Benson
@mbenson
Feb 19 2016 23:27
no, I'm trying to get around using @Param and just use the ConversionService, although that wouldn't handle the case in which someone needed a different conversion for different interfaces or different methods.
It might be better to simply add @Param support to SpringMvcContract
Spencer Gibb
@spencergibb
Feb 19 2016 23:28
so how are you trying to add the expander?
Matt Benson
@mbenson
Feb 19 2016 23:29
my current code is inspecting handled parameters for convertibility, then setting a class reference. Then I could set the value of a ThreadLocal to the injected ConversionService but it would still have the shortcomings I mentioned above. It might still be a nice option though.