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

相关推荐
k***12172 分钟前
基于SpringBoot和PostGIS的云南与缅甸的千里边境线实战
java·spring boot·spring
a***11352 分钟前
【springboot】健康检查 监控
java·spring boot·后端
j***63082 分钟前
使用Kubernetes部署Spring Boot项目
spring boot·容器·kubernetes
q***385126 分钟前
Spring Boot + Spring AI快速体验
人工智能·spring boot·spring
q***483131 分钟前
【springboot】Spring 官方抛弃了 Java 8!新idea如何创建java8项目
java·spring boot·spring
y***613143 分钟前
在Spring Boot项目中使用MySQL数据库
数据库·spring boot·mysql
清晰-简洁1 小时前
Spring Boot 单元测试按需加载
spring boot·后端·单元测试
q***42051 小时前
Spring Boot 整合 log4j2 日志配置教程
spring boot·单元测试·log4j
r***99821 小时前
在2023idea中如何创建SpringBoot
java·spring boot·后端
一 乐2 小时前
考公|考务考试|基于SprinBoot+vue的考公在线考试系统(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·课程设计