spring zuul + eureka route delegation - spring-cloud

Im working with Spring Cloud Zuul + Eureka Server. i know that Zuul will create routes dynamically when there is a service registered on Eureka and it will be route using their Service ID. Is it possible to delegate routes to group services ?
for example i have 2 services that i want to group:
server.port=8081
spring.application.name=company-account-api
server.port=8082
spring.application.name=company-transaction-api
eureka config
spring.application.name=api-discovery
spring.cloud.config.uri=${CONFIG_SERVER_URL:http://localhost:8888}
on Zuul is it possible define a route where i can access the 2 services registered on eureka ?
server.port=9090
spring.application.name=api-gateway
eureka.instance.preferIpAddress=true
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.serviceurl.defaultzone=http://localhost:8761/eureka
zuul.routes.company-api=/company-**
so when i access http://localhost:9090/company-api/company-account-api & http://localhost:9090/company-api/company-transaction-api the service registered on eureka will be available

You can achieve this with the following config
zuul.ignored-services=*
zuul.routes.company-account-api.serviceId=company-account-api
zuul.routes.company-account-api.path=/company-api/company-account-api/**
zuul.routes.company-transaction-api.serviceId=company-transaction-api
zuul.routes.company-transaction-api.path=/company-api/company-transaction-api/**
Explanation:
zuul.ignored-services=* This will supress the default config
zuul.routes.company-account-api.serviceId=company-account-api
zuul.routes.company-account-api.path=/company-api/company-account-api/**
What is exposed to public is /company-api/company-account-api/** which will be internally mapped to company-account-api service.
If you are not using service discovery then you can do it using url instead of service name
zuul.routes.company-account-api.url=http://accountapihost:accountapiport
zuul.routes.company-account-api.path=/company-api/company-account-api/**

Related

Deployment Context Based Vip Address in Spring Cloud Load Balancer

We are looking to of move to Spring Cloud Load Balancer to replace Ribbon. We use Eureka for service discovery and registration.
It looks like as of Spring Cloud Netflix 3.x, the EurekaRibbonClientConfiguration in the Eureka client module has been removed.
We were using the deploymentContextBasedVipAddress configuration to map our internal host name to a registered vip address in Eureka.
The configuration was similar to this:
some-sevice-v1.ribbon.NIWSServerListClassName=com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
some-sevice-v1.ribbon.DeploymentContextBasedVipAddresses=some_service-v1
some-sevice-v1.ribbon.NIWSServerListFilterClassName=com.netflix.loadbalancer.ServerListSubsetFilter
We do this because the vip address that is registered with Eureka contains an _ in it and which is technically an invalid character for host names; the Java URI class will fail to parse a host with a _ in it. We are not able to change this at this point.
So my question is; can this similar configuration be done with Spring Cloud Load Balancer and the new Eureka client module in Spring Cloud Netflix 3.x, where we can provide aliasing for the vip address?
We have faced the same issue. Currently, we are using the following workaround for our feign clients:
#FeignClient(
value = "${my.amazing.service.name:amazing-service-name-default}",
contextId = "amazing-service",
configuration = AmazingServiceClientConfiguration.class,
path = "/amazing-service"
)
public interface AmazingServiceClient {
...
}
We can configure my.amazing.service.name the same way as DeploymentContextBasedVipAddresses.
There is also an open ticket for this issue: https://github.com/spring-cloud/spring-cloud-commons/issues/951
Hope, this helps.

Ribbon- Calling a specific uri of an application from urls obtained from Eureka

Lets consider the following situation.This example will only have urls containing localhost. I have a zuul proxy setup and lets say its running on port 8080. So
Zuul proxy-
localhost:8080
I have an eureka server setup running on port 81.
Eureka server-
localhost:8081.
I have an application lets call it by name-example which is a REST web service. Its running on 3 different ports 82,83 and 84. All 3 instances are registered with eureka server. I have a filter setup in zuul for the uri /example.
So i expect consumers to call the zuul proxy at locahost:8080/example.
Now, in the application example for the request mapping /example, there is a controller setup.
So what i want to do is basically have the consumers call localhost:8080/example and route that request to localhost:8082/example, localhost:8083/example, localhost:8084/example . I know how to load balance using ribbon and eureka and have all the appropriate properties set to achieve that.
zuul.routes.example.serviceid=example
ribbon.eureka.enabled=true.
What i want to do is have ribbon look up the list of url(s) from eureka server and then call localhost:8082/example rather localhost:8082.
Is this possible?
Thank you in advance.
You need to specify the path & serviceId
zuul:
routes:
examplepath:
path: /example/**
serviceId: name-example
stripPrefix: false
The serviceId is the name registered with Eureka. Hope you are specifying Eureka server details in you Zuul gateway.

eureka zuul cannot find my python app registered on eureka

I have a python web app, and registered with eureka using restfull api[https://github.com/Netflix/eureka/wiki/Eureka-REST-operations], and I found it status UP on the eureka web page, but my gateway server(also registered with eureka) can not find it, I call the url "gateway-server-host/myapp-url" and the following response is:
com.netflix.zuul.exception.ZuulException: Forwarding error at
org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:188)
at
org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:163)
at
org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:111)
...
Caused by: com.netflix.client.ClientException: Load balancer does not
have available server for client: test at
com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483)
at
com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:184)
at
com.netflix.loadbalancer.reactive.LoadBalancerCommand$1.call(LoadBalancerCommand.java:180)
any advise for this problem???
Have you looked over Spring Cloud's Sidecar ?
It basically a service over your non-jvm language service (in your case python) and with sidecar service (you have to deploy your python service and the sidecar service on the same host, if I am not mistaken) and you will include in your Zuul the endpoint to the sidecar service, which will try to handle things like eureka and such.
You spin up a new spring-boot app, with #EnableSidecar annotated, you configure the health-uri and port
example application.yml
server:
port: 5678
spring:
application:
name: sidecar
sidecar:
port: 8000
health-uri: http://localhost:8000/health.json
You can checkout Spring Cloud's documentation regarding Sidecar here for more details how to set it up
Since you are using Zuul you need to manually register routes. Its okay for them to just include the application name, from Eureka.
Example of Zuul route config:
zuul:
routes:
application1: /app1/**
application2: /app2/**
application3:
path: /app3/**
url: http://10.0.8.11:3000/
applicationN is the name registred in Eureka. The url will be resolved and load balanced automatically. For app3 the url is manually specified.
Adding Sidecar solves this problem to an extent where your Zuul /routes shows the registered Application Name.
You must have experienced , even if you do not have an actual app and just put any name with a payload following this document - [https://github.com/Netflix/eureka/wiki/Eureka-REST-operations] , that too gets registered in Eureka as an app.

Spring Boot Admin Eureka Authentication

I am using Eureka discovery, Spring Boot Admin (1.5.4) and several services. Each service has enabled basic auth to actuator endpoints:
security.user.name=admin
security.user.password=admin
management.security.enabled=true
SBA fetches info about services from eureka and because of secured endpoints I have configured eureka's metadata map like this:
eureka.instance.metadata-map.user.name=${security.user.name}
eureka.instance.metadata-map.user.password=${security.user.password}
but still getting 401 Unauthorized:
o.s.b.a.e.m.MvcEndpointSecurityInterceptor - Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.
What am I missing? If I turn management.security.enabled off it works.

Do request to Eureka client using server

I hava eureka server at eureka-server.com host and application with appId facade registered at server. Facade application has /users endpoint. Can I call /users endpoint through Eureka server something like this eureka-server.com/facade/users ?
No, Eureka can't proxy your calls through it, it's pure service discovery. But you can add a separate Zuul service with reverse proxy filtering which uses Eureka client to discover routes. Spring Cloud Netflix Zuul component has this out of the box.