dubbo 環(huán)境搭建

初次體驗(yàn),做個(gè)總結(jié)和記錄,主要在引入依賴包的時(shí)候遇到問題多。jdk環(huán)境是1.8
添加依賴,這個(gè)依賴比較少了

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>dubbostudy2</artifactId>
        <groupId>com.nn.dubbostudy2</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>
    <artifactId>server</artifactId>
    <dependencies>
      <!--本地的分層module的引入,model 引入了api的module-->
        <dependency>
            <groupId>com.zah.dubbostudy2</groupId>
            <artifactId>model</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.6</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.45</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.6.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.curator/curator-framework -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>4.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.jboss.resteasy/resteasy-jaxrs -->
        <!--jax-rs 標(biāo)準(zhǔn)的依賴 -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.0.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.6</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>

最好先在maven的setting.xml中設(shè)置自己的本地maven庫的地址。這樣在后續(xù)打包發(fā)布之后consumer才可以拿到j(luò)ar。

添加一個(gè)properties文件,添加一些

dubbo.reference.check=false
dubbo.registry.client=curator
dubbo.application.name=provider1
dubbo.application.owner=debug

dubbo.protocol.name=dubbo
dubbo.protocol.dubbo.port=20903

dubbo.protocol.name=rest
dubbo.protocol.rest.port=9013
dubbo.protocol.rest.server=tomcat

添加一個(gè)xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    <!--發(fā)布出去的dubbo服務(wù)類所在包的注解-->
    <dubbo:annotation package="com.zah.dubbostudy2.service.dubbo" />

    <!--注冊(cè)中心zookeeper配置信息-->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" />
    <!--支持兩種協(xié)議的調(diào)用:rpc-dubbo協(xié)議;http協(xié)議-rest api-url調(diào)用-->
    <dubbo:protocol name="rest" threads="500" contextpath="v1" server="tomcat" accepts="500" port="9013"/>
    <dubbo:protocol name="dubbo" port="20903"/>
    <!--消費(fèi)方信息配置-->
    <dubbo:application name="consumer1" owner="debug" organization="dubbox"/>
</beans>

網(wǎng)上有的xml,注解的不能夠被引用。這個(gè)沒有問題,都是測試通過的。
然后配置一下消費(fèi)者方的文件,properties文件都差不多,就是端口號(hào)和名稱改一下

dubbo.reference.check=false
dubbo.registry.client=curator
dubbo.application.name=provider2
dubbo.application.owner=debug

添加配置文件xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    <!--發(fā)布出去的dubbo服務(wù)類所在包的注解-->
    <dubbo:annotation package="com.nn.dubbostudy3.server.service.dubbo" />

    <!--注冊(cè)中心zookeeper配置信息-->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" />
    <!--支持兩種協(xié)議的調(diào)用:rpc-dubbo協(xié)議;http協(xié)議-rest api-url調(diào)用-->
    <dubbo:protocol name="rest" threads="500" contextpath="v1" server="tomcat" accepts="500" port="9014"/>
    <dubbo:protocol name="dubbo" port="20904"/>

    <!--消費(fèi)方信息配置-->
    <dubbo:application name="consumer2" owner="debug" organization="dubbox"/>
    <!--deploy content-->
    <dubbo:reference id="dubboItemService" interface="com.nn.project.service.IDubboItemService"
       protocol="dubbo" version="1.0" timeout="20000"/>
</beans>

其它問題就比較容易解決了。

dubbo 的控制臺(tái)搭建
官網(wǎng)http://dubbo.apache.org/zh-cn/docs/admin/introduction.html
按照操作使用maven構(gòu)建。
如果發(fā)現(xiàn)tomcat端口被占用,windows下
netstat -ano|findstr 8080
taskkill /pid 55565 /f

此文是慕課網(wǎng)的
2小時(shí)實(shí)戰(zhàn)Apache頂級(jí)項(xiàng)目-RPC框架Dubb
的同堂練習(xí)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容