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

相关推荐
CoderYanger4 小时前
Java EE 进阶:8.MyBatis 操作数据库(入门)(第二弹)
java·数据库·spring boot·spring·面试·java-ee·mybatis
计算机毕设定制辅导-无忧学长14 小时前
《基于微信小程序的居家医疗陪护预约系统设计与实现》
java·spring boot·微信小程序·uniapp·居家医疗陪护预约系统
小郎君65820 小时前
注解式脱敏:用 Jackson 的 ContextualSerializer 做字段级策略(一)
spring boot·spring cloud
陈希12321 小时前
Nginx 从入门到能扛事:反向代理、负载均衡与 HTTPS 实战
nginx·https·负载均衡
jktantan1 天前
注解式脱敏:用 Jackson 的 ContextualSerializer 做字段级策略(一)
spring boot·后端·算法·spring cloud·系统架构
露天赏雪2 天前
第3篇:Sentinel熔断降级实战:大模型接口抖动时的服务兜底方案
java·开发语言·人工智能·spring boot·spring·servlet·sentinel
蜗牛8752 天前
为 Spring Boot 团队做一个 Elasticsearch 查询工作台:六种模式、语义补全与浏览器直连
spring boot
养军博客2 天前
Spring Boot 3.x + Spring Security 6.x 整合 JWT 实战:jjwt 与 java-jwt 两种工具库详解
java·spring boot·springsecurity
txxzjmzlh2 天前
SpringBoot 统⼀功能处理
java·spring boot·后端
秋天的怀念_David3 天前
算法一千零一夜 · 第二十六夜 协议的母语
java·spring boot·算法