开始前,先看一下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.-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", "", , 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

最新文章

  1. java web(六)多个请求对应一个Servlet
  2. memcached的最佳实践方案
  3. 用mciSendString做音乐播放器
  4. Python学习总结3:元组、列表的操作汇总
  5. 在fedora 桌面上添加应用程序
  6. Jordan Lecture Note-4: Linear &amp; Ridge Regression
  7. C#线程篇---Task(任务)和线程池不得不说的秘密(5)
  8. Android 获取imageview的图,在另一个imageview里显示。
  9. 【C++模版之旅】静态多态的讨论
  10. Selenium 使用Eclipse+TestNG创建一个Project中遇到的问题
  11. XML(一)XML大揭秘
  12. RESTful Console Application
  13. django中如何实现分页功能
  14. Git 记不住命令
  15. 二、selenium 安装
  16. Feature Extractor[content]
  17. Addition Chains POJ - 2248 (bfs / dfs / 迭代加深)
  18. loadrunner:Action.c(4): Error -27796: Failed to connect to server &quot;192.168.66.3:8080&quot;: [10060] Connection timed out
  19. 利用TensorFlow实现线性回归模型
  20. matlab 向量场线积分

热门文章

  1. Codeforces828 B. Black Square
  2. Android Studio导入项目一直卡在Building gradle project info的解决方案
  3. spring boot开发笔记——mybatis
  4. 【洛谷4770】 [NOI2018]你的名字(SAM,线段树合并)
  5. [ZJOI2019]语言
  6. 程序性能调优工具之gprob
  7. 机器学习技法笔记:04 Soft-Margin Support Vector Machine
  8. 09-部署配置kubedns插件
  9. shell编程中的循环语句
  10. epel安装第三方扩展源后,运行yum报错的解决方案