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

26th
Jan 2018
Dave Syer
@dsyer
Jan 26 2018 07:25
Yes. And both source and sink bridge to/from a broker via the the binder abstraction. It's a simple pattern, actually. Maybe you are overthinking it?
Abhishek Dujari
@abshkd
Jan 26 2018 14:44
@dsyer Is it true that RestTemplate does not support eureka client for lookups?
i am using 1.5.6
Abhishek Dujari
@abshkd
Jan 26 2018 14:58
i mean spring boot version 1.5.6
Dave Syer
@dsyer
Jan 26 2018 15:20
Don't know what you mean
Abhishek Dujari
@abshkd
Jan 26 2018 15:21
I am using DiscoveryClient and Eureka registry. But when I use RestTemplate to call http://serviceAName/api/ It cannot be resolved
i have to use external URL
yelhouti
@yelhouti
Jan 26 2018 15:23
@abshkd this is indeed the right place to ask :)
Abhishek Dujari
@abshkd
Jan 26 2018 15:23
All services register to eureka just fine
@yelhouti yeah :D
i want to be sure since I am super stupid
so i could be doing something wrong
many things change so fast
Dave Syer
@dsyer
Jan 26 2018 15:25
How did you construct the rest template?
yelhouti
@yelhouti
Jan 26 2018 15:25
No you're not, I don't think the answer will change, but I'll gladely hear an answer athat contradcits what was said earlier
Abhishek Dujari
@abshkd
Jan 26 2018 15:25
@dsyer I just create a new object within my method where I want to make the API call
yelhouti
@yelhouti
Jan 26 2018 15:25
and of course @dsyer is the right person to answer you :)
Dave Syer
@dsyer
Jan 26 2018 15:25
Is has to be @LoadBalanced. It’s all in the user guide and samples
Abhishek Dujari
@abshkd
Jan 26 2018 15:25
I tried this way too
 @Autowired
    @LoadBalanced
    protected RestTemplate restTemplate;
but i get unsatisfied dependency
Dave Syer
@dsyer
Jan 26 2018 15:26
Then that’s your problem
Maybe you don’t have ribbon on the classpath?
Abhishek Dujari
@abshkd
Jan 26 2018 15:27
i dont
i didnt think it was required but now that you mention it ...
also i know you asked me to go read DI an dstuff but I am still green
ill try with ribbon
yelhouti
@yelhouti
Jan 26 2018 15:28
let me knwo please @abshkd if it works
Abhishek Dujari
@abshkd
Jan 26 2018 15:28
i assumed that having @EnableDiscoveryClient would be enough, but it is not?
yelhouti
@yelhouti
Jan 26 2018 15:29
and @dsyer once you use ribbon how do you configure resTemplate headers please
(to add Authentication)
Raja Sundaram
@zeagord
Jan 26 2018 15:29
Docs..docs..docs
Abhishek Dujari
@abshkd
Jan 26 2018 15:29
@yelhouti I have the same xact use case. i am checking docs
yelhouti
@yelhouti
Jan 26 2018 15:29
@zeagord Sorry I'm out :p (totally diserved)
Abhishek Dujari
@abshkd
Jan 26 2018 15:38
I am reading an example (i couldnt figure out the docs) and its using @RibbonClient so that is what I need to define as well?
Raja Sundaram
@zeagord
Jan 26 2018 15:39
No you don’t have to. Do you have example project? If so upload to Github or any repo. I will take a look.
Abhishek Dujari
@abshkd
Jan 26 2018 15:39
I can tupload my company projects to github
i am sure they will not like it
but i am using jhipster, and the microservice generated by it
i can find you the sample project because it sthe same skeleton
yelhouti
@yelhouti
Jan 26 2018 15:41
@abshkd insetad of doing restTemplate=new RestTemplate()
@yelhouti pls continue. i dont like the suspense
:D
yelhouti
@yelhouti
Jan 26 2018 15:43
do
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
    return new RestTemplate();
}
Abhishek Dujari
@abshkd
Jan 26 2018 15:43
if that works i feel reeeally dumb
yelhouti
@yelhouti
Jan 26 2018 15:43
and
@Autowired RestTemplate;
if it works tell me please :)
Abhishek Dujari
@abshkd
Jan 26 2018 15:45
where do you inject that Bean? can I do it within the class where I need it?
i am doing it now
if it works you can go blog about it :D
I'd say it might work. I am getting the right errors now like No instances available for http://nonexistanthostname/
i am going to update my test now and figure how to mock this so my tests can work
yelhouti
@yelhouti
Jan 26 2018 15:50
Yes you can/should (inject=Autowired) declaration can (shouldn't) be in the same place
greate I'll try later
Abhishek Dujari
@abshkd
Jan 26 2018 15:51
all ic an say, it can (should) work
but i am going to keep going forward
yelhouti
@yelhouti
Jan 26 2018 15:51
good luck
Abhishek Dujari
@abshkd
Jan 26 2018 15:51
if you can figure out how to test it, that will be great.
Abhishek Dujari
@abshkd
Jan 26 2018 16:07
when i do it the way @yelhouti describes, the resttemplate cannot resolve regular URLs. O guess I have to inject only where i need it
yelhouti
@yelhouti
Jan 26 2018 16:08
Indeed
@abshkd
Abhishek Dujari
@abshkd
Jan 26 2018 16:09
it seems to be automatically working for TestRestTemplate as well. I think the behaviour is global
even though i did the inject and declaration inside the class where I need it
sorry my bad
ofcourse its on the test, the rest works fine so i got it right
any clues on how you run tests with this?
i cant ofcourse resolve anything
Abhishek Dujari
@abshkd
Jan 26 2018 16:21
nvm thats another rabbit hole
Abhishek Dujari
@abshkd
Jan 26 2018 16:43
there is a way to solve this problem for local development and tests but I cant figure out how. Like when the Bean is injected we can say that dont use the resolver when you're in test profile or dev profile
but then its confusing because in those environments resttemplate cant be picked up simply by autowiring
Tyler Thrailkill
@snowe2010
Jan 26 2018 17:02
I'm having trouble reading this error message

2018-01-26 16:59:04.515  INFO 1 --- [nio-8080-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: iam-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2018-01-26 16:59:04.573  INFO 1 --- [nio-8080-exec-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-iam-service
2018-01-26 16:59:04.713  INFO 1 --- [nio-8080-exec-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client:iam-service instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=iam-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2018-01-26 16:59:04.728  INFO 1 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2018-01-26 16:59:04.743  INFO 1 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client iam-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=iam-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@7a4aac0a
2018-01-26 16:59:05.629  WARN 1 --- [nio-8080-exec-1] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering


com.netflix.zuul.exception.ZuulException: Forwarding error
        at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:170) ~[spring-cloud-netflix-core-1.2.7.RELEASE.jar!/:1.2.7.RELEASE]
        at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:145) ~[spring-cloud-netflix-core-1.2.7.RELEASE.jar!/:1.2.7.RELEASE]
        at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:88) ~[spring-cloud-netflix-core-1.2.7.RELEASE.jar!/:1.2.7.RELEASE]
        at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.3.0.jar!/:1.3.0]
...very large stacktrace....

Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: iam-service
        at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:468) ~[ribbon-loadbalancer-2.2.0.jar!/:2.2.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184) ~[ribbon-loadbalancer-2.2.0.jar!/:2.2.0]
        at com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180) ~[ribbon-loadbalancer-2.2.0.jar!/:2.2.0]
        at rx.Observable.unsafeSubscribe(Observable.java:10211) ~[rxjava-1.1.10.jar!/:1.1.10]
....morestack...
it appears that spring is able to find the load balancer, but then it has no server. I'm not sure how to even begin to debug this.
Tyler Van Gorder
@tkvangorder
Jan 26 2018 17:08
@snowe2010 This is telling you that there are no instances of the down stream service "iam-service" registered with the discover service. You can see this in the info logging: c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client iam-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=iam-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@7a4aac0a
Tyler Thrailkill
@snowe2010
Jan 26 2018 17:12
@tkvangorder is the discover service the spring service or my k8s load balancer? I swear I had this working before, but it's been a month.
Tyler Van Gorder
@tkvangorder
Jan 26 2018 17:23
The load balancer is running on your client (the one making the rest call). We use Eureka as our service discovery, rather than the Kubernetes service, but it should be similar. Your downstream application must register with Kubernetes. The client load balancer will ping the Kubernetes server to ask it for a list of registered services (The Eureka client does this every 30 seconds). Each call you make using "iam-service", will result in the load balancer checking it's local client cache for instances registered with that name. The local cache means that there can be some latency before your service "shows up".
so either: your downstream service is NOT registered with kubernetes, the client load balancer is not correctly wired to ping kubernetes (make sure the client is not talking to a different discovery service than the down stream service), or you need to wait "some amount of time" (sometimes it takes up to a minute) before you make your client call.
Tyler Thrailkill
@snowe2010
Jan 26 2018 17:37
@tkvangorder I'm guessing it's the second problem then. the client load balancer is not correctly wired to ping kubernetes (make sure the client is not talking to a different discovery service than the down stream service), but I don't see how that could be. I have many applications, but let's discuss the two in question. One is gateway which is just a zuul router written with spring-boot.
gateway routes all connections to our services, one of which is iam-service. These are both deployed to kubernetes (GCE) and I'm using postman to hit the gateway just to duplicate this error. You are saying that gateway is the rest client in this case, and it is running the load balancer (different than the forwarding rules from a kubernetes Service LoadBalancer right?) and it is not correctly pinging kubernetes properly?
I am attempting to just use the plain kubernetes discovery, I don't want to use Eureka or anything else. My application.yml looks like this (removed a bunch of stuff I hope doesn't matter)
hystrix:
  command:
    default:
      execution:
        timeout:
          enabled: false
        isolation:
          thread:
            timeoutInMilliseconds: 60000
zuul:
  host:
    connect-timeout-millis: 10000
    socket-timeout-millis: 60000
spring:
  cloud:
    kubernetes:
      discovery:
        enabled: true
ribbon:
  eureka:
    enabled: false
  ReadTimeout: 30000
  ConnectTimeout: 30000
zuul:
  routes:
    iam:
      url: ${IAM_SERVICE_URL:http://iam-service:9008}
I don't know if I actually need the hystrix and ribbon settings, but I didn't want those being enabled since we're using spring-cloud-starter-zuul
Tyler Van Gorder
@tkvangorder
Jan 26 2018 19:39
Your zuul server will need to have the spring-cloud-kubernetes integration. I believe that is all a third-party implementation and you might be better off pinging those guys: https://github.com/fabric8io/spring-cloud-kubernetes
I dont have much more I can contribute, as we are not using any of the kubernetes infrastructure. I am assuming you using https://github.com/fabric8io/spring-cloud-kubernetes#discoveryclient-for-kubernetes
Tyler Thrailkill
@snowe2010
Jan 26 2018 20:29
yes, well spring recently absorbed the spring-cloud-kubernetes project, but that is what I'm using. And yes, my zuul server has that dependency included. I'm sure I've got just the tiniest thing misconfigured, but I can't figure out what it is. :/