dubbo源码分析第二十八篇一dubbo3.0拥抱云原生

cloud-native 简介: 每一种概念,都需要一种技术支撑
k8s+docker做为底层基础设施
Jenkins + git + 自建devops 等等作为服务发布部署工具
服务治理: istio ,dubbo3.0等实现治理: 包含服务发现,负载,流量控制等

应用级注册中心

old注册中心新的注册中心
以接口维度进行注册实例维度进行注册 ,同springcloud 注册consul

数据: 一个服务10个instance,每个instance10个接口

接口维度注册: zk上provider就包含100个url
实例维度注册: zk上只有10个instance信息

优点: 新的注册中心降低了存储,上行下发等压力
按照官方话语,可支持百万实例在线

优点二: 云原生则意味dubbo需要对齐k8s等通用服务发现策略;k8s,springcloud等都采用了instance级别注册,dubbo改造实现了对齐云方案

应用级注册中心demo

消费者配置

  • 必须指明provided-by属性表示消费哪种应用的实例
  • 无法直接到达接口
   <dubbo:application name="demo-consumer"/>

    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181?registry-type=service"/>
<!--    <dubbo:registry address="nacos://${nacos.address:127.0.0.1}:8848?registry-type=service"/>-->

    <dubbo:metadata-report address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />

    <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService" provided-by="demo-provider"/>

提供者配置

  • 配置的应用层demo-provider,作为消费的核心依据,而不是dubbo2的一个应用表示
  • 新增registry-type=service表示采用ServiceDiscoveryRegistry而不是dubbo2常用的ZookeeperRegistry进行注册
  • 引入元数据中心
    <dubbo:application name="demo-provider" metadata-type="remote"/>

    <dubbo:provider token="true"/>

    <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181?registry-type=service"/>
<!--    <dubbo:registry address="nacos://${nacos.address:127.0.0.1}:8848?registry-type=service"/>-->

    <dubbo:protocol name="dubbo" port="20880"/>

<!--    <dubbo:metadata-report address="nacos://${nacos.address:127.0.0.1}:8848" />-->
    <dubbo:metadata-report address="zookeeper://${zookeeper.address:127.0.0.1}:2181" />

    <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>

    <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService" weight="12"/>

k8s-apiserver作为注册中心(dns方案忽略)

消费者属性配置

dubbo.application.name=kubernetes-apiserver-demo-provider
dubbo.application.metadataServicePort=20885
dubbo.registry.address=kubernetes://${your kubernetes api server ip here}:${your kubernetes api server port here}?registry-type=service&duplicate=false&namespace=dubbo-demo&trustCerts=true&oauthToken=${your ServiceAccount token here}
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.application.qosEnable=true
dubbo.application.qosAcceptForeignIp=true
dubbo.provider.token=true

消费者配置

  • 消费原理,providedBy指明了需要消费k8s的路由实例
  • 到达这些pod节点后,通过元数据中心获取接口信息,进行rpc调用
  • 同时也说明,注册中心从此不在关注接口,值关注应用—地址映射
@Component("annotatedConsumer")
public class GreetingServiceConsumer {

    @DubboReference(version = "1.0.0", providedBy = {"kubernetes-apiserver-demo-provider"})
    private GreetingService greetingService;
    // 支持混合协议调用  支持多语言调用 支持k8s集成  支持应用级别注册 registry-type=service[dubbo3.0支持 否则配不配一样]
    public String doSayHello(String name) {
        return greetingService.sayHello(name);
    }

}

消费者启动配置


public class ConsumerBootstrap {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class);
        String hello = greetingServiceConsumer.doSayHello("Kubernetes Api Server");
        System.out.println("result: " + hello);
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.action")
    @PropertySource("classpath:/spring/dubbo-consumer.properties")
    @ComponentScan(value = {"org.apache.dubbo.samples.action"})
    static class ConsumerConfiguration {

    }
}

提供者属性配置

 

dubbo.application.name=kubernetes-apiserver-demo-provider
dubbo.application.metadataServicePort=20885
dubbo.registry.address=kubernetes://${your kubernetes api server ip here}:${your kubernetes api server port here}?registry-type=service&duplicate=false&namespace=dubbo-demo&trustCerts=true&oauthToken=${your ServiceAccount token here}
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
dubbo.application.qosEnable=true
dubbo.application.qosAcceptForeignIp=true
dubbo.provider.token=true

提供者配置

  • 接口几倍无需关注注册中心

@DubboService(version = "1.0.0")
public class AnnotatedGreetingService implements GreetingService {

    public String sayHello(String name) {
        System.out.println("greeting service received: " + name);
        return "hello, " + name;
    }

}

提供者启动配置

 public class ProviderBootstrap {

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
        context.start();
        System.out.println("dubbo service started");
        new CountDownLatch(1).await();
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.impl")
    @PropertySource("classpath:/spring/dubbo-provider.properties")
    static class ProviderConfiguration {
    }
}

}

注册内容

在这里插入图片描述

mapping映射信息

在这里插入图片描述

metadata元信息

在这里插入图片描述

总结

  • 注册中心由接口级上升到应用级,为超大规模集群落地提供支撑
  • 向云原生进行拥抱,应用级注册能对无缝切换到k8s注册
  • 注册内容之与实例规模成正比,不在与接口数量挂钩,降低存储,下载等压力
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值