1-SOA Distributed Architecture Building (dubbo)

1. Evolution of Distributed Architecture

1. Single Application Architecture

  • Advantages: For small websites, small management systems, all functions are deployed in one function, easy to use.
  • Disadvantages:1. Difficulty in performance expansion_2. Collaborative development issues_3. Disadvantage in upgrade maintenance

2. Vertical Application Architecture

  • Advantages: Single modules are deployed independently by splitting the business, which reduces the difficulty of maintenance and deployment, makes it easier for teams to perform their duties, and makes performance expansion easier and more targeted.
  • Disadvantages: Public modules cannot be reused and development performance is wasted

3. Distributed Application Architecture

  • Advantages: Separate each application by layers, rpc can be used to invoke web and service, service and service, and improve code reuse.
  • Disadvantages: Each invoked module stores a complete location and state of the invoked module, and updates all involved configurations once the location and state change

4. Service-oriented distributed architecture

Overview of****Architecture: ** As the architecture grows, service nodes become more and more, calls and dependencies between services become more and more responsible, and a unified center is needed to schedule, route and manage all services. This new architecture built on this center is the current mainstream SOA distributed architecture.

2. Module Building of Distributed Engineering

1. Distributed Module File Diagram

_Since querying a web application requires calling the crawler service interface, you must also include a service interface in the project of the order.

_If you copy an interface query project, what if more modules call this interface in the future?Are there copies of each interface?

_In this case, these interfaces can be managed as public packages using maven's dependency.At the same time, the methods in the interface class also refer to many entity beans, so the same entity beans class can be managed uniformly.

2. Distributed Dependency Diagram

3. Building a distributed module

1. Create parent module

  • New maven module

  • Define module name, package name

  • pom.xml in parent module

_Since dependent packages are distributed across multiple modules, it is best to have a place to manage all dependent versions.Here you can use the <parent>concept in maven.You can have all modules inherit this parent module, which manages versions.

<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>

    <parent>
        <groupid>org.springframework.boot</groupid>
        <artifactid>spring-boot-starter-parent</artifactid>
        <version>1.5.21.RELEASE</version>
        <relativepath /> <!-- lookup parent from repository -->
    </parent>
    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-parent</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-parent</name>
    <packaging>pom</packaging>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceencoding>UTF-8</project.build.sourceencoding>
        <project.reporting.outputencoding>UTF-8</project.reporting.outputencoding>
        <java.version>1.8</java.version>

        <fastjson.version>1.2.46</fastjson.version>
        <dubbo-starter.version>1.0.10</dubbo-starter.version>
        <dubbo.version>2.6.0</dubbo.version>
        <zkclient.version>0.10</zkclient.version>
        <mybatis.version>1.3.1</mybatis.version>
        <nekohtml.version>1.9.20</nekohtml.version>
        <xml-apis.version>1.4.01</xml-apis.version>
        <batik-ext.version>1.9.1</batik-ext.version>
        <jsoup.version>1.11.2</jsoup.version>
        <httpclient.version>4.5.5</httpclient.version>
        <commons-lang3.version>3.7</commons-lang3.version>
        <mapper-starter.version>1.2.3</mapper-starter.version>
        <jedis.version>2.9.0</jedis.version>
        <jest.version>5.3.3</jest.version>
        <jna.version>4.5.1</jna.version>
        <beanutils.version>1.9.3</beanutils.version>
    </properties>

    <dependencymanagement>
        <dependencies>
            <dependency>
                <groupid>com.alibaba</groupid>
                <artifactid>fastjson</artifactid>
                <version>${fastjson.version}</version>
            </dependency>

            <dependency>
                <groupid>com.alibaba</groupid>
                <artifactid>dubbo</artifactid>
                <version>${dubbo.version}</version>
            </dependency>

            <dependency>
                <groupid>com.101tec</groupid>
                <artifactid>zkclient</artifactid>
                <version>${zkclient.version}</version>
            </dependency>

            <dependency>
                <groupid>com.gitee.reger</groupid>
                <artifactid>spring-boot-starter-dubbo</artifactid>
                <version>${dubbo-starter.version}</version>
            </dependency>

            <dependency>
                <groupid>org.mybatis.spring.boot</groupid>
                <artifactid>mybatis-spring-boot-starter</artifactid>
                <version>${mybatis.version}</version>
            </dependency>


            <dependency>
                <groupid>net.sourceforge.nekohtml</groupid>
                <artifactid>nekohtml</artifactid>
                <version>${nekohtml.version}</version>
            </dependency>

            <dependency>
                <groupid>xml-apis</groupid>
                <artifactid>xml-apis</artifactid>
                <version>${xml-apis.version}</version>
            </dependency>

            <dependency>
                <groupid>org.apache.xmlgraphics</groupid>
                <artifactid>batik-ext</artifactid>
                <version>${batik-ext.version}</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
            <dependency>
                <groupid>org.jsoup</groupid>
                <artifactid>jsoup</artifactid>
                <version>${jsoup.version}</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
            <dependency>
                <groupid>org.apache.httpcomponents</groupid>
                <artifactid>httpclient</artifactid>
                <version>${httpclient.version}</version>
            </dependency>

            <dependency>
                <groupid>org.apache.commons</groupid>
                <artifactid>commons-lang3</artifactid>
                <version>${commons-lang3.version}</version>
            </dependency>


            <dependency>
                <groupid>tk.mybatis</groupid>
                <artifactid>mapper-spring-boot-starter</artifactid>
                <version>${mapper-starter.version}</version>
            </dependency>

            <dependency>
                <groupid>redis.clients</groupid>
                <artifactid>jedis</artifactid>
                <version>${jedis.version}</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/io.searchbox/jest -->
            <dependency>
                <groupid>io.searchbox</groupid>
                <artifactid>jest</artifactid>
                <version>${jest.version}</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
            <dependency>
                <groupid>net.java.dev.jna</groupid>
                <artifactid>jna</artifactid>
                <version>${jna.version}</version>
            </dependency>

            <dependency>
                <groupid>commons-beanutils</groupid>
                <artifactid>commons-beanutils</artifactid>
                <version>${beanUtils.version}</version>
            </dependency>


        </dependencies>
    </dependencymanagement>

    <build>
        <plugins>
            <plugin>
                <groupid>org.springframwork.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>
</project>

  • Perform the installation from the menu on the right side of the idea

(2) Build Util modules

  • Util Module Kind
  1. Third-party packages used by the web business module, such as page rendering tools, tool classes for manipulating cookie s, and so on.
  2. Third-party packages used by service business modules, such as jdbc, mybatis, jedis, activemq toolkit, and so on.
  3. Generic third-party packages, such as fastjson, httpclient, apache toolkit, and so on.
  4. Only es used in this module
  • Util Module Dependency Diagram

  • Create three Util modules

  • pom.xml in Util module
  1. souzhi-common-util
spring-boot-starter-test Test (springboot has default version number)
spring-boot-starter-web Contains tomcat container, HttpSevrletRequest, etc. (springboot has default version number)
fastjson json tool
commons-lang3 A handy apache tool library
commons-beanutils A handy apache processing entity bean tool library
commons-codec Easy to use apache decoding tool library
httpclient restful calling client
<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>
    <parent>
        <groupid>com.couragehe.souzhi</groupid>
        <artifactid>souzhi-parent</artifactid>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-common-util</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-common-util</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <!-- SpringBoot Hot Deployment Plug-ins       -->
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-devtools</artifactid>
            <optional>true</optional>         <!--This is set to true Hot deployment will take effect-->
        </dependency>

        <dependency>
            <groupid>com.alibaba</groupid>
            <artifactid>fastjson</artifactid>
        </dependency>


        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-test</artifactid>
        </dependency>


        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-web</artifactid>
        </dependency>


        <dependency>
            <groupid>org.apache.httpcomponents</groupid>
            <artifactid>httpclient</artifactid>
        </dependency>

        <dependency>
            <groupid>org.apache.commons</groupid>
            <artifactid>commons-lang3</artifactid>
        </dependency>

        <dependency>
            <groupid>commons-beanutils</groupid>
            <artifactid>commons-beanutils</artifactid>
        </dependency>

        <dependency>
            <groupid>commons-codec</groupid>
            <artifactid>commons-codec</artifactid>
        </dependency>


        <dependency>
            <groupid>com.alibaba</groupid>
            <artifactid>dubbo</artifactid>
        </dependency>

        <dependency>
            <groupid>com.101tec</groupid>
            <artifactid>zkclient</artifactid>
            <exclusions>
                <exclusion>
                    <groupid>org.slf4j</groupid>
                    <artifactid>slf4j-log4j12</artifactid>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupid>com.gitee.reger</groupid>
            <artifactid>spring-boot-starter-dubbo</artifactid>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>

</project>

  1. souzhi-web-util
Thymeleaf/jsp/freemarker Springboot comes with its own page rendering tool (springboot has a default version number)
<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>
    <parent>
        <groupid>com.couragehe.souzhi</groupid>
        <artifactid>souzhi-parent</artifactid>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-web-util</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-web-util</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <dependency>
            <groupid>com.couragehe.souzhi</groupid>
            <artifactid>souzhi-common-util</artifactid>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <!-- thymeleaf yes springBoot Native Rendering Template -->
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-thymeleaf</artifactid>
        </dependency>
        <!--    thymelead Support packages, facilities available for validation, hot deployment -->
        <dependency>
            <groupid>net.sourceforge.nekohtml</groupid>
            <artifactid>nekohtml</artifactid>
        </dependency>

        <dependency>
            <groupid>xml-apis</groupid>
            <artifactid>xml-apis</artifactid>
        </dependency>

        <dependency>
            <groupid>org.apache.xmlgraphics</groupid>
            <artifactid>batik-ext</artifactid>
        </dependency>
        <dependency>
            <groupid>io.jsonwebtoken</groupid>
            <artifactid>jjwt</artifactid>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-test</artifactid>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-test</artifactid>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>

</project>

  1. souzhi-service-util
spring-boot-starter-jdbc Database Driver (springboot has default version number)
mysql-connector-java Database Connector (springboot has default version number)
mybatis-spring-boot-starter mybatis
<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>
    <parent>
        <groupid>com.couragehe.souzhi</groupid>
        <artifactid>souzhi-parent</artifactid>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-service-util</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-service-util</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <dependency>
            <groupid>com.couragehe.souzhi</groupid>
            <artifactid>souzhi-common-util</artifactid>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-jdbc</artifactid>
        </dependency>

        <dependency>
            <groupid>org.mybatis.spring.boot</groupid>
            <artifactid>mybatis-spring-boot-starter</artifactid>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupid>mysql</groupid>
            <artifactid>mysql-connector-java</artifactid>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupid>redis.clients</groupid>
            <artifactid>jedis</artifactid>
        </dependency>
        <dependency>
            <groupid>org.redisson</groupid>
            <artifactid>redisson</artifactid>
            <version>3.10.5</version>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-test</artifactid>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-test</artifactid>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>

</project>

(3) Build api module

_Integrating the interface module with the bean module is an api module

Use maven's dependency to manage these interfaces as public packages.At the same time, the methods in the interface class also refer to many entity beans, so the same entity beans class can be managed uniformly.

  • api module dependency diagram

_Bean module refers to the generic mapper, so we extracted the dependencies of the generic mapper and put them behind the bean module into the following structure.

  • pom.xml in api module
<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>

    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-api</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-api</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
        <!-- currency mapper Implement simple additions to single tables       -->
        <dependency>
            <groupid>tk.mybatis</groupid>
            <artifactid>mapper-spring-boot-starter</artifactid>
            <version>1.2.3</version>
            <exclusions>
                <exclusion>
                    <groupid>org.springframework.boot</groupid>
                    <artifactid>spring-boot-starter-jdbc</artifactid>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>


    
    <build>
        <plugins>
            <plugin>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>
</project>

(4) Set up application module (souzhi-search-web)

  • search-web module dependency diagram

  • pom.xml in search-web module
<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>
    <parent>
        <groupid>com.couragehe.souzhi</groupid>
        <artifactid>souzhi-parent</artifactid>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-search-web</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-search-web</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupid>com.couragehe.souzhi</groupid>
            <artifactid>souzhi-api</artifactid>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupid>com.couragehe.souzhi</groupid>
            <artifactid>souzhi-web-util</artifactid>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-autoconfigure</artifactid>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-test</artifactid>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-test</artifactid>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>

</project>

  • Controller test code
@Controller
public class SearchController {
    @Reference//import com.alibaba.dubbo.config.annotation.Reference;
    SearchService searchService;

    @RequestMapping("index")
    @ResponseBody
    public String index(){
        String msg = searchService.index();
        return msg;
    }
}
  • configuration file
server.port=8011
#log level
logging.level.root=debug

##Configuration of dubbo
#Service name in dubbo
spring.dubbo.application=search-web
#Communication protocol name in dubbo
spring.duubbo.protocol.name=dubbo
#zookeeper's registry center address
spring.dubbo.registry.address=192.168.10.100:2181
#Name of communication protocol for zookeeper
spring.dubbo.registry.protocol=zookeeper
#Scan Path for dubbo's Service
spring.dubbo.base-package=com.couragehe.souzhi
#Set timeout
spring.dubbo.consumer.timeout=600000
#Set whether to detect service existence
spring.dubbo.consumer.check=false

(4) Set up application module (souzhi-search-service)

  • search-service module dependency diagram

  • pom.xml in search-web module
<!--?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelversion>4.0.0</modelversion>
    <parent>
        <groupid>com.couragehe.souzhi</groupid>
        <artifactid>souzhi-parent</artifactid>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupid>com.couragehe.souzhi</groupid>
    <artifactid>souzhi-search-service</artifactid>
    <version>0.0.1-SNAPSHOT</version>
    <name>souzhi-search-service</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupid>com.couragehe.souzhi</groupid>
            <artifactid>souzhi-api</artifactid>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupid>com.couragehe.souzhi</groupid>
            <artifactid>souzhi-service-util</artifactid>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-autoconfigure</artifactid>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-test</artifactid>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-test</artifactid>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupid>org.springframework.boot</groupid>
            <artifactid>spring-boot-starter-test</artifactid>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupid>org.springframework.boot</groupid>
                <artifactid>spring-boot-maven-plugin</artifactid>
            </plugin>
        </plugins>
    </build>

</project>

  • Service test code
@Service//import com.alibaba.dubbo.config.annotation.Service;
public class SearchServiceImpl implements SearchService {
    @Override
    public String index() {
        return "index";
    }
}
  • configuration file
server.port=8000
#log level
logging.level.root=debug

#jdbc
spring.datasource.password=123456
spring.datasource.username=root
spring.datasource.url=jdbc:mysql://localhost:3306/hms?characterEncoding=UTF-8

##Configuration of dubbo
#Service name in dubbo
spring.dubbo.application=search-service
#Communication protocol name in dubbo
spring.duubbo.protocol.name=dubbo
#zookeeper's registry center address
spring.dubbo.registry.address=192.168.10.100:2181
#Name of communication protocol for zookeeper
spring.dubbo.registry.protocol=zookeeper
#Scan Path for dubbo's Service
spring.dubbo.base-package=com.couragehe.souzhi
#Set timeout.
spring.dubbo.consumer.timeout=60000
#Set whether to detect service existence
spring.dubbo.consumer.check=false

</parent>

Tags: Programming Spring Maven Dubbo Apache

Posted on Sun, 22 Mar 2020 10:01:53 -0700 by angeljyt