• Dubbo源码构建


    前言

    最近一直在倒腾Dubbo相关的事情,闲来无事准备研究一下Dubbo的源码。在网上找了几篇Dubbo源码构建的文章发现没有解决自己的问题,所以记录一下构建过程中自己踩的坑。

    环境准备

    • MacOS (M1 Apple Silicon)
    • Jetbrains IDEA
    • JDK:1.8
    • maven:apache-maven-3.8.3
    • ZooKeeper 3.5.0

    下载源码&编译

    进入到GitHub中的Dubbo官网,点击tags标签,选择你想研究的版本进行切换

    image-20220409153116910

    然后将对应版本的Dubbo源码下载,不要试图使用IDEA直接clone,我挂着梯子速度还是不行。直接下载到本地,然后解压即可。我下载的是2.7.15版本。

    image-20220409153442025

    接着使用IDEA直接导入即可

    image-20220409171234017

    然后等待IDEA导入相关依赖,在这个过程中出现这个错误:Cannot resolve io.grpc:grpc-api:1.31.1

    image-20220409153905736

    然后我找了半天,终于在StackOverFlow找到解决办法,指路Cannot resolve io.grpc:grpc-api:1.31.1,这里面有两个办法,高赞的那个没能解决,我采用的是在依赖管理中覆盖grpc-core的办法,在dubbo-2.7.15的父pom.xml中引入如下依赖:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.grpc</groupId>
                <artifactId>grpc-core</artifactId>
                <version>1.13.1</version>
            </dependency>
            <dependency>
                <groupId>com.google.firebase</groupId>
                <artifactId>firebase-admin</artifactId>
                <version>6.6.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
        </dependency>
    </dependencies>
    

    然后reImport一下pom.xml文件即可

    image-20220409154838720

    接着打开IDEAmaven工具栏,找到dubbo-parent(root),先点击clean,完成后,点击上方的⚡️按钮,开启跳过test编译,然后点击build

    image-20220409162140014

    接着会遇到一个报错,Could not find artifact com.google.protobuf:protoc:exe:osx-aarch_64:3.7.1 in alimaven (http://maven.aliyun.com/nexus/content/groups/public/)

    image-20220409165039650

    谷歌一圈,发现好像是因为M1芯片的MBP不兼容,所以出现了报错,最后找到了这个解决办法,com.google.protobuf:protoc:exe:osx-aarch_64:3.7.1,需要在mavensetting.xml的文件中添加上针对M1芯片的profile,如下所示:

    <settings>
        <activeProfiles>
            <activeProfile>
                apple-silicon
            </activeProfile>
        </activeProfiles>
        <profiles>
            <profile>
                <id>apple-silicon</id>
                <properties>
                    <os.detected.classifier>osx-x86_64</os.detected.classifier>
                </properties>
            </profile>
        </profiles>
    </settings>
    

    然后重新执行build,最后编译成功。

    image-20220409163349543

    测试&日志

    接着找到dubbo-demo中的dubbo-demo-annotation-provider,如下所示:

    image-20220409160338075

    为了方便了解Dubbo的启动流程,修改log4j.properties,将org.apache.dubbo包及其子包的日志等级设置为debug

    image-20220409160137387

    接着启动本地的zookeeper,如下所示:

    image-20220409165936323

    然后启动Application中的main方法

    image-20220409165705725

    至此Dubbo源码构建结束。

  • 相关阅读:
    美国地质调研局USGS
    SAR 图像
    Matlab 之meshgrid, interp, griddata 用法和实例
    ENVISAT卫星及ASAR数据介绍
    ASP.NET Integration with IIS7
    ubuntu下C/C++基本开发环境的配置
    C++ Objects Part 1: Basic Object Memory Layout
    Socket Programming in Windows
    Memory Layout for Multiple and Virtual Inheritance
    Common Type System—Memory Layout at C# Online.NET
  • 原文地址:https://www.cnblogs.com/reecelin/p/16122715.html
Copyright © 2020-2023  润新知