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

相关推荐
brevity_souls3 小时前
Spring Boot 内置工具类
java·spring boot
luoluoal4 小时前
基于Spring Boot+Vue的宠物服务管理系统(源码+文档)
vue.js·spring boot·宠物
小钊(求职中)4 小时前
Java开发实习面试笔试题(含答案)
java·开发语言·spring boot·spring·面试·tomcat·maven
毕业设计-016 小时前
0081.基于springboot+uni-app的垃圾分类小程序+论文
spring boot·小程序·uni-app
小猫猫猫◍˃ᵕ˂◍6 小时前
rabbitmq五种模式的实现——springboot
spring boot·rabbitmq·java-rabbitmq
CodeMonkey陈7 小时前
springboot使用webSocket
spring boot·python·websocket
苹果酱05678 小时前
玩转SpringCloud Stream
java·spring boot·毕业设计·layui·课程设计
拾忆,想起8 小时前
Spring 和 Spring MVC 的关系是什么?
java·spring boot·spring·spring cloud·微服务