springboot dubbo3 zookeeper整合

springboot dubbo3 zookeeper整合

  1. 在这个项目的基础上: Nexus 私服资源的上传下载
  2. 项目放到 gitee 上了,地址为: https://gitee.com/qinenqi/zookeeperdubbo.git

provider项目

  1. pom 文件:


    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent


        2.2.6.RELEASE
         
    
    com.example
    provider
    0.0.3
    provider
    Demo project for Spring Boot
    
        1.8
        3.0.4
        4.2.0
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.projectlombok
            lombok
            1.18.22
        
        
        
            org.apache.dubbo
            dubbo-spring-boot-starter
            ${dubbo-boot.version}
        
        
            org.apache.dubbo
            dubbo-dependencies-zookeeper
            3.0.7
            pom
        

    

    
    
        
            
            test-release
            
            http://192.168.88.100:8081/repository/test-release/
        
        
            
            test-snapshot
            
            http://192.168.88.100:8081/repository/test-snapshot/
        
    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.8.1
                
                    1.8
                    1.8
                    UTF-8
                
            

        
    



  1. application.yml文件
server:
  port: 8085

dubbo:
  application:
    name: provider
  registry:
    address: zookeeper://localhost:2181
    timeout: 600000
    parameters:
      blockUntilConnectedWait: 600000
  protocol:
    name: dubbo
    port: 20880
  scan:
    base-packages: com.example.provider.service


package com.example.provider.service;

/**
 * @author qeq
 * @date 2022-10-21 16:02
 */
public interface TestService {

    String test();
}

package com.example.provider.service.impl;

import com.example.provider.service.TestService;
import org.springframework.stereotype.Service;

/**
 * @author qeq
 * @date 2022-10-21 16:03
 */
@Service
public class TestServiceImpl implements TestService {

    @Override
    public String test() {
        return "TestServiceImpl";
    }
}

package com.example.provider;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableDubbo
public class ProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

}

项目 deploy 至私服中,方便consumer调用
springboot dubbo3 zookeeper整合_第1张图片

consumer项目:

pom文件:



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.2.6.RELEASE
         
    
    com.example
    consumer
    0.0.1-SNAPSHOT
    consumer
    Demo project for Spring Boot
    
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.projectlombok
            lombok
            1.18.22
        

        
            com.example
            provider
            0.0.3
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



application.yml 文件:

server:
  port: 8086

dubbo:
  application:
    name: consumer
  registry:
    address: zookeeper://localhost:2181
  protocol:
    name: dubbo



package com.example.consumer;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableDubbo
public class ConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }

}

package com.example.consumer.controller;


import com.example.provider.rpcservice.TestRpcService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qeq
 * @date 2022-10-21 14:21
 */
@RestController
@RequestMapping("/testController")
public class TestController {

    @DubboReference
    private TestRpcService testRpcService;

    /**
     *  127.0.0.1:8086/testController/test
     * @author qeq
     * @date 2022/10/21 14:22
     * @return String
     **/
    @RequestMapping("test")
    public String test(){
        String str = "success-consumer: ";
        System.out.println(str);
        String test = testRpcService.test();

        return str + test;
    }
}

测试之: 127.0.0.1:8086/testController/test
springboot dubbo3 zookeeper整合_第2张图片

你可能感兴趣的:(nexus,centos7,springboot,java-zookeeper,zookeeper,spring,boot)