• 微服务篇-B 深入理解SOA框架(Dubbo)_III SpringBoot整合Dubbo(学习总结)


    原创作者:田超凡(程序员田宝宝)

    版权所有,转载请注明原作者,严禁复制转载

    实践部分

    ittcf-dubbo-parent

    --------------ittcf-dubbo-api

    ------------------------ittcf-dubbo-api-member

    --------------ittcf-dubbo-api-member-impl

    --------------ittcf-dubbo-api-order-impl

    ittcf-dubbo-parent

    Maven依赖信息

    <parent>

                <groupId>org.springframework.bootgroupId>

                <artifactId>spring-boot-starter-parentartifactId>

                <version>2.0.1.RELEASEversion>

          parent>

          <properties>

                <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>

                <project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>

                <java.version>1.8java.version>

                <curator-framework.version>4.0.1curator-framework.version>

                <zookeeper.version>3.4.13zookeeper.version>

                <dubbo.starter.version>0.2.0dubbo.starter.version>

          properties>

          <dependencies>

                <dependency>

                      <groupId>org.springframework.bootgroupId>

                      <artifactId>spring-boot-starter-webartifactId>

                dependency>

                <dependency>

                      <groupId>com.alibaba.bootgroupId>

                      <artifactId>dubbo-spring-boot-starterartifactId>

                      <version>${dubbo.starter.version}version>

                dependency>

                <dependency>

                      <groupId>org.apache.curatorgroupId>

                      <artifactId>curator-frameworkartifactId>

                      <version>${curator-framework.version}version>

                dependency>

                <dependency>

                      <groupId>org.apache.zookeepergroupId>

                      <artifactId>zookeeperartifactId>

                      <version>${zookeeper.version}version>

                dependency>

                <dependency>

                      <groupId>org.springframework.bootgroupId>

                      <artifactId>spring-boot-starter-testartifactId>

                      <scope>testscope>

                dependency>

          dependencies>

          <build>

                <plugins>

                      <plugin>

                            <groupId>org.springframework.bootgroupId>

                            <artifactId>spring-boot-maven-pluginartifactId>

                      plugin>

                plugins>

          build>

    生产者

    ittcf-dubbo-api-member-impl

    Maven依赖信息

          <dependencies>

                <dependency>

                      <groupId>com.ittcfgroupId>

                      <artifactId>ittcf-dubbo-api-memberartifactId>

                      <version>0.0.1-SNAPSHOTversion>

                dependency>

          dependencies>

    application.yml

    server:

      port: 8080

    dubbo:

      application:

        name: member

      protocol:

        name: dubbo

        port: 20880

      registry:

        address: zookeeper://127.0.0.1:2181

      scan:

        base-packages: com.ittcf.api.member.impl

    发布服务

    @Service

    public class MemberServiceImpl implements MemberService {

          @Override

          public String getUser() {

                return "订单服务调用会员服务接口";

          }

    }

    注意:@Service 注解引入为阿里巴巴注解

    启动服务

    @EnableDubbo

    @SpringBootApplication

    public class AppMember {

          public static void main(String[] args) {

                SpringApplication.run(AppMember.class, args);

          }

    }

    @EnableDubbo 开启Dubbo服务功能

    消费者

    ittcf-dubbo-api-order-impl

    Maven依赖信息

         <dependencies>

               <dependency>

                    <groupId>com.ittcfgroupId>

                    <artifactId>ittcf-dubbo-api-memberartifactId>

                    <version>0.0.1-SNAPSHOTversion>

               dependency>

         dependencies>

    application.yml

    server:

      port: 8081

    ###dubbo 注册服务名称

    dubbo:

      application:

        name: order

     ###dubbo服务地址

      protocol:

        name: dubbo

        port: 20880

      registry:

        address: zookeeper://localhost:2181

      consumer:

        timeout: 5000

    调用服务

          @Reference

          private MemberService memberService;

          @RequestMapping("/orderToMember")

          public String orderToMember() {

                return memberService.getUser();

          }

    使用该  @Reference调用dubbo接口

    启动项目

    @EnableDubbo

    @SpringBootApplication

    public class AppOrder {

          public static void main(String[] args) {

                SpringApplication.run(AppOrder.class, args);

          }

    }

    本文部分素材转载自蚂蚁课堂

  • 相关阅读:
    (附源码)springboot菠萝大学课室预约分析与设计 毕业设计641656
    [Angular 基础] - routing 路由(上)
    js arrys函数
    JVM8 元空间
    DJ13-1 汇编语言程序设计-1
    蓝桥算法赛(摆玩具)
    Qt之天气预报实现(一)预备篇
    JSR303和拦截器
    使用Enterprise Architect(EA)的插件AtScope,解析代码中函数和变量调用关系
    (附源码)ssm基于jsp的网上购物系统 毕业设计 190917
  • 原文地址:https://blog.csdn.net/qq_30056341/article/details/136609794