java - How to set the value of loadBalancerKey in ribbon or Feign -
in spring cloud, i'm using ribbon or feign client api, , have server cluster registered in eureka. in case, want use specific key determine server want call, eg: server-a
has 2 instances, localhost:8001
, localhost:8002
, , want call 8001
setting loadbalancerkey
8001
, after can write customized balance rule class choose server can call below:
public class myconfigbalancerule extends clientconfigenabledroundrobinrule { @override public server choose(object key) { list<server> serverlist = getloadbalancer().getallservers(); (server srv : serverlist) { if (srv.getport == key) { return srv; } } } }
Comments
Post a Comment