zoukankan      html  css  js  c++  java
  • springboot+dubbo微服务入门

    springboot+dubbo微服务入门

    • dubbo-api
    • dubbo-provider
    • dubbo-consumer

    服务提供者依赖和服务消费者依赖:

    <dependency>
            <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.7.8</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-dependencies-zookeeper -->
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-dependencies-zookeeper</artifactId>
                <version>2.7.8</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>com.botao</groupId>
                <artifactId>dubbo-api</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency
    

    服务提供者配置文件:

    server:
      port: 8001
    dubbo:
      application:
        name: dubbo-provider
      registry:
        address: zookeeper://127.0.0.1:2181
      protocol:
        name: dubbo
        port: 20880
    
    

    服务消费者配置文件:

    server:
      port: 8080
    dubbo:
      application:
        name: dubbo-consumer
      registry:
        address: zookeeper://127.0.0.1:2181
    

    服务提供者业务代码

    @DubboService(version = "1.0.0")
    public class IUserServiceImpl implements IUserService {
        @Override
        public User getUserById(int id) {
            return new User(id,"admin","123456");
        }
    }
    

    服务消费者调用代码

        @DubboReference(version = "1.0.0")
        IUserService iUserService;
        @RequestMapping("/getUserById")
        public User getUserById(int id){
            return iUserService.getUserById(id);
        }
    

    调用:http://127.0.0.1:8080/getUserById?id=15

    结果:

    // 20210218110942
    // http://127.0.0.1:8080/getUserById?id=15
    
    {
      "id": 15,
      "username": "admin",
      "password": "123456"
    }
    
  • 相关阅读:
    vue学习之五生命周期
    vue学习之四组件系统
    vue学习之三常用命令
    vue学习之二ECMAScript6标准
    vue学习之一vue初识
    (转)nginx负载均衡(5种方式)、rewrite重写规则及多server反代配置梳理
    python技巧总结之set、日志、rsa加密
    (转)二十三种设计模式及其python实现
    Python之traceback错误堆栈信息处理
    python虚拟环境--virtualenv
  • 原文地址:https://www.cnblogs.com/botaoJava/p/14411081.html
Copyright © 2011-2022 走看看