美文网首页
Dubbo应用

Dubbo应用

作者: ythmilk | 来源:发表于2021-09-04 12:35 被阅读0次

    环境搭建

    1. zookeeper 下载安装(环境变量配置)
      1. 使用3.4.14版本https://archive.apache.org/dist/zookeeper/zookeeper-3.4.14/

    项目搭建

    项目模块

    Dubbo-demo-provider
    Dubbo-demo-consumer
    Dubbo-demo-sdk
    Maven 依赖

        <properties>
            <zookeeper.version>2.12.0</zookeeper.version>
        </properties>
            <!--zookeeper-->
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.7</version>
            </dependency>
            <!--dubbo引入-->
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo</artifactId>
                <version>2.7.3</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-framework</artifactId>
                <version>${zookeeper.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.curator</groupId>
                <artifactId>curator-recipes</artifactId>
                <version>${zookeeper.version}</version>
            </dependency>
    

    dubbo-admin(Dubbo控制台)

    GitHub地址:https://github.com/apache/dubbo-admin

    下载代码,执行 mvn clean package -Dmaven.test.skip=true

    元数据出不来
    解决办法:https://blog.csdn.net/wangxq0224/article/details/99304253

    1. 添加zk节点
      package com.yth.dubbo.provider.service.impl;
      import org.apache.curator.framework.CuratorFramework;
      import org.apache.curator.framework.CuratorFrameworkFactory;
      import org.apache.curator.retry.ExponentialBackoffRetry;
      public class Test {
          public static void main(String[] args) {
              try {
                  CuratorFramework zkClient = CuratorFrameworkFactory.builder().
                          connectString("127.0.0.1:2181").
                          retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
                  zkClient.start();
                  if (zkClient.checkExists().forPath("/dubbo/config/dubbo/dubbo.properties") == null) {
                      zkClient.create().creatingParentsIfNeeded().forPath("/dubbo/config/dubbo/dubbo.properties");
                  }
                  zkClient.setData().forPath("/dubbo/config/dubbo/dubbo.properties", ("dubbo.registry.address=zookeeper://127.0.0.1:2181\n" +
                          "dubbo.metadata-report.address=zookeeper://127.0.0.1:2181").getBytes());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      
      1. application.properties配置
        dubbo.registry.address=zookeeper://127.0.0.1:2181
        dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
        

    dubbo-monitor(监控中心)

    用来统计服务的调⽤次数和调⽤时间的监控中⼼。
    代码路径

    dubbo 统一异常处理

    相关文章

      网友评论

          本文标题:Dubbo应用

          本文链接:https://www.haomeiwen.com/subject/abrrwltx.html