栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

springboot +zookeeper+dubbo

springboot +zookeeper+dubbo

1.目录结构
springboot 2.4.3
zookeeper 3.6.2
dubbo-spring-boot-starter 2.7.8

2.dubbointerface

package com.zhou.dubbointerface.service;

import java.io.IOException;

public interface ITestService {
    public String dubboCallProiderService(String params) throws IOException;

}

}

3.dubboprivder
mvn

    
        org.springframework.boot
        spring-boot-starter-parent
        2.4.3
        
    
      
        1.8
    
    

        
        
            org.springframework.boot
            spring-boot-starter
        

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

        
        
            org.apache.dubbo
            dubbo-spring-boot-starter
            2.7.8
        

        
        
            org.apache.zookeeper
            zookeeper
            3.6.2
        

        
            com.101tec
            zkclient
            0.11
        
        
            com.zhou
            dubbointerface
            0.0.1-SNAPSHOT
            compile
        

        
            org.apache.curator
            curator-recipes
            5.1.0
        
        
            org.apache.curator
            curator-framework
            5.1.0
        


    

application.properties

spring.application.name = user-server
management.port = 9091
dubbo.application.id = user-server
dubbo.application.name = user-server

## ProtocolConfig Bean
dubbo.protocol.id = dubbo
dubbo.protocol.name = dubbo
dubbo.protocol.port = 20881

impl

package com.zhou.dubboprivder.impl;

import com.zhou.dubbointerface.service.ITestService;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

import java.io.IOException;


@DubboService(interfaceClass = ITestService.class,timeout = 60000,version = "2.0.1")
public class TestServiceImpl implements ITestService {

    @Override
    public String dubboCallProiderService(String params) throws IOException {
        System.out.println("ITestService-->"+params);
        return "hello:->"+params;
    }
}

启动

package com.zhou.dubboprivder;

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

import java.io.IOException;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDubboConfig
@EnableDubbo
public class DubboprivderApplication {

    public static void main(String[] args) throws IOException {

        SpringApplication.run(DubboprivderApplication.class, args);

    }

}

3.dubboconsumer
mvn


        org.springframework.boot
        spring-boot-starter-parent
        2.4.3
        
       
 
        1.8
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.0
        

        
        
            org.apache.dubbo
            dubbo-spring-boot-starter
            2.7.8
        

        
        
            org.apache.zookeeper
            zookeeper
            3.6.2
        

        
            com.101tec
            zkclient
            0.11
        

        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            com.zhou
            dubbointerface
            0.0.1-SNAPSHOT
            compile
        
        
            org.apache.curator
            curator-framework
            5.1.0
        
        
            org.apache.curator
            curator-recipes
            5.1.0
        
    

application.properties

server.port=8081
dubbo.application.id = dubbo-dome-consumer
dubbo.application.name = dubbo-dome-consumer
dubbo.protocol.id = dubbo-dome-consumer
dubbo.protocol.name = dubbo-dome-consumer
dubbo.consumer.timeout=2000
## RegistryConfig Bean
dubbo.registry.id = dubbo-dome-consumer
dubbo.registry.address = zookeeper://127.0.0.1:2181
dubbo.protocol.port = 20890

controller

package com.zhou.dubboconsumer.controller;

import com.zhou.dubbointerface.service.ITestService;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/test")
public class TestController {
    @DubboReference(version = "2.0.1",timeout = 60000)
    private ITestService service;




    @RequestMapping("/test.action")
    public String test() throws IOException {
        String result = service.dubboCallProiderService("232");
        return result;
    }
}

启动

package com.zhou.dubboconsumer;

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

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDubbo(scanbasePackages = "com.zhou.dubboconsumer.controller")
public class DubboconsumerApplication {

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

}

先启动dubboprivder在启动dubboconsumer


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/699249.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号