go-router | base system design for Soft-routing base
kandi X-RAY | go-router Summary
kandi X-RAY | go-router Summary
a base system design for Soft-routing base on go-plugin which provide a simple web interface to use.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Basic example .
- Load a plugin
- RegUserHandler registers a new user in a session
- OnLoad is called when a plugin is loaded
- getSid gets session id from http request
- ReadLines reads lines from a file
- GetGoStats returns the current status of the process .
- parseJSONConfig is used to parse a json file .
- execute command
- power handler
go-router Key Features
go-router Examples and Code Snippets
Community Discussions
Trending Discussions on go-router
QUESTION
I am using Spring Cloud Netflix Ribbon in combination with Eureka in a Cloud Foundry environment.
The use case I am trying to implement is the following:
I have a running CF application named
address-service
with several instances spawned.The instances are registering to Eureka by the service name
address-service
I have added custom metadata to service instances using
eureka.instance.metadata-map.applicationId: ${vcap.application.application_id}
I want to use the information in Eureka's
InstanceInfo
(in particular the metadata and how many service instances are available) for setting a CF HTTP header "X-CF-APP-INSTANCE" as described here.The idea is to send a Header like
"X-CF-APP-INSTANCE":"appIdFromMetadata:instanceIndexCalculatedFromNoOfServiceInstances"
and thus "overrule" CF's Go-Router when it comes to load balancing as described at the bottom of this issue.
I believe to set headers, I need to create a custom RibbonClient implementation - i.e. in plain Netflix terms a subclass of AbstractLoadBalancerAwareClient as described here - and override the execute()
methods.
However, this does not work, as Spring Cloud Netflix Ribbon won't read the class name of my CustomRibbonClient
from application.yml
. It also seems Spring Cloud Netflix wraps quite a bit of classes around the plain Netflix stuff.
I tried implementing a subclass of RetryableRibbonLoadBalancingHttpClient
and RibbonLoadBalancingHttpClient
which are Spring classes. I tried giving their class names in application.yml
using ribbon.ClientClassName
but that does not work. I tried to override beans defined in Spring Cloud's HttpClientRibbonConfiguration
but I cannot get it to work.
So I have two questions:
is my assumption correct that I need to create a custom Ribbon Client and that the beans defined here and here won't do the trick?
How to do it properly?
Any ideas are greatly appreciated, so thanks in advance!
Update-1
I have dug into this some more and found RibbonAutoConfiguration.
This creates a SpringClientFactory which provides a getClient()
method that is only used in RibbonClientHttpRequestFactory
(also declared in RibbonAutoConfiguration
).
Unfortunately, RibbonClientHttpRequestFactory
hard-codes the client to Netflix RestClient
. And it does not seem possible to override either SpringClientFactory
nor RibbonClientHttpRequestFactory
beans.
I wonder if this is possible at all.
...ANSWER
Answered 2019-Mar-20 at 22:07Ok, I'll answer this question myself, in case someone else may need that in the future.
Actually, I finally managed to implement it.
TLDR - the solution is here: https://github.com/TheFonz2017/Spring-Cloud-Netflix-Ribbon-CF-Routing
The solution:
- Allows to use Ribbon on Cloud Foundry, overriding Go-Router's load balancing.
- Adds a custom routing header to Ribbon load balancing requests (including retries) to instruct CF's Go-Router to route requests to the service instance selected by Ribbon (rather than by its own load balancer).
- Shows how to intercept load balancing requests
The key to understanding this, is that Spring Cloud has its own LoadBalancer
framework, for which Ribbon is just one possible implementation. It is also important to understand, that Ribbon is only used as a load balancer not as an HTTP client. In other words, Ribbon's ILoadBalancer
instance is only used to select the service instance from the server list. Requests to the selected server instances are done by an implementation of Spring Cloud's AbstractLoadBalancingClient
. When using Ribbon, these are sub-classes of RibbonLoadBalancingHttpClient
and RetryableRibbonLoadBalancingHttpClient
.
So, my initial approach to add an HTTP header to the requests sent by Ribbon's HTTP client did not succeed, since Ribbon's HTTP / Rest client is actually not used by Spring Cloud at all.
The solution is to implement a Spring Cloud LoadBalancerRequestTransformer
which (contrary to its name) is a request interceptor.
My solution uses the following implementation:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go-router
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page