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

相关推荐
计算机毕设VX:Fegn08954 小时前
计算机毕业设计|基于springboot + vue图书商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·课程设计
hhzz7 小时前
Spring Boot整合Activiti的项目中实现抄送功能
java·spring boot·后端
愿你天黑有灯下雨有伞7 小时前
实战演练:如何在Spring Boot项目中优雅地使用参数校验
spring boot
期待のcode11 小时前
springboot热部署
java·spring boot·后端
Somehow00711 小时前
Spring Boot 集成 ElasticSearch 的简单示例
spring boot·设计
vx_bisheyuange12 小时前
基于SpringBoot的老年一站式服务平台
java·spring boot·后端·毕业设计
计算机毕设VX:Fegn089512 小时前
计算机毕业设计|基于Java + vue水果商城系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·课程设计
老华带你飞14 小时前
校务管理|基于springboot 校务管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·spring
JosieBook14 小时前
【部署】Spring Boot + Vue框架项目生产环境部署完整方案
vue.js·spring boot·后端
油丶酸萝卜别吃14 小时前
springboot项目中与接口文档有关的注解
java·spring boot·后端