How to disable eureka lookup on specific #FeignClient - spring-cloud

I have a microservice that uses #FeignClient predominantly to talk to other micro-services. This works beautifuly using Eureka's service discovery mechanism.
Now I have a pressing need to use a #FeignClient to connect to an external system and still perform load balancing using configurations as shown below.
Feign client:
#FeignClient("externalServers")
public interface ExternalServersClient {
#RequestMapping(method = RequestMethod.GET, value = "/someExternalUrl")
ResponseEntity<Object> callExternalServer();
}
application.yml:
externalServers:
ribbon:
listOfServers: server1:18201,server2:18201
From many documentations that I have gone through, it is adviced to disable eureka to allow loadbalancing to be picked up from available listOfServers. I did follow that up and used following configuration to disable it.
application.yml:
ribbon:
eureka:
enabled: false
This allowed me to perform loadbalancing for feign client targeting external systems but all other feign clients that need to use service discovery broke.
Is there any way to disable eureka for feign client setup for external system alone but allow it to function normally for other clients?
Thanks in advance!

In spring-cloud-netflix 1.2.0 (part of the Camden release train), the ability to set the server list implementation was recently added.
You'll be able to do the following:
externalServers:
ribbon:
NIWSServerListClassName: com.netflix.loadbalancer.ConfigurationBasedServerList
listOfServers: server1:18201,server2:18201
Probably released sometime in August or September.

Related

How to use http2 in Feign for better performance RPC?

A new project consider use Spring Cloud build micro service. But we have many inner RPC call within services.
For performance, how to upgrade Feign support http2?
There are gRPC has give a great example for high performance by http2 but our project based on JVM and Feign and relative annotation is good enough for interface definition.
So, I'm first consider Feign support http2 without SSL to speed up RPC.
Hope there are benchmark on http2 if someone has done.
Thanks.
To use http/2 with feign you just need to replace the Http client Bean with a client that prefers http/2.
With default HttpClient (as opposed to OkHttp), you can just add this as a bean, and feign should use it, or you can build it into the feignClient:
HttpClient client = HttpClient.newBuilder()
.version(Version.HTTP_2)
.build();
ref: https://openjdk.java.net/groups/net/httpclient/intro.html
The OkHttp Client may have http/2
I think you would also have to enable http/2 on the server with:
server.http2.enabled: true
This should allow it to receive incoming requests with http/2.
https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.server.server.http2.enabled

spring cloud netflix service to service through zuul

In a spring-cloud-netflix setup (everything uses feign,ribbon,eureka,zuul), is there any simple/elegant/out-of-the-box way (i.e. discovery based on serviceId vs URL) for CompositeAB to communicate to ServiceA and ServiceB through Zuul? In all of the examples I've seen, CompositeAB discovers and calls ServiceA directly vs. via the Zuul route for ServiceA.
Put another way, if ServiceA registers itself in Eureka as service-a, is the automatically created Zuul proxy for service-a exposed in Eureka in any discoverable way?
For real world context, this relates to network topology and firewalls (there's no direct route between CompositeAB and ServiceA - everything needs to go through the gateway). Using URLs in CompositeAB isn't awful, but seems to defeat the purpose of having the registry present (ideally, Zuul would register the proxy for service-a as something like "zuul-service-a" in the registry). That said, i do get how this particular use case doesn't really fit Zuul's purpose as an edge gateway.
Finally, i think i know how to get my desired effect through code - just wanted to check that i wasn't reinventing any wheels first.
Make sure that your Zuul proxy is registering with Eureka and fetching the registry. Any service that registers with eureka will get a route.
You don't have to allow every service that registers with eureka to be accessible via the proxy either.
A sample application.yml for your Zuul proxy that only allows service-a and service-b:
eureka:
client:
fetchRegistry: true
zuul:
add-proxy-headers: true
ignored-services: "*"
routes:
service-a:
serviceId: service-a
service-b:
serviceId: service-b

How can I get specific diagnostic information on an IP address from Zuul?

I have Zuul and Eureka running, with a bunch of smaller services. Using Eureka, I can see all of the services and their associated host/IP address. Usually, I can boot up multiple instances of another service and Eureka will pick them up for Zuul to route to. I'm currently having an issue where I have three instances of a service registered in Eureka, but Zuul only routes to one of them. I don't know where to go to get diagnostic information from Zuul to understand why it isn't routing to the other two instances. I've tried simple things, like manually sending requests from the Zuul box to the service boxes to make sure they can communicate.
Does Zuul expose an endpoint to list hosts/IP addresses and their status? What are my diagnostic options?
You can try to list all your endpoints with the routes endpoint
So, if you running zuul on your localhost on port 8080 you can do a GET call to http://localhost:8080/routes and you will get something like
{
/stores/**: "http://localhost:8081"
}
Depending on the version you are using, you also need to set
management.security.enabled = false
in the application.properties
EDIT:
You can also use the logging mechanism.
Set the loglevel just of the LoadBalancerContext to debug in application.properties
#logging
logging.level.com.netflix.loadbalancer.LoadBalancerContext=DEBUG
It will log each call that is routed.

Can Zuul Edge Server be used without Eureka / Ribbon

We have an infrastructure with service discovery and load balancing (i.e. server side with STM and weblogic cluster). Now we are in the process of refactoring into micro-services. We would need an API gateway which does basic routing to other microservices. Netflix Zuul looks a good candidate however I could not get Zuul working without Eureka - but we do not need Eureka since we already have service discovery and load balancing in place.
Is it possible to use Zuul without Eureka and Ribbon?
If yes please provide some guild-lines since the there's no mention about in the wiki.
Thanks.
Yes, it is totally possible.You have to use #EnableZuulProxy on your config class and config it something like this :
zuul:
routes:
yourService:
path: /yourService/**
serviceId: yourService
ribbon:
eureka:
enabled: false
yourService:
ribbon:
listOfServers: localhost:8080
A sample usage can be like this:
shared.microservice.customer.service1.url=zttp://127.0.0.1:8080/shared/microservice/customer/
shared.microservice.customer.service2.url=zttp://127.0.0.1:8181/shared/microservice/customer/
ribbon.eureka.enabled = false
zuul.routes.customer-micro-service.path: /shared/microservice/customer/**
zuul.routes.customer-micro-service.serviceId: customers
customers.ribbon.listOfServers =
zttp://ip:port1/shared/microservice/customer/,zttp://ip2:port2/shared/microservice/customer/
Yes, Of course you can. Actually, by default, if you use #EnableZuulProxy with the Spring Boot Actuator, you enable two additional endpoints:
Routes
Filters
application.yaml
zuul:
routes:
users:
path: /myusers/**
url: https://example.com/users_service
These simple url-routes do not get executed as a HystrixCommand, nor do they load-balance multiple URLs with Ribbon.
Yo can get more information from here.

spring-cloud with Feign/Ribbon/Eureka - unable to discover service instances

My feign client currently fails to discover service instances using Eureka. My configuration includes the following annotations:
#Configuration
#ComponentScan
#EnableAutoConfiguration
#EnableDiscoveryClient
#FeignClientScan
I included the following dependencies (spring-cloud 1.0.0-BUILD-SNAPSHOT):
org.springframework.cloud:spring-cloud-starter-eureka
com.netflix.feign:feign-core
com.netflix.feign:feign-ribbon
As far as I can tell, the feign client makes use of a ConfigurationBasedServerList and therefore requires the addresses of the available service instances to be explicitly specified in the configuration file (ribbon.serverList property).
However, everything is working fine if I explicitly specify:
ribbon.NIWSServerListClassName: com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
My test application also makes use of a Spring RestTemplate based client automatically configured to make use of an Eureka-enabled Ribbon implementation. Strange thing is that the Feign client is working fine (i.e. finds service instances) if the RestTemplate is invoked first. Looks like the RestTemplate setup performs some (static) initialisations somewhere that then benefit to the feign client.
Do I miss something in how Feign support should be configured?