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

相关推荐
ai产品老杨21 分钟前
异构计算时代的视频底座:基于 ZLMediaKit 与 Spring Boot 的 X86/ARM 跨平台架构解析
arm开发·spring boot·音视频
老神在在00143 分钟前
Spring Boot 全局异常处理器(GlobalExceptionHandler)
spring boot·spring·java-ee·状态模式·
han_hanker1 小时前
@GetMapping @PostMapping @DeleteMapping @PutMapping
spring boot
han_hanker2 小时前
@Validated @Valid 用法
java·spring boot
言慢行善3 小时前
SpringBoot中的注解介绍
java·spring boot·后端
许杰小刀4 小时前
MyBatis-Plus实战:Spring Boot数据库操作效率提升10倍
数据库·spring boot·mybatis
霸道流氓气质5 小时前
SpringBoot中使用SpringAIAlibaba框架集成阿里云百炼实现AI快速对话入门示例
人工智能·spring boot·阿里云
认真的小羽❅5 小时前
从入门到精通:Spring Boot 整合 MyBatis 全攻略
spring boot·后端·mybatis
qq_297574676 小时前
【Kafka 系列・入门第六篇】Kafka 集群部署(3 节点)+ 负载均衡配置
分布式·kafka·负载均衡
珍朱(珠)奶茶7 小时前
Spring Boot3整合Jxls工具包实现模版excel导出文件
spring boot·后端·excel