dubbo学习-01

1. dubbo 依赖包 pom.xml

    <dependencies>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>dubbo</artifactId>
                <version>2.5.3</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.jboss.netty</groupId>
                        <artifactId>netty</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>com.dubbo</groupId>
                <artifactId>dubbo_config</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.dubbo</groupId>
                <artifactId>dubbo_service</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.8</version>
            </dependency>
            <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.9</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.netty</groupId>
                <artifactId>netty</artifactId>
                <version>3.2.5.Final</version>
            </dependency>
    <dependencies>

2. dubbo 与 spring 结合使用配置

2.1 提供者
    <?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.xsd
           http://code.alibabatech.com/schema/dubbo
           http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreResourceNotFound" value="true"/>
            <property name="order" value="2"/>
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
            <property name="locations">
                <list>
                        <value>
                            classpath*:zookeeper.properties
                        </value>
                        <value>
                            file:d:/setting/zookeeper.properties
                        </value>
                </list>
            </property>
        </bean>
        <dubbo:application name="user-service"/>
        <dubbo:registry protocol="zookeeper" address="${zookeeper.address}"/>
        <dubbo:protocol name="dubbo" port="20880"/>
        <dubbo:provider retries="3" timeout="10000" threads="500"/>
        <dubbo:service interface="com.dubbo.service.IndexTestService" ref="indexTestServiceImpl"/>
    </beans>
2.2 消费者
    <?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.xsd
           http://code.alibabatech.com/schema/dubbo
           http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreResourceNotFound" value="true"/>
            <property name="order" value="2"/>
            <property name="ignoreUnresolvablePlaceholders" value="true"/>
            <property name="locations">
                <list>

                        <value>
                            classpath*:zookeeper.properties
                        </value>
                        <value>
                            file:d:/setting/zookeeper.properties
                        </value>

                </list>
            </property>
        </bean>
        <dubbo:application name="user-service"/>
        <dubbo:registry protocol="zookeeper" address="${zookeeper.address}"/>
        <dubbo:protocol name="dubbo" port="20880"/>
        <dubbo:reference interface="com.dubbo.service.IndexTestService" id="indexTestServiceImpl"/>
    </beans>

3. dubbo 注册中心 zookeeper.properties

    zookeeper.address=192.168.121.132:2181

4. dubbo 启动的三种方式

    1.使用servlet容器运行,即将dubbo部署在tomcat上。
        缺点:增加复杂性,浪费内存资源
    2.使用main方法调用spring容器运行dubbo
        缺点:dubbo自身的高级特性没有使用到
    3.使用dubbo框架提供的main方法运行

5.使用maven构建dubbo的jar包

    启动jar包命令: java -jar jar包名称

6. dubbo管控台

    主要作用:服务治理
    包含模块:
        路由规则,动态配置,访问控制,权重调整,负载均衡

7、采用dubbo自身的main方法运行dubbo,导出dubbo的jar需要在pom.xml文件中配置

        <?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>exercise</artifactId>
            <groupId>com.dubbo</groupId>
            <version>1.0-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>

        <artifactId>dubbo_provider_self</artifactId>
        <packaging>jar</packaging>

        <dependencies>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>dubbo</artifactId>
                <version>2.5.3</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.jboss.netty</groupId>
                        <artifactId>netty</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>com.dubbo</groupId>
                <artifactId>dubbo_config</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.dubbo</groupId>
                <artifactId>dubbo_service</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.8</version>
            </dependency>
            <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.9</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.netty</groupId>
                <artifactId>netty</artifactId>
                <version>3.2.5.Final</version>
            </dependency>
        </dependencies>


        <build>
            <resources>
                <!--配置将classes下的所有的xml,properties文件打入jar包-->
                <resource>
                    <targetPath>${project.build.directory}/classes</targetPath>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>**/*.xml</include>
                        <include>**/*.properties</include>
                    </includes>
                </resource>
                <!--由于dubbo默认加载spring的配置为/classes/META-INF/spring/*.xml,
                因此需要配置一下内容,将自己的.xml文件拷贝到指定目录下-->
                <resource>
                    <targetPath>${project.build.directory}/classes/META-INF/spring</targetPath>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>
                            applicationContext-provider.xml
                        </include>
                    </includes>
                </resource>
            </resources>
            <plugins>
                <!--打jar包时,配置manifest文件,加入lib包依赖-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <classesDirectory>target/classes/</classesDirectory>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                                <!--<useUniqueVersions>false</useUniqueVersions>-->
                            </manifest>
                            <manifestEntries>
                                <Calass-Path>.</Calass-Path>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <type>jar</type>
                                <includeTypes>jar</includeTypes>
                                <useBaseVersion>false</useBaseVersion>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>




    </project>

猜你喜欢

转载自blog.csdn.net/shan_zhi_jun/article/details/79183469
今日推荐