1. 程式人生 > >dubbo入門之springboot+dubbo

dubbo入門之springboot+dubbo

1、建立mave專案:

圖片.png

2、修改pom.xml檔案:

    4.0.0

    com.ym
    springbootdubbo
    pom
    1.0-SNAPSHOT
    
        service
        serviceImpl
        testweb
    

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.9.RELEASE
    
    
        UTF-8
        1.8
        1.8
    
    
        
            junit
            junit
            3.8.2
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            com.alibaba.boot
            dubbo-spring-boot-starter
            0.1.0
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        
        
            ch.qos.logback
            logback-core
        
        
            ch.qos.logback
            logback-classic
        
        
            com.101tec
            zkclient
            0.10
        
        
            org.eclipse.jetty
            jetty-maven-plugin
            9.4.6.v20170531
        

    

    
        
                
                    maven-clean-plugin
                    3.0.0
                
                
                    maven-resources-plugin
                    3.0.2
                
                
                    maven-compiler-plugin
                    3.7.0
                
                
                    maven-surefire-plugin
                    2.20.1
                
                
                    maven-jar-plugin
                    3.0.2
                
                
                    maven-install-plugin
                    2.5.2
                
                
                    maven-deploy-plugin
                    2.8.2


3、建立遠端介面定義模組:

圖片.png

4、建立介面:

圖片.png

5、建立介面實現模組:

圖片.png

6、springboot整合application.yml:

dubbo-provider-app
9090
com.ym.service
  dubbo-provider
    dubbo-provider
  duboo
    dubbo
    12345
    server my-reg
    zookeeper://192.168.1.224:2181
true
9091
  load,threadpool
        memory

7、實現介面:

圖片.png

com.ym.service.impl;

com.alibaba.dubbo.config.annotation.;
com.ym.service.TestService;

(version = ,application = ,protocol = ,registry = ) TestServiceImpl TestService {
    String getData(String name) {
        + name;
    }
}

8、建立啟動程式:

ym;

org.springframework.boot.SpringApplication;
org.springframework.boot.autoconfigure.;

StartSpringBootMain {
    main(String[] args) {
        SpringApplication.(StartSpringBootMain.);
    }
}

觀察dubbo控制檯:

圖片.png

圖片.png


9、建立消費端:

圖片.png


10、整合springboot和dubbo(application.yml):

dubbo-consumer-app
8080
dubbo-consumer
    dubbo-consumer
  duboo
    dubbo
    54321
  my-reg
    zookeeper://192.168.1.224:2181

11、建立controller程式,引用遠端介面:

com.ym.controller;

com.alibaba.dubbo.config.annotation.;
com.ym.service.TestService;
org.springframework.web.bind.annotation.;
org.springframework.web.bind.annotation.;
org.springframework.web.bind.annotation.;

()
TestController {

    (version = , application = )
    TestService ;

    ()
    String getData(() String name) {
        .getData(name);
    }
}

12、建立啟動程式,並啟動專案:

com.ym;

org.springframework.boot.SpringApplication;
org.springframework.boot.autoconfigure.;

(scanBasePackages = )
StartSpringBootMain {
    main(String[] args) {
        SpringApplication.(StartSpringBootMain.);
    }
}

13、觀察dubbo控制檯:

圖片.png

圖片.png