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

相关推荐
biyezuopinvip43 分钟前
基于Spring Boot的投资理财系统设计与实现(任务书)
java·spring boot·vue·毕业设计·论文·任务书·投资理财系统设计与实现
小邓睡不饱耶1 小时前
Spring Boot 3 + MyBatis-Plus 高性能持久层开发实战:从入门到调优
spring boot·后端·mybatis
百锦再2 小时前
Java的TCP和UDP实现详解
java·spring boot·tcp/ip·struts·spring cloud·udp·kafka
无尽的沉默4 小时前
Spring Boot 整合 Thymeleaf 模板引擎
java·前端·spring boot
番茄去哪了4 小时前
苍穹外卖day07---Redis缓存优化与购物车功能实现
java·数据库·ide·spring boot·spring·maven·mybatis
亓才孓4 小时前
【MyBatis Plus】Wrapper接口
java·开发语言·数据库·spring boot·mybatis
源码获取_wx:Fegn08955 小时前
计算机毕业设计|基于springboot + vue鲜花销售管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
毕设源码-赖学姐6 小时前
【开题答辩全过程】以 基于SpringBoot 的个人健康分析指导系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端
SmartBrain6 小时前
技术洞察:SpringAI与LangGraph选型对比
人工智能·spring boot·架构·langchain·aigc·fastapi
Dragon Wu7 小时前
SpringCache 缓存使用总结
spring boot·后端·spring·缓存·springcloud