dubbo - What is dubbo & dubbo architecture & dubbo entry procedures?!!

Graphic: (dubbo effect: the system (the war package) and service (war package) in the middle of a bridge!)
                                    (No dubbo, system layer will not be able to call the service layer)

Here Insert Picture Description
Analysis:
       Before our system layer is a war package, while Service layer is a jar package, you can use the direct system layer calls the service layer, and now we are using a distributed architecture, system level package is war, war is the service layer package, so the use of dubbo!
 

First, what is Dubbo?

       Dubbox is a distributed service framework , its predecessor is an open source project Alibaba Dubbo , is the use of domestic electricity providers and Internet projects, the late Ali Baba stopped the maintenance of the project, Dangdang will be optimized on the basis of Dubbo , and continues to maintain in order to distinguish the original Dubbo, it will be named Dubbox.
       Dubbox is committed to providing high performance and transparency of RPC remote service call programs, services and SOA governance program. Simply put, dubbox is a service framework, if not distributed demand, in fact, do not need, and demand is only distributed in time, have a distributed service framework such dubbox , and essentially to serve call, saying that white is a distributed framework for remote service invocation.

Official Summary:
       Dubbo is a high-performance , lightweight , java-based RPC framework.

Apache Dubbo is a high-performance, light weight, java based RPC framework.

Two, Dubbo architecture?

Here Insert Picture Description

  • 1. Provider: Service Provider : interface address will be exposed to the registry. ( Service registry)
  • 2. Consumer: the service consumer : first need to monitor registry, there are services such as service consumer needs on the registry, then you can go directly to the call. ( Service Discovery)
  • 3. Registry: Registry : container (storage interface message). In dubbo, you can register as a center are: redis, multicast, zookeeper.
  • 4. Container: a container (container service is running: Tomcat)
  • 5. Monitor: Monitoring Center (software, needs to be placed under webapp)

Third, what is the distributed architecture?

Distributed architecture: the business is split!

  • System : accepting requests and response data (controller presentation layer) -> a packaging! WAR package
  • Service :! Business logic processing (service business layer) -> a packaging war package

 

Four, dubbo entry procedures!

1. Start a virtual machine installed on the zookeeper (registry)

Here Insert Picture Description

2. Service (service level - war package)

2.1 pom.xml

maven project import dependent jar package, and plug configuration tomcat (port number 8081 )

2.2 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
 
  <!-- 加载spring容器 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:dubbo-provider.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

2.3 dubbo-provider.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.xsd 
       http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 配置服务名 -->
    <dubbo:application name="dubbo-service" />
    <!-- 配置注册中心 -->
    <dubbo:registry address="zookeeper://192.168.200.128:2181" />
    <!-- 暴露服务地址 -->
    <dubbo:annotation package="com.jxj.service" />

</beans>

2.4 Interface UserService.java

public interface UserService {
    public String showName();
}

2.5 implementation class UserServiceImple.java

import com.alibaba.dubbo.config.annotation.Service;
import com.jxj.service.UserService;

@Service  // 导入阿里巴巴的service包!
public class UserServiceImpl implements UserService {

    @Override
    public String showName() {
        return "hello dubbo";
    }
}
3. The system (controller layer - war package)

3.1 pom.xml

maven project import dependent jar package, and configuration tomcat plug (port number 8080 )
Note: Port and port number to the service level is not the same!

3.2 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
         
  <!-- 配置前端控制器 -->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!-- 加载配置文件的位置 -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:dubbo-consumer.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <!-- 拦截请求的url-->
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

</web-app>

3.3 dubbo-consumer.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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 配置映射处理器和适配处理器 -->
    <mvc:annotation-driven />

    <!-- 1.配置服务名 -->
    <dubbo:application name="dubbo-consumer" />
    <!-- 2.配置注册中心 -->
    <dubbo:registry address="zookeeper://192.168.200.128:2181" />
    <!-- 3.发现服务 -->
    <dubbo:annotation package="com.jxj.controller" />
</beans>

3.4 Public Interface UserService.java

public interface UserService {
    public String showName();
}

3.5 UserController.java

/**
 *   RestController:
 *       包含了Controller 和 ResponseBody.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Reference  // 引用.
    public UserService userService;

    @RequestMapping("/showName.do")
    public String showName(){
        return userService.showName();
    }
}
Published 107 original articles · won praise 173 · views 120 000 +

Guess you like

Origin blog.csdn.net/qq_42986107/article/details/85042243