当前位置:   article > 正文

Springboot/cloud调用alibaba dubbo服务(nacos)_spring boot 获取nacos的dubbo实例调用

spring boot 获取nacos的dubbo实例调用

一、需求

  已经有bms-email-service-provider提供了两组服务在nacos服务器上注册,如下图:
在这里插入图片描述
  那么如何用调用它们?

二、建立配置文件

  先建立application-dubbo.yml,xxx.xxx.xxx.xxx是nacos服务器ip

#send mail dubbo consumer service 配置
dubbo:
  application:
    #name: dubbo-business-account-service-provider
    qos-enable: false
    qos-accept-foreign-ip: false
# nacos集群的时候要分别注册各nacos,我认为比用nginx管理要好
  registries:
    nacos1:
      address: nacos://xxx.xxx.xxx.xxx:8848
      group: bms-business
    nacos2:
      address: nacos://yyy.yyy.yyy.yyy:8848
      group: bms-business
  protocol:
    name: dubbo
    port: -1

  scan:
    base-packages: com.freestyle.common.email.api
  cloud:
    subscribed-services: bms-email-service-provider
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

 &esmp;然后在application.yml里面引用它:


spring:
  profiles:
    include: dubbo
  application:
    name: send-mail-consumer
  cloud:
    nacos:
      discovery:
        server-addr: xxx.xxx.xxx.xxx:8848,yyy.yyy.yyy.yyy:8848
        #namespace: 1864098a-8d49-447a-ab0a-2ce2bff43166
        group: bms-business
    inetutils:
      preferred-networks: 128.30
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

三、代码实现

1、调用代码

@Service
public class TestService {
   
  @DubboReference
  private EMailUserService eMailUserService;
  public Map<String,String> test(){
   
     return eMailUserService.getMailMapByAccountList(Arrays.asList("dgmislrh","dgmislxj"));
  }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

2、主程序

&esmp;&esmp;主程序要加注解@EnableDiscoveryClient:

@SpringBootApplication(exclude= {
   DataSourceAutoConfiguration</
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/315298
推荐阅读
相关标签
  

闽ICP备14008679号