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

相关推荐
z***026032 分钟前
springboot整合modbus实现通讯
数据库·spring boot·后端
i***683235 分钟前
Spring Boot--@PathVariable、@RequestParam、@RequestBody
java·spring boot·后端
h***06651 小时前
Spring Boot 集成 Kettle
java·spring boot·后端
unclecss1 小时前
从 0 到 1 落地 SSE:Spring Boot 3 实战 Server-Sent Events 推送全链路
java·spring boot·后端·http·sse
e***95641 小时前
springboot-自定义注解
java·spring boot·spring
i***27952 小时前
SpringBoot实现异步调用的方法
java·spring boot·spring
d***29242 小时前
Springboot中SLF4J详解
java·spring boot·后端
阿在在2 小时前
Dubbo 与 Spring 整合全流程解析(含生产者与消费者
java·spring·dubbo
LSL666_2 小时前
SpringBoot项目连接deepseek
java·spring boot·后端·deepseek
i***39582 小时前
JAVA系统中Spring Boot 应用程序的配置文件:application.yml
java·开发语言·spring boot