Spring Cloud Ribbon configuration

Posted by nicky77uk1 on Wed, 02 Oct 2019 06:05:20 +0200

Ribbon Load Balancing

Ribbon is a load balancer released by Netflix. Spring Cloud Ribbon is a load balancing solution. It is based on Netflix Ribbon and is a load balancing client for controlling HTTP requests.

After registering Ribbon in the registry, Ribbon can automatically help service consumers call interfaces based on some load balancing algorithms, such as polling, randomization, weighted polling, weighted randomization, etc. Developers can also customize Ribbon load balancing algorithm according to specific needs.

In practical development, Spring Cloud Ribbon needs to be used in conjunction with Spring Cloud Eureka, which provides a list of all service providers that can be invoked. Ribbon selects specific instances from these service providers based on specific load balancing algorithms.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>SpringCloudFoundation</artifactId>
        <groupId>com.springcloud</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Ribbon</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
    </dependencies>
</project>

bootstrap.properties configuration

server.port=8040
# The name of the current service registered on Eureka Server
spring.application.name=ribbon
# Access address of registry
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
# Whether to register the IP of the current service to Eureka Server
eureka.instance.prefer-ip-address=true

test

Topics: Spring Maven Apache xml