消费者模块的配置

  1. 消费者consume中pom.xml的配置 ,

           引入接口和spring-boot-starter-web 是指这是一个web模块
    
           spring-boot-starter-web如果用2.1.5.RELEASE 会报错,先用1.5.3 
    
       <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>1.5.3.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.hcb</groupId>
                <artifactId>dubboapi</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
  1. 建立配置文件 和provider一样,名字换成consumer就可以

    spring.dubbo.appname=dubboconsumer
    spring.dubbo.registry=zookeeper://192.168.159.131:2181
  1. 建立启动类

    package com.hcb;
    
    import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    import java.util.concurrent.CountDownLatch;
    
    @SpringBootApplication
    @EnableDubboConfiguration
    public class Consumer {
        public static void main(String[] args)  {
            SpringApplication.run(Consumer.class,args);
        }
    }
    
  1. 建立controll类实现接口

    package com.hcb;
    
    import com.alibaba.dubbo.config.annotation.Reference;
    import com.hcb.Service.IHelloService;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/hello")
    public class HelloController {
        @Reference
        IHelloService ihelloService;
    
        @RequestMapping
        public String hello(@RequestParam String name){
            return ihelloService.SayHello(name);
        }
    }
    
  1. 启动消费者

    1561035794634

    1561035816270

    1. 测试

    浏览器中输入 http://localhost:8080/hello?name=%E6%A1%82%E6%9E%97

    正确显示出来

    1561036292281

源码下载地址:
链接:https://pan.baidu.com/s/1WO2BQnsmIxP04mWNZin93A
提取码:5h0w


本文由 hcb 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

还不快抢沙发

添加新评论