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

相关推荐
摇滚侠10 分钟前
Spring Boot 3零基础教程,深度理解 Spring Boot 自动配置原理,笔记11
spring boot·笔记·后端
爆更小哇35 分钟前
统一功能处理
java·spring boot
熙客2 小时前
阿里云负载均衡SLB的使用
网络·阿里云·云原生·云计算·负载均衡
土星碎冰机4 小时前
Dubbo RPC 调用中用户上下文传递问题的解决
网络协议·rpc·dubbo
hweiyu004 小时前
Spring Boot 项目集成 Gradle:构建、测试、打包全流程教程
java·spring boot·后端·gradle
一勺菠萝丶4 小时前
Spring Boot 项目启动报错:`Could not resolve type id ... no such class found` 终极解决方案!
java·spring boot·后端
摇滚侠8 小时前
Spring Boot 3零基础教程,IOC容器中组件的注册,笔记08
spring boot·笔记·后端
程序员小凯10 小时前
Spring Boot测试框架详解
java·spring boot·后端
程序员小凯12 小时前
Spring Boot缓存机制详解
spring boot·后端·缓存
正见TrueView13 小时前
阿里美团京东从“三国杀”到“双雄会”:本地生活无限战争的终局猜想
dubbo·生活