Skip to content
forked from Netflix/ribbon

Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.

License

Notifications You must be signed in to change notification settings

allenxwang/ribbon

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ribbon

Ribbon is a client side IPC library that is battle-tested in cloud. It provides the following features

  • Load balancing
  • Fault tolerance
  • Multiple protocol (HTTP, TCP, UDP) support in an asynchronous and reactive model
  • Caching and batching

To get ribbon binaries, go to maven central. Here is an example to add dependency in Maven:

<dependency>
    <groupId>com.netflix.ribbon</groupId>
    <artifactId>ribbon</artifactId>
    <version>2.0-RC1</version>
</dependency>

Modules

  • ribbon: APIs that integrate load balancing, fault tolerance, caching/batching on top of other ribbon modules and Hystrix
  • ribbon-loadbalancer: Load balancer APIs that can be used independently or with other modules
  • ribbon-eureka: APIs using Eureka client to provide dynamic server list for cloud
  • ribbon-transport: Transport clients that support HTTP, TCP and UDP protocols using RxNetty with load balancing capability
  • ribbon-httpclient: REST client built on top of Apache HttpClient integrated with load balancers (deprecated and being replaced by ribbon module)
  • ribbon-example: Examples
  • ribbon-core: Client configuration APIs and other shared APIs

Release notes

See https://github.com/Netflix/ribbon/releases

Code example

Access HTTP resource using template

HttpResourceGroup httpResourceGroup = Ribbon.createHttpResourceGroup("movieServiceClient",
            ClientOptions.create()
                    .withMaxAutoRetriesNextServer(3)
                    .withConfigurationBasedServerList("localhost:8080,localhost:8088"));
HttpRequestTemplate<ByteBuf> recommendationsByUserIdTemplate = httpResourceGroup.newRequestTemplate("recommendationsByUserId", ByteBuf.class)
            .withMethod("GET")
            .withUriTemplate("/users/{userId}/recommendations")
            .withFallbackProvider(new RecommendationServiceFallbackHandler())
            .withResponseValidator(new RecommendationServiceResponseValidator());
Observable<ByteBuf> result = recommendationsByUserIdTemplate.requestBuilder()
                        .withRequestProperty("userId", “user1")
                        .build()
                        .observe();

Access HTTP resource using annotations

public interface MovieService {
    @TemplateName("recommendations")
    @Http(
            method = HttpMethod.GET,
            uriTemplate = "/users/{userId}/recommendations",
            )
    @Hystrix(
            validator = RecommendationServiceResponseValidator.class,
            fallbackHandler = RecommendationServiceFallbackHandler.class)
    @CacheProviders(@Provider(key = "{userId}", provider = InMemoryCacheProviderFactory.class))
    RibbonRequest<ByteBuf> recommendationsByUserId(@Var("userId") String userId);
}

MovieService movieService = Ribbon.from(MovieService.class);
Observable<ByteBuf> result = movieService.recommendationsByUserId("user1").observe();

Create a load balancer with Eureka dynamic server list and zone affinity enabled

        IRule rule = new AvailabilityFilteringRule();
        ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("MyVIP:7001");
        ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>();
        ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder()
                .withDynamicServerList(list)
                .withRule(rule)
                .withServerListFilter(filter)
                .buildDynamicServerListLoadBalancer();   
        DiscoveryEnabledServer server = lb.chooseServer();         

Use load balancing APIs with HttpURLConnection

LoadBalancerExecutor lbExecutor = LoadBalancerBuilder.newBuilder()
	.buildFixedServerListLoadBalancerExecutor(
		Lists.newArrayList(
                new Server("www.google.com", 80),
                new Server("www.linkedin.com", 80),
                new Server("www.yahoo.com", 80))
		);
String statusLine = lbExecutor.execute(new LoadBalancerCommand<String>() {
            @Override
            public String run(Server server) throws Exception {
                URL url = new URL("http://" + server.getHost() + ":" + server.getPort() + "/");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                return conn.getResponseMessage();
            }
        });

Questions?

Email [email protected] or join us

About

Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 98.6%
  • Groovy 1.4%