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

相关推荐
xyyaihxl1 小时前
springboot与springcloud对应版本
java·spring boot·spring cloud
小箌2 小时前
springboot_01
java·spring boot·后端
a8a3022 小时前
Springboot中CommandLineRunner的用法以及执行顺序的控制
java·spring boot·spring
sevenlin2 小时前
Spring Boot 经典九设计模式全览
java·spring boot·设计模式
salipopl2 小时前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
Java水解3 小时前
Spring Boot 数据仓库与ETL工具集成
spring boot·后端
beata3 小时前
Spring Boot基础-3:Spring Boot 4.x 配置文件全攻略与多环境切换
spring boot·后端
jolimark3 小时前
Spring Boot 集成 Kettle
java·spring boot·后端
gaozhiyong08133 小时前
SpringBoot连接多数据源MySQL、SqlServer等(MyBatisPlus测试)
spring boot·mysql·sqlserver
zb200641204 小时前
Spring Boot 实战篇(四):实现用户登录与注册功能
java·spring boot·后端