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

相关推荐
经典199228 分钟前
spring boot 详解以及原理
java·spring boot·后端
CZZDg1 小时前
LVS负载均衡-DR模式配置
运维·负载均衡·lvs
白仑色2 小时前
Spring Boot 多环境配置详解
java·spring boot·后端·微服务架构·配置管理
超级小忍2 小时前
在 Spring Boot 中优化长轮询(Long Polling)连接频繁建立销毁问题
java·spring boot·后端
Z_W_H_2 小时前
【springboot】IDEA手动创建SpringBoot简单工程(无插件)
java·spring boot·intellij-idea
荔枝hu3 小时前
springboot生成pdf方案之dot/html/图片转pdf三种方式
spring boot·pdf·html
Z_W_H_6 小时前
【SpringBoot】 整合MyBatis+Postgresql
java·spring boot·后端
麦兜*7 小时前
【SpringBoot 】Spring Boot OAuth2 六大安全隐患深度分析报告,包含渗透测试复现、漏洞原理、风险等级及完整修复方案
java·jvm·spring boot·后端·spring·系统架构
Code季风8 小时前
Spring Bean的生命周期详解
java·spring boot·spring
万能小锦鲤9 小时前
《Java EE与中间件》实验三 基于Spring Boot框架的购物车
java·spring boot·mysql·实验报告·购物车·文档资源·java ee与中间件