dubbo复习:(4) 和springboot 整合时,客户端负载均衡的配置

需要在@DubboReference注解指定loadbalance属性。示例如下:

复制代码
package cn.edu.tju.service;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Date;

@Service
public class RemoteService {

    //@DubboReference(loadbalance = "roundrobin")
    @DubboReference(loadbalance = "consistenthash")
    private DemoService demoService;


    public String  callRemoteService(){
        try {
            Thread. sleep(10);
            return new Date() + " Receive result ======> " + demoService.sayHello("world");
        } catch (InterruptedException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }
}

其中可以使用的值如下:

默认的配置是random

相关推荐
paopaokaka_luck3 小时前
基于SpringBoot+Vue的电影售票系统(协同过滤算法)
vue.js·spring boot·后端
陌殇殇6 小时前
SpringBoot整合SpringCache缓存
spring boot·redis·缓存
小林学习编程9 小时前
Springboot + vue + uni-app小程序web端全套家具商场
前端·vue.js·spring boot
ladymorgana9 小时前
【Spring boot】tomcat Jetty Undertow对比,以及应用场景
spring boot·tomcat·jetty
IT_10249 小时前
Spring Boot项目开发实战销售管理系统——系统设计!
大数据·spring boot·后端
DCTANT10 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
Touper.10 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
喜欢敲代码的程序员12 小时前
SpringBoot+Mybatis+MySQL+Vue+ElementUI前后端分离版:项目搭建(一)
spring boot·mysql·elementui·vue·mybatis
华子w90892585913 小时前
基于 SpringBoot+Vue.js+ElementUI 的 “花开富贵“ 花园管理系统设计与实现7000字论文
vue.js·spring boot·elementui
小时候的阳光14 小时前
SpringBoot3 spring.factories 自动配置功能不生效?
spring boot·spring·失效·factories·imports