zoukankan      html  css  js  c++  java
  • 基于mave的dubbo分别架构

    开始前,先看一下demo项目工程结构:

    1、抽离接口

    dubbo-api工程,根据业务抽离接口,deploy到mave nexus。

    public interface TestService {
        /**
         * @param name
         * @return
         */
        public String sayHello(String name);
        /**
         * @param cmd
         * @return
         */
        public String linuxCMD(String cmd);
    
    }

    提供三维坐标:

    <dependency>
      <groupId>com.dubbo</groupId>
      <artifactId>dubbo-api</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>

    2、提供者和消费者并行

    dubbo-service工程pom引入实现接口三维坐标实现接口。

    import com.dubbo.service.TestService;
    import com.dubbo.common.TestLinuxCmd;
    public class TestServiceImpl implements TestService { @Override public String sayHello(String name) { // TODO Auto-generated method stub return null; } @Override public String linuxCMD(String cmd) { String exec = TestLinuxCmd.exec("192.168.20.20", "root", "123456", 22, name); return exec; } }

    注:TestLinuxCmd方法来至dubbo-common工程,公共方法到放到这里,就不多做解释了。

    写完服务记得暴露出服务:

    <dubbo:service interface="com.dubbo.service.TestService" ref="testService" />

    dubbo-controller工程pom同样也要引入实现接口三维坐标,调用这个接口。

    package com.dubbo.controller;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.ResponseBody;
    import com.dubbo.service.TestService;
    @Controller
    public class MyController {
        @Autowired
        private TestService testService;
        @RequestMapping(value = "/test")
        @ResponseBody
        public String testSay(@RequestParam(value = "name",defaultValue = "") String name){
            StringBuffer sb = new StringBuffer();
            sb.append("Dubbo: ").append(testService.sayHello(name));
            return sb.toString();
        }
    }

    消费者不需要关心谁提供的服务,它只需要调用三维坐标的接口即可。

    写完同样记得暴露出服务:

        <dubbo:reference interface="com.dubbo.service.TestService" id="testService" check="false" />

     源码下载:

    https://files.cnblogs.com/files/Javame/dubbo.zip

  • 相关阅读:
    QT visual stuido 集成插件不能打开ui文件的原因
    KLSudoku 1.2 数独游戏软件发布
    QT for linux 的错误 undefined reference to 'FcFreeTypeQueryFace' 的解决方法
    tp3.2源码解析——入口文件
    关于php调用.net的web service 踩过的坑
    CentOS7 LNMP+phpmyadmin环境搭建(二、LNMP环境搭建)
    CentOS7 LNMP+phpmyadmin环境搭建(一、虚拟机及centos7安装)
    php无限分类
    php的文件引用
    CentOS7 LNMP+phpmyadmin环境搭建(三、安装phpmyadmin)
  • 原文地址:https://www.cnblogs.com/Javame/p/8034079.html
Copyright © 2011-2022 走看看