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

19th
Apr 2016
Bartek Andrzejczak
@bandrzejczak
Apr 19 2016 08:57
Hi guys. I've annotated multiple interfaces with @FeignClient but the problem is that every client refers to the same eureka service. If I have one client I can annotate it with @FeignClient("myclient") which resolves eureka service just fine, but what if I have two? If I annotate them with @FeignClient(name = "first", url = "http://myclient/") and @FeignClient(name = "second", url = "http://myclient") it doesn't work any more. Should it work, but there this is just a bug, or is there some other way of declaring multiple clients using the same eureka service?
Darek Kaczyński
@kaczynskid
Apr 19 2016 08:59
This message was deleted
Dave Syer
@dsyer
Apr 19 2016 09:02
I don't think that you can have multiple clients with the same service
That would be a new feature I guess
Spencer Gibb
@spencergibb
Apr 19 2016 09:03
@bandrzejczak the url attribute is for fully qualified URLs, not service ID URLs.
Dave Syer
@dsyer
Apr 19 2016 09:04
Indeed
(it does say that in the javadocs I think)
Darek Kaczyński
@kaczynskid
Apr 19 2016 09:05
yeah, but wouldn't that be nice if it worked just like the RestClient? :)
Dave Syer
@dsyer
Apr 19 2016 09:05
Yes. that's why I said it's a new feature.
Darek Kaczyński
@kaczynskid
Apr 19 2016 09:29

how can I force a service to register in eureka using a hostname, not an IP address? I'm trying with:

eureka:
  instance:
    hostname: example.com

but in Eureka dashboard I still can see the IP address, not the hostname :(

and also Zuul proxy is than using the IP instead of the hostname, while my service requires to be accessed via domain name instead
Dave Syer
@dsyer
Apr 19 2016 09:32
Did you set eureka.instance.preferIpAddress somewhere?
Darek Kaczyński
@kaczynskid
Apr 19 2016 09:32
no
Dave Syer
@dsyer
Apr 19 2016 09:32
Do you have a simple sample that reproduces the problem?
Darek Kaczyński
@kaczynskid
Apr 19 2016 09:34
Not really. But I use SpringBootServletInitializer to initialize this app on tomcat, and it seems to behave differently that another one with embedded tomcat.

yeah, when I set:

eureka:
  instance:
    preferIpAddress: false
    hostname: config.example.com
    nonSecurePort: 8888

in a standard Spring Boot app it works like a charm

Dave Syer
@dsyer
Apr 19 2016 09:38
I don't know why that would affect anything, unless your container defines eureka.instance.preferIpAddress=true and you didn't notice
Look in the /env endpoint
Darek Kaczyński
@kaczynskid
Apr 19 2016 09:45
yeah :/ I had another bootstrap.yml on the classpath that set it to true but I was hoping the file from spring.cloud.bootstrap.location and spring.config.location would take precedence anyway
when I removed the file from the classpath, it works
Koizumi85
@Koizumi85
Apr 19 2016 09:50

@dsyer @kaczynskid I am pretty sure you can have two @FeignClientinstances which are referring to the same service id... I had this in a previous project. Simply as the following:

@FeignClient("myservice")
public interface MyServiceFeignClient1 {
...
}

@FeignClient("myservice")
public interface MyServiceFeignClient2 {
...
}

Or did I missunderstand your question?

Bartek Andrzejczak
@bandrzejczak
Apr 19 2016 09:52
That was the question exactly. If that's the case, than it's good to hear that. :)
Dave Syer
@dsyer
Apr 19 2016 09:54
I guess that makes sense. But you can't configure them differently.
The ribbon client underneath is the same
Bartek Andrzejczak
@bandrzejczak
Apr 19 2016 09:54
That's quite fine. If we've had one client with multiple inheritance it would be the same, with one ribbon cient underneath.
Koizumi85
@Koizumi85
Apr 19 2016 09:56
@dsyer why not? You can add a client specific configuration to both of them or?
@FeignClient(value "myservice", configuration = Xyz.class)
public interface MyServiceFeignClient1 {
...
}

@FeignClient(value "myservice", configuration = Zyx.class)
public interface MyServiceFeignClient2 {
...
}
Dave Syer
@dsyer
Apr 19 2016 09:56
Actually, you can. But the archaius bindings from myservice.ribbon.* will be shared
Koizumi85
@Koizumi85
Apr 19 2016 09:57
ah okay.. thats right... didn't thought about archaius or something like this ^^
Marcin Grzejszczak
@marcingrzejszczak
Apr 19 2016 10:01
actually you can try to hack Ribbon the way I did with Zookeeper dependencies
where I remap the provided name in Ribbon to a proper registered application in Zookeeper
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:06

would sth like this work:

@FeignClient(value = "myservice", url = "${myservice.url}")

?

Dave Syer
@dsyer
Apr 19 2016 10:06
I don't see how that could work. I think it's illegal to specify both a value and a url.
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:06
you can specify both
it works
but can you use placeholders?
Dave Syer
@dsyer
Apr 19 2016 10:07
Really?
Bartek Andrzejczak
@bandrzejczak
Apr 19 2016 10:07
Shouldn't it be name and url?
Dave Syer
@dsyer
Apr 19 2016 10:07
Isn't value an alias for name?
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:07
well, I have it running right now :)
Dave Syer
@dsyer
Apr 19 2016 10:07
What does it mean if you specify both?
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:08
I'm not sure. I don't really need the name, and it just uses the url, so I can remove the name
Koizumi85
@Koizumi85
Apr 19 2016 10:08
really..? but why should you do that? shouldn't the url be determined by eureka?
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:08
yes, it should :)
Koizumi85
@Koizumi85
Apr 19 2016 10:08
then you should just have to use the name, not the url, or?
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:08
belive me, I don't want to do that, but for the moment I have to :(
Koizumi85
@Koizumi85
Apr 19 2016 10:08
ah okay...
Bartek Andrzejczak
@bandrzejczak
Apr 19 2016 10:09
Javadoc says Either serviceId or url must be specified but not both., so it's a little bit deprecated, because serviceId is already deprecated.
Dave Syer
@dsyer
Apr 19 2016 10:09
the javadocs say use "name" instead of "serviceId"
and "name" is an alias for "value"
So it should be illegal to specify both
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:11

ok, let me rephrase my question :)
would sth like this work:

@FeignClient(url = "${myservice.url}")

?

Bartek Andrzejczak
@bandrzejczak
Apr 19 2016 10:11
I remember that I got exception for using both in previous version of feign. But nevermind. What about placeholder? Does url resolving for feign uses environment properties.
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:12
I'll test it, and let you guys know :)
Koizumi85
@Koizumi85
Apr 19 2016 10:12
@kaczynskid I think there was an issue to support placeholders in feign client annotations, but not sure if this was closed already and if it was for the url, or for something else :D
Dave Syer
@dsyer
Apr 19 2016 10:13
It seems like a name is mandatory in 1.1 (I'm pretty sure it was illegal to use both in 1.0, which explains the javadocs).
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:13
we're using 1.1.0.RC1
Dave Syer
@dsyer
Apr 19 2016 10:15
The default name is empty (apparently)
so you don't have to set it as a user
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:15
I do have to :) When I removed it I got:
 ERROR[main] SpringApplication - Application startup failed
java.lang.IllegalStateException: Either 'name' or 'value' must be provided in @FeignClient
    at org.springframework.cloud.netflix.feign.FeignClientsRegistrar.getClientName(FeignClientsRegistrar.java:321)
Dave Syer
@dsyer
Apr 19 2016 10:17
OK, I see that code.
We need to fix the javadocs
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:21

ok, so the answer is: yes, you can use placeholders like this:

@FeignClient(name = "myservice", url = "${myservice.url}")

awesome :)

Piotr Lewandowski
@navaro1
Apr 19 2016 10:51
Hello guys, I have problem with cloud-consul + docker configuration
I have two dockers on two different hosts
one contains Consul, other spring cloud application
and it sends wrong information about it location
as - docker host IP, not proper host IP
anyone knows hwat to do with this?
Darek Kaczyński
@kaczynskid
Apr 19 2016 10:53
@navaro1 application running within docker container knows only about docker container IP, it has no knowledge about the docker host networking
it's working correctly and it's not a Spring problem
it's about Docker and how it's networking works
Piotr Lewandowski
@navaro1
Apr 19 2016 10:54
okay
thank you :)
Donovan Muller
@donovanmuller
Apr 19 2016 12:36

I have a @FeignClient interface and trying to override/mask this in an integration test.
I'm trying with:

@Bean
@Primary
public FeignThingy feignThingy() {
    ...
}

however, seems @FeignClient is also primary (not sure where, not on annotation?). Getting:

... [FeignThingy] is defined: more than one 'primary' bean found among candidates:
any ieas?
Dave Syer
@dsyer
Apr 19 2016 12:37
It's primary by construction. Not sure why.
Donovan Muller
@donovanmuller
Apr 19 2016 12:37
Anyway to disable Feign configuration for tests?
Dave Syer
@dsyer
Apr 19 2016 12:37
That's an interesting use case though
Donovan Muller
@donovanmuller
Apr 19 2016 12:37
Like feign.httpclient.enabled etc.
Dave Syer
@dsyer
Apr 19 2016 12:38
I guess you control it yourself with @EnableFeignClients
You just need to not include that in your test config?
Donovan Muller
@donovanmuller
Apr 19 2016 12:39
Will give it a try... is there a reason it's constructed as primary?
Dave Syer
@dsyer
Apr 19 2016 12:41
I don't know. I suspect Spencer did it.
Donovan Muller
@donovanmuller
Apr 19 2016 14:31
This message was deleted
Donovan Muller
@donovanmuller
Apr 19 2016 14:38

I have my Application with:

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class Application {

  public static void main(final String[] args) {
      SpringApplication.run(Application.class, args);
  }
}

and a TestApplication with:

@SpringBootApplication
public class TestApplication {

}

and a test with:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration({
   TestApplication.class,
   SomeIntegrationTest.MoreTestConfiguration.class
})
@IntegrationTest
@ActiveProfiles("test")
public class SomeIntegrationTest {

...

why does the test still pick up the config in Application?

I.e. (related to the Feign question above) if I remove @EnableFeignClients from Application test runs as expected.
This is even though it (Application) is NOT referenced in @SpringApplicationConfiguration.

??

Matt Benson
@mbenson
Apr 19 2016 14:52
so I would like to be able to organize configserver resources by directory. Any reasons why this would not be an appropriate feature? @dsyer ? Others?
Dave Syer
@dsyer
Apr 19 2016 15:27
What is it that you can't do already?
why does the test still pick up the config in Application?
probably a @ComponentScan?
Your test config would have to be in a different (no enclosed) package.
Matt Benson
@mbenson
Apr 19 2016 15:41
@dsyer I am confused by those last few lines. I want to be able, for starters, to request resource e.g. data/foo.xml for project x, profile y, label z e.g. x/y/z/data/foo.xml
again, I'm talking about spring-config-server here
Donovan Muller
@donovanmuller
Apr 19 2016 15:42
@mbenson think @dsyer was replying to my question...
Dave Syer
@dsyer
Apr 19 2016 15:42
Indeed
Matt Benson
@mbenson
Apr 19 2016 15:42
;)
Dave Syer
@dsyer
Apr 19 2016 15:43
/x/y/z/data/foo.xml is a valid resource path with no extra configuration or customization, so I'm still confused
Matt Benson
@mbenson
Apr 19 2016 15:46
have you tried it? Your RequestMapping is tokenized by /, so it doesn't match. I have a local change that uses a trailing /** instead of /{path:.*}
Dave Syer
@dsyer
Apr 19 2016 15:47
Hmm. That's annoying.
Matt Benson
@mbenson
Apr 19 2016 15:47
+1 ;)
Dave Syer
@dsyer
Apr 19 2016 15:47
Spring MVC and "/" is a PIA
I'm not sure it's possible
You said you had something that works?
Matt Benson
@mbenson
Apr 19 2016 15:50
yes
Dave Syer
@dsyer
Apr 19 2016 15:50
Does it break anything else?
Matt Benson
@mbenson
Apr 19 2016 15:51
no
I'll push my branch up and open a PR to begin from
there it is
Dave Syer
@dsyer
Apr 19 2016 15:54
So you have to pass in the HttpServletRequest
I hate that
Matt Benson
@mbenson
Apr 19 2016 15:55
:/ If there's a slicker way that'd be great
Dave Syer
@dsyer
Apr 19 2016 15:55
I said it was a PIA
Donovan Muller
@donovanmuller
Apr 19 2016 16:01
@dsyer, would it be valid to log an issue to look into not making @FeignClient's primary? This is where it's set
Dave Syer
@dsyer
Apr 19 2016 16:02
Sure. We can ping @spencergibb to get his opinion. He did it recently.
Why not see if it was part of a github issue?
Donovan Muller
@donovanmuller
Apr 19 2016 16:05
Checked, didn't find anything existing
Dave Syer
@dsyer
Apr 19 2016 16:06
spring-cloud/spring-cloud-netflix#899
It's because of fallbacks
Donovan Muller
@donovanmuller
Apr 19 2016 16:07
doh 😬 thanks, will take a look
Darek Kaczyński
@kaczynskid
Apr 19 2016 16:11

@donovanmuller it's a good idea to put all SpringCloud @Enable annotations behind some Spring profile; this way it's easy to run the app without them and provide mocks in tests instead; just try sth like this:

@SpringBootApplication
public class Application {
}

@Profile("cloud")
@EnableDiscoveryClient
@EnableFeignClients
public class ApplicationConfig {
}

@Profile("test")
public class TestApplicationConfig {
    // decalre your mocks for Spring Cloud components here
}

than run your app in production with cloud profile, and in tests with test profile

Donovan Muller
@donovanmuller
Apr 19 2016 16:12
Was hoping not to have "test" profile specific code in the main source but may not have a choice...
Darek Kaczyński
@kaczynskid
Apr 19 2016 16:13
but with this you don't have
both Application and ApplicationConfig live in src/main
and TestApplicationConfig lives in src/test
Donovan Muller
@donovanmuller
Apr 19 2016 16:14
ok, will give it a whirl...
Dave Syer
@dsyer
Apr 19 2016 16:14
Spring Boot 1.4 has @MockBean
But that won't work with Spring Cloud yet
Donovan Muller
@donovanmuller
Apr 19 2016 16:18
This message was deleted
Donovan Muller
@donovanmuller
Apr 19 2016 16:25
Thanks @kaczynskid, went with something similar to your suggestion
Looking forward to @MockBean
Matt Benson
@mbenson
Apr 19 2016 16:32
so what does that mean for #376?
also, WDYT about extending the cloud-config-server to support some means of searching for resources matching a Ant path spec?
Dave Syer
@dsyer
Apr 19 2016 16:35
If we get a solution to SPR-14193 in Spring we won't need the HttpServletRequest hack in #376
Searching for resources is something we already do, but we can only return one. Ant paths can match multiple resources, and the order isn't defined.
Matt Benson
@mbenson
Apr 19 2016 16:37
I saw that wrt #376; was just wondering if it was then going to be waiting on Spring 5
Dave Syer
@dsyer
Apr 19 2016 16:37
Don't know.
Probably not
4.3 is nearly out though
so if we don't get anything there we'll have to hack, I guess
Matt Benson
@mbenson
Apr 19 2016 16:38
I realize only one resource could be returned at a time; I was thinking of adding another call or a parameter perhaps, to call for a json representation of the matching resources found.
Dave Syer
@dsyer
Apr 19 2016 16:39
Yuck
Matt Benson
@mbenson
Apr 19 2016 16:39
:)
Dave Syer
@dsyer
Apr 19 2016 16:40
Another endpoint seems more appropriate if you need it
but how would it be used?
If you find there are 2 resources that match your search, what would you do?
Matt Benson
@mbenson
Apr 19 2016 16:41
I haven't fully researched, but I was thinking about setting up another resource prefix so I could inject a Resource[] based on e.g. configserver:**/*.ext
Dave Syer
@dsyer
Apr 19 2016 16:43
OK, so you actually want them all.
I just realized there's a problem with the implementation anyway
If we start accepting "/" as part of a file path, we should also accept it as part of a git label
Matt Benson
@mbenson
Apr 19 2016 16:44
why? Wouldn't it be prohibitively difficult to do both?
Dave Syer
@dsyer
Apr 19 2016 16:45
So I think if we might do this we should add a prefix (e.g. /files to the file endpoint)
It's not difficult it's impossible
They overlap
How can you tell the difference between a git label and a file name?
Matt Benson
@mbenson
Apr 19 2016 16:45
you already support _ for label
Dave Syer
@dsyer
Apr 19 2016 16:45
Yeah, but that was a hack as well
If we can support "/" in filenames we can do it in labels too
Matt Benson
@mbenson
Apr 19 2016 16:48
I thought the _ was handy to keep them separate
Dave Syer
@dsyer
Apr 19 2016 16:49
spring-cloud/spring-cloud-config#377
"_" was s hack we were forced to make to avoid parsing HttpServletRequests
Matt Benson
@mbenson
Apr 19 2016 16:51
your thought being that as long as you're parsing them, might as well do everything? So you're thinking /files goes at the beginning of the whole endpoint to disambiguate from the basic properties request?
Dave Syer
@dsyer
Apr 19 2016 16:51
Yes
Matt Benson
@mbenson
Apr 19 2016 16:51
Then you have to tokenize the whole thing and figure out where the label ends and the path begins by, what, trial and error?
Dave Syer
@dsyer
Apr 19 2016 16:52
I think the code in https://jira.spring.io/browse/SPR-14032 would work
You know the prefix so you can easily find it and remove it from the URL path
Ah, I get it.
The files endpoint cannot have "/" in labels and file paths
Phooey
Maybe "_" is needed there
We could use the same hack in the resources controller
But "_" is quite common in file names
Matt Benson
@mbenson
Apr 19 2016 16:54
_? It's in the resources controller
Dave Syer
@dsyer
Apr 19 2016 16:54
It's in the EnvironmentController too
Matt Benson
@mbenson
Apr 19 2016 16:55
I'm sure, I was just saying it's already supported in resources
Dave Syer
@dsyer
Apr 19 2016 16:55
Of course
Matt Benson
@mbenson
Apr 19 2016 16:55
then I'm confused by what you meant "we could use the same hack in the resources controller"
Dave Syer
@dsyer
Apr 19 2016 16:56
How about /{name}/{profile}/{label}/files/{path}?
Matt Benson
@mbenson
Apr 19 2016 16:56
but still requiring _ in {label}? WFM
or just looking for /files to mark the difference to find / in {label}?
Dave Syer
@dsyer
Apr 19 2016 16:59
What happens when a label has "/files" in it?
It's legal in git. So it all sucks basically.
I need to go away and think about it
Thanks for the PR
Matt Benson
@mbenson
Apr 19 2016 17:07
thanks for your time
Donovan Muller
@donovanmuller
Apr 19 2016 17:23
Does the SC feign implementation support @RequestHeader as a param? I.e. setting something as a header when calling the feign interface
Matt Benson
@mbenson
Apr 19 2016 17:49
@donovanmuller it should and from looking at the code I'd guess it does.
Marcos Barbero
@marcosbarbero
Apr 19 2016 18:37
@dsyer @spencergibb when you have a spare time please take a look on this PR spring-cloud/spring-cloud-netflix#979
Marcos Barbero
@marcosbarbero
Apr 19 2016 20:23
Is everything ok with Brixton.RC2? When I run maven package I got this message in console before build fails
[WARNING] The POM for org.springframework.cloud:spring-cloud-starter-oauth2:jar:1.1.0.RC2 is missing, no dependency information available
Dave Syer
@dsyer
Apr 19 2016 20:52
Don't know. Do you have a flakey wifi?
Dave Syer
@dsyer
Apr 19 2016 20:59
Wait. That is a problem. There is no RC2 of the security stuff.
Thanks.
I'll just re-push the dependencies BOM
Marcos Barbero
@marcosbarbero
Apr 19 2016 21:00
Thanks
Dave Syer
@dsyer
Apr 19 2016 21:01
Done.
You may need to remove your cached version of the spring-cloud-dependencies BOM
Marcos Barbero
@marcosbarbero
Apr 19 2016 21:03
Ok I’ll do that right now
Marcos Barbero
@marcosbarbero
Apr 19 2016 21:22
Everything is working fine