Home Java javaTutorial Ribbon usage in Spring Cloud applications

Ribbon usage in Spring Cloud applications

Jul 23, 2018 am 10:08 AM

A load balancer provides at least the following functions:

  • To maintain the IP and other information of each server

  • According to specific Logical selection of servers

In order to achieve basic load balancing functions, Ribbon's load balancer has three major sub-modules:

  • Rule

  • Ping

  • ServerList

When Ribbon is used in SpringCloud, the configuration can be done in two ways, one One is Java configuration and the other is configuration file configuration.

Configuration through java:

package com.hurricane.learn.springcloud.ribbon;

import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;

@RibbonClient(name="user-service-provider",configuration=MyConfig.class)
public class MyConfig {
	
	@Bean
	public MyRule createMyRule() {
		return new MyRule();
	}

}
Copy after login

Configuration file configuration:

#自定义规则的使用
user-service-provider.ribbon.NFLoadBalancerRuleClassName=com.hurricane.learn.springcloud.ribbon.MyRule
Copy after login

A pitfall of service calls:

Test calls between services, keep calling Unsuccessful, prompt:

Request URI does not contain a valid hostname: http://user_service_provider/getUser
Copy after login

Finally found out that it was because the service instance name cannot have underscores. You can access it by changing the instance name to aaa.

The above is the detailed content of Ribbon usage in Spring Cloud applications. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Cleverly use Spring Cloud to solve load balancing problems under microservice architecture Cleverly use Spring Cloud to solve load balancing problems under microservice architecture Jun 23, 2023 pm 01:40 PM

As the complexity of enterprise applications continues to increase, more and more enterprises are beginning to split applications into multiple microservices and complete the entire business process through collaboration between microservices. This architectural approach can make applications more stable and scalable, but it also brings some new problems, such as load balancing, service discovery, etc. This article will introduce how to use Spring Cloud to solve the load balancing problem under the microservice architecture. What is load balancing? Load Balancing (LoadBalancing) refers to the balancing of multiple servers and networks

Spring Cloud source code analysis: Part 1 Spring Cloud source code analysis: Part 1 Aug 15, 2023 pm 04:04 PM

Personally, I think the prerequisite for reading the source code is that you must be able to use it. Once you are familiar with it, you can guess how others implemented it. If there are relevant official documents, then read the official documents.

Service-oriented Spring Cloud microservice development Service-oriented Spring Cloud microservice development Jun 23, 2023 pm 12:30 PM

With the development of the Internet and the continuous updating of technology, traditional single applications can no longer meet user needs, and the concept of microservices has emerged. SpringCloud is a microservice development toolkit launched by Pivotal. It provides developers with an extremely convenient way to build, deploy and manage microservice architecture applications. This article will introduce the service-oriented SpringCloud microservice development in detail, including the concept and architecture of SpringCloud, the microservice development process and

Spring Cloud microservice architecture deployment and operation Spring Cloud microservice architecture deployment and operation Jun 23, 2023 am 08:19 AM

With the rapid development of the Internet, the complexity of enterprise-level applications is increasing day by day. In response to this situation, the microservice architecture came into being. With its modularity, independent deployment, and high scalability, it has become the first choice for enterprise-level application development today. As an excellent microservice architecture, Spring Cloud has shown great advantages in practical applications. This article will introduce the deployment and operation and maintenance of SpringCloud microservice architecture. 1. Deploy SpringCloud microservice architecture SpringCloud

How to use Java to develop a container orchestration application based on Spring Cloud Kubernetes How to use Java to develop a container orchestration application based on Spring Cloud Kubernetes Sep 20, 2023 am 11:15 AM

How to use Java to develop a container orchestration application based on Spring Cloud Kubernetes. With the development and widespread application of container technology, container orchestration tools have become an indispensable part of developers. As one of the most popular container orchestration tools, Kubernetes has become the industry standard. In this context, combining Spring Cloud and Kubernetes, we can easily develop applications based on container orchestration. This article will introduce in detail

Introduction to Spring Cloud framework in Java language Introduction to Spring Cloud framework in Java language Jun 09, 2023 pm 10:54 PM

Introduction to the Spring Cloud framework in the Java language With the popularity of cloud computing and microservices, the Spring Cloud framework has become one of the preferred frameworks for building cloud native applications in the Java language. This article will introduce the concepts and features of the Spring Cloud framework, and how to use Spring Cloud to build a microservice architecture. Introduction to SpringCloud The SpringCloud framework is a microservice framework based on SpringBoot. it is

Spring Cloud microservice practice for implementing distributed locks Spring Cloud microservice practice for implementing distributed locks Jun 22, 2023 pm 11:28 PM

With the popularity of microservice architecture, more and more enterprise development teams are beginning to use Spring Cloud to build their own microservice systems. In a distributed environment, implementing distributed locks is an important technical challenge. This article will introduce how to implement microservice practices of distributed locks under the Spring Cloud framework. First, we need to understand what a distributed lock is. Distributed lock is a technology used to protect access to shared resources. It can ensure that in a distributed environment, multiple nodes will not modify the same resource at the same time or

The combination of Spring Cloud microservices and componentization The combination of Spring Cloud microservices and componentization Jun 23, 2023 am 10:21 AM

With the continuous development of Internet technology, more and more enterprises are beginning to adopt microservice architecture to build their systems. SpringCloud is a microservices framework that has emerged rapidly in this context. On this basis, this article will discuss the combination of SpringCloud microservices and componentization, and analyze its advantages and implementation methods. 1. Introduction to SpringCloud microservices SpringCloud is an upgraded version of the SpringBoot project. It provides a large number of tools.

See all articles