-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support to set loadBalancerKey from request header #451
base: 2.2.x
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## 2.2.x #451 +/- ##
============================================
+ Coverage 77.80% 77.98% +0.18%
- Complexity 476 477 +1
============================================
Files 64 64
Lines 1883 1885 +2
Branches 265 265
============================================
+ Hits 1465 1470 +5
+ Misses 298 295 -3
Partials 120 120
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alan-tang-tt Thanks for the PR. The idea is good, however some more work has to be done on the PR.
Please verify if the headers contain the header you want to use.
Please change the default header name to X-LodBalancer-Key
.
Please allow changing header name via properties.
Please add tests.
Please add documentation.
@@ -93,6 +94,11 @@ public RibbonResponse execute(RibbonRequest request, IClientConfig configOverrid | |||
return new RibbonResponse(request.getUri(), response); | |||
} | |||
|
|||
@Override | |||
protected void customizeLoadBalancerCommandBuilder(RibbonRequest request, IClientConfig config, LoadBalancerCommand.Builder<RibbonResponse> builder) { | |||
builder.withServerLocator(request.request.headers().get("loadBalancerKey")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And consider other parameter like url parameter?
When I write myself
MyRule
implementsIRule
, the key is always null, like below:By watching the source code, I find there's no where to set this
loadBalancerKey
. So I push this PR to resolve this problem by overridingFeignLoadBalancer#customizeLoadBalancerCommandBuilder
method.By this way, I can put my
loadBalancerKey
fromfeign.RequestInterceptor
implementation like this:Then in
MyRule
I can get the key:This is all.