• spring boot + dubbo 服务部署实例


    项目github:https://github.com/nalidou/spring-dubbo

    1. 公共组件:dubbo-component

    提供了接口定义、实体类等,其他项目可以直接导入jar包,也可以用maven导入。

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
             http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.wzy</groupId>
        <artifactId>dubbo-component</artifactId>
        <version>1.0</version>
    </project>

    2. 服务生产者:dubbo-producer

    实现了公共组件接口

    <dependencies>
            <dependency>
                <groupId>com.alibaba.spring.boot</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.6</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.101tec/zkclient -->
            <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.10</version>
            </dependency>
    
            <dependency>
                <groupId>com.wzy</groupId>
                <artifactId>dubbo-component</artifactId>
                <version>1.0</version>
            </dependency>
        </dependencies>

    package com.wzy.dubbo.producer.server;
    
    import com.alibaba.dubbo.config.annotation.Service;
    import com.wzy.component.entity.User;
    import com.wzy.component.server.IUserServer;
    import org.springframework.stereotype.Component;
    
    import java.util.ArrayList;
    import java.util.List;
    @Service(interfaceClass = IUserServer.class) //这里用的是dubbo的接口
    @Component
    public class UserServerImpl implements IUserServer {
        @Override
        public User getById(long id) {
            return new User(id, "小明");
        }
    
        @Override
        public List<User> getAll() {
            List<User> list = new ArrayList<User>();
            list.add(new User(100, "jerry"));
            list.add(new User(200, "tom"));
            return list;
        }
    }

     3. web服务(服务消费者):dubbo-web

    <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>com.alibaba.spring.boot</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
                <version>3.4.6</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.101tec/zkclient -->
            <dependency>
                <groupId>com.101tec</groupId>
                <artifactId>zkclient</artifactId>
                <version>0.10</version>
            </dependency>
    
            <dependency>
                <groupId>com.wzy</groupId>
                <artifactId>dubbo-component</artifactId>
                <version>1.0</version>
            </dependency>
        </dependencies>

    package com.wzy.dubbo.web;
    
    import com.alibaba.dubbo.config.annotation.Reference;
    import com.wzy.component.entity.User;
    import com.wzy.component.server.IOrderServer;
    import com.wzy.component.server.IUserServer;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class WebCtl {
        @Reference
        private IOrderServer orderServer;
        @Reference
        private IUserServer userServer;
    
        @RequestMapping("getUser")
        public User getUser() {
            System.out.println("WebCtl getUser...");
            System.out.println(orderServer.getName());
            return userServer.getById(100);
        }
    }

    4. 在zookeeper上查看注册节点

  • 相关阅读:
    链式队列(先进先出)
    单链表的基本操作
    线性表的基本操作
    面向对象分析与设计
    结构化分析与设计
    图片
    2021-ACM-ICPC-济南站 K Search For Mafuyu 【树的遍历与回溯,dfs, 邻接表】
    Codeforces Round #754 (Div. 2), problem: (A) A.M. Deviation泪目 万万没想到狂wa是因为这
    Codeforces Round #704 (Div. 2), problem: (C) Maximum width还是要多学习
    Educational Codeforces Round 116 (Rated for Div. 2), problem: (C) Banknotes
  • 原文地址:https://www.cnblogs.com/wwzyy/p/10659420.html
Copyright © 2020-2023  润新知