Browse Source
Before, LBClients were created for each request, which led to issues such as #182. Moreover, a user could not avoid using Ribbon's static factories. Adding LBClientFactory allows users to control how Ribbon resources are created.pull/243/head
Brendan Nolan
10 years ago
committed by
Adrian Cole
8 changed files with 138 additions and 27 deletions
@ -0,0 +1,22 @@ |
|||||||
|
package feign.ribbon; |
||||||
|
|
||||||
|
import com.netflix.client.ClientFactory; |
||||||
|
import com.netflix.client.config.IClientConfig; |
||||||
|
import com.netflix.loadbalancer.ILoadBalancer; |
||||||
|
|
||||||
|
public interface LBClientFactory { |
||||||
|
|
||||||
|
LBClient create(String clientName); |
||||||
|
|
||||||
|
/** |
||||||
|
* Uses {@link ClientFactory} static factories from ribbon to create an LBClient. |
||||||
|
*/ |
||||||
|
public static final class Default implements LBClientFactory { |
||||||
|
@Override |
||||||
|
public LBClient create(String clientName) { |
||||||
|
IClientConfig config = ClientFactory.getNamedConfig(clientName); |
||||||
|
ILoadBalancer lb = ClientFactory.getNamedLoadBalancer(clientName); |
||||||
|
return LBClient.create(lb, config); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package feign.ribbon; |
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals; |
||||||
|
|
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
import com.netflix.client.ClientFactory; |
||||||
|
|
||||||
|
public class LBClientFactoryTest { |
||||||
|
|
||||||
|
@Test |
||||||
|
public void testCreateLBClient() { |
||||||
|
LBClientFactory.Default lbClientFactory = new LBClientFactory.Default(); |
||||||
|
LBClient client = lbClientFactory.create("clientName"); |
||||||
|
assertEquals("clientName", client.getClientName()); |
||||||
|
assertEquals(ClientFactory.getNamedLoadBalancer("clientName"), client.getLoadBalancer()); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue