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

相关推荐
ywf12151 小时前
前端的dist包放到后端springboot项目下一起打包
前端·spring boot·后端
大阿明8 小时前
Spring Boot(快速上手)
java·spring boot·后端
哆啦A梦15888 小时前
Springboot整合MyBatis实现数据库操作
数据库·spring boot·mybatis
星轨zb10 小时前
通过实际demo掌握SpringSecurity+MP中的基本框架搭建
数据库·spring boot·spring security·mp
没有bug.的程序员12 小时前
Serverless 弹性扩容引发的全线熔断:Spring Boot 启动耗时从 1s 压缩至 0.3s 的物理级绞杀
java·spring boot·kubernetes·serverless·扩容·线上
luom010214 小时前
SpringBoot - Cookie & Session 用户登录及登录状态保持功能实现
java·spring boot·后端
希望永不加班14 小时前
SpringBoot 核心配置文件:application.yml 与 application.properties
java·spring boot·后端·spring
毕设源码-朱学姐16 小时前
【开题答辩全过程】以 基于SpringBoot+Vue的百货商品进出货平台为例,包含答辩的问题和答案
java·spring boot·后端
夜空下的星16 小时前
springboot实现Minio大文件分片下载
java·spring boot·后端
程序员老乔19 小时前
Java 新纪元 — JDK 25 + Spring Boot 4 全栈实战(三):虚拟线程2.0,电商秒杀场景下的并发革命
java·开发语言·spring boot