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

相关推荐
韩立学长20 分钟前
基于Springboot的商品库存管理系统369jr3t9(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
java·数据库·spring boot·后端
CNAHYZ1 小时前
Apache HttpClient 配置 SSL 证书指南
java·spring boot·http
浩宇软件开发1 小时前
springBoot+Vue中华诗词学习后台管理系统
vue.js·spring boot·axios·element-plus·router
iPadiPhone1 小时前
Spring Boot 自动装配原理与 Starter 开发实战
java·spring boot·后端·spring·面试
码匠君1 小时前
首个基于 Spring Boot 4 的正式版发布!Dante Cloud 4.X 新特性全解析
java·spring boot·后端
脆皮的饭桶2 小时前
haproxy高可用、高性能、高灵活负载均衡集群技术实验
运维·负载均衡
Natalia_Portman2 小时前
springboot整合DolphinDB
java·数据库·spring boot·后端·db
beata2 小时前
Spring Boot基础-1:用5分钟搭建第一个REST API应用(含深度原理解析)
spring boot
忧郁缭绕2 小时前
Spring Boot Pf4j模块化能力设计思考
java·spring boot·后端
iPadiPhone3 小时前
Spring Boot 核心注解全维度解析与面试复盘
java·spring boot·后端·spring·面试