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

相关推荐
bitt TRES1 小时前
springboot与springcloud对应版本
java·spring boot·spring cloud
2301_771717216 小时前
Spring Boot 自动配置核心注解
java·spring boot·mybatis
庞轩px7 小时前
大模型推理网关——从负载均衡到故障注入的完整设计
网关·大模型·负载均衡·webflux·token限流·api密钥
❀͜͡傀儡师7 小时前
Claude Code 命令大全:从入门到精通的完整指南
spring boot·claude code
kybs19918 小时前
springboot租车系统--附源码68701
java·hadoop·spring boot·python·django·asp.net·php
过期动态9 小时前
MySQL中的约束
android·java·数据库·spring boot·mysql
wxin_VXbishe9 小时前
springboot新能源车充电站管理系统小程序-计算机毕业设计源码29213
java·c++·spring boot·python·spring·django·php
代码漫谈10 小时前
一文学习 SpringBoot 的 application.yml 配置,基于 Spring Boot 3.2.x
java·spring boot·spring·配置文件
Java面试题总结11 小时前
Spring Boot:别再重复造轮子,这些内置功能香麻了
java·spring boot·后端
海兰12 小时前
【第32篇】场景示例项目
人工智能·spring boot·状态模式·spring ai