转载:http://blog.csdn.net/zjcjava/article/details/78766095

背景

Dubbo的开源人梁飞在内部的交流会上宣布重启dubbo的维护和更新,具体PPT内容请看我的个人订阅号。

因此本文基于2017-12-10号的维护的版本dubbo-2.5.7。

这里为何从Dubbo-admin开始,这不是最重要的部分,但是却是dubbo源码编译最简单的部分。

准备工作

按照zookeeper服务(参考单机安装zookeeper安装

下载dubbo源码 
https://github.com/alibaba/dubbo/releases/tag/dubbo-2.5.7

当然也可以直接从我的github上面直接下载已经编译好了的war包 
https://github.com/BambooZhang/dubbo-study

编译

解压后这里只用到一个项目就是dubbo-admin

cd D:\git_space\dubbo-dubbo-2.5.7\dubbo-dubbo-2.5.7\dubbo-admin
mvn package -Dmaven.skip.test=true

出现下面的结果则说明编译成功


[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ dubbo-admin ---
[INFO] Packaging webapp
[INFO] Assembling webapp [dubbo-admin] in [D:\git_space\dubbo-dubbo-2.5.7\dubbo-dubbo-2.5.7\dubbo-admin\target\dubbo-admin-2.5.7]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\git_space\dubbo-dubbo-2.5.7\dubbo-dubbo-2.5.7\dubbo-admin\src\main\webapp]
[INFO] Webapp assembled in [880 msecs]
[INFO] Building war: D:\git_space\dubbo-dubbo-2.5.7\dubbo-dubbo-2.5.7\dubbo-admin\target\dubbo-admin-2.5.7.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.516 s
[INFO] Finished at: 2017-12-10T17:38:17+08:00
[INFO] Final Memory: 19M/244M
[INFO] ------------------------------------------------------------------------

部署dubbo-admin到tomcat

把target\dubbo-admin-2.5.7下面的文件都拷贝到tomcat/webapps/ROOT下面

修改配置dubbo.properties 
zookeeper地址修改为自己安装的ip地址,默认是127.0.0.1

dubbo.registry.address=zookeeper://192.168.0.91:2181
dubbo.admin.root.password=root
dubbo.admin.guest.password=guest

启动dubbo-admin

首先启动zookeeper服务,在启动tomcat 
启动完成访问localhost:8080 
默认账号密码都是root 

Dubbo服务提供者和消费者demo

dubbo-admin-2.5.7.war管理中心 
dubbo-provider服务器提供者 
dubbo-consumer服务器消费者

spring版本:4.3.9.RELEASE

dubbo-provider服务器提供者

pom

<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.bamboo</groupId>
<artifactId>dubbo-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>dubbo-provider</name>
<url>http://maven.apache.org</url> <repositories>
<repository>
<id>maven-ali</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository> </repositories> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.9.RELEASE</spring.version>
</properties> <dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.7</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!-- spring相关 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

applicationProvider.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
<!-- 具体的实现bean -->
<bean id="providerService" class="com.bamboo.dubbo_provider.ProviderServiceImpl" />
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="dubbo_provider" />
<!-- 使用multicast广播注册中心暴露服务地址
<dubbo:registry address="multicast://localhost:1234" />-->
<!-- 使用zookeeper注册中心暴露服务地址 127.0.0.1:2181 -->
<dubbo:registry address="zookeeper://192.168.0.91:2181" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="29014" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.bamboo.service.ProviderService" ref="providerService" />
</beans>

java

service

package com.bamboo.service;

public interface  ProviderService {

    public String sayHello(String name);
}

ProviderServiceImpl

package com.bamboo.dubbo_provider;

import com.bamboo.service.ProviderService;

public class ProviderServiceImpl implements ProviderService {  

    public String sayHello(String name) {
return "Hello:"+name+"你好,你好~~";
} }

main.java

package com.bamboo.dubbo_provider;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* dubbo 服务提供端
* @author bamboo
*/
public class App
{
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"applicationProvider.xml"});
context.start();
System.out.println("提供者服务已注册成功");
System.out.println("请按任意键取消提供者服务");
try {
System.in.read();//让此程序一直跑,表示一直提供服务
} catch (IOException e) {
e.printStackTrace();
}
}
}

运行

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
提供者服务已注册成功
请按任意键取消提供者服务

dubbo-consumer服务器消费者

pom

<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.bamboo</groupId>
<artifactId>dubbo-consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>dubbo-consumer</name>
<url>http://maven.apache.org</url> <repositories>
<repository>
<id>maven-ali</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository> </repositories> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.9.RELEASE</spring.version>
</properties> <dependencies> <!-- 添加dubbo依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.7</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 添加zk客户端依赖 -->
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!-- spring相关 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

applicationConsumer.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd ">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="dubbo_consumer" />
<!-- 使用multicast广播注册中心暴露发现服务地址127.0.0.1:2181 -->
<dubbo:registry protocol="zookeeper" address="zookeeper://192.168.0.91:2181" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="providerService" interface="com.bamboo.service.ProviderService" />
</beans>

java

service

package com.bamboo.service;

public interface  ProviderService {

    public String sayHello(String name);
}

main

package com.bamboo.dubbo_consumer;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.bamboo.service.ProviderService;

/**
* dubbo 服务消费端
* @author bamboo
*
*/
public class App
{
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "applicationConsumer.xml" }); context.start();
ProviderService providerService = (ProviderService) context.getBean("providerService"); System.out.println(providerService.sayHello("bamboo"));
System.out.println("Press any key to exit.");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
} }
}

运行

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
Hello:bamboo你好,你好~~
Press any key to exit.

查看监控列表 

dubbo安装和使用的更多相关文章

  1. DUBBO安装配置注意事项

    DUBBO安装配置注意事项 参考URL:http://blog.csdn.net/lichunan/article/details/40349645 ====== 管理端: 记得更改TOMCAT的端口 ...

  2. Dubbo安装及其实战1

    一.Dubbo安装 (1)安装zk和tomcat yum 安装tomcat 默认路径为 /usr/share/tomcat zookeeper 我这里采用的是使用zookeeper管理的.所以要安装z ...

  3. dubbo 安装部署

    dubbo 安装部署   1 安装zookeeper 2 安装dubbo    1 下载源码 https://github.com/alibaba/dubbo 2 编译 mvn clean packa ...

  4. Dubbo 安装监控中心

    一.Dubbo 安装服务管理控制台 1.在官方Github下载Dubbo OPS 2.下载incubator-dubbo-ops源码后,解压修改配置文件Zookeeper注册中心地址 3.maven打 ...

  5. zookeeper和dubbo安装与搭建

    Zookeeper+Dubbo安装与搭建 (原创:黑小子-余) 本文有借鉴:https://www.cnblogs.com/UncleYong/p/10737119.html (一)zookeeper ...

  6. Linux系统下Dubbo安装的详细教程

    Linux系统下Dubbo安装的详细教程 1.Dubbo的简介 Dubbo是 [1]  阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 [ ...

  7. zookeeper和dubbo安装与搭建(2)

    Zookeeper+Dubbo安装与搭建(2) (原创:黑小子-余) 一.环境配置:zookeeper3.6.0 + dubbo3.5.4 + maven3.6.1 + jdk1.8 + tomcat ...

  8. dubbo 安装部署Windows

    1 安装zookeeper 2 安装dubbo    1 下载源码 https://github.com/alibaba/dubbo 2 编译 mvn clean package install -D ...

  9. dubbo安装(转载)

    1.   概述 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂 ...

  10. windows下 zookeeper dubbo 安装+配置+demo 详细图文教程

    Java集群优化——dubbo+zookeeper构建 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这 ...

随机推荐

  1. 读取Java文件到byte数组的三种方式

    package zs; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io ...

  2. vue路由细节探讨

    1.使用router-link 不会让页面刷新,使用a标签会使页面刷新.2.router-link 里面的to="/路由地址" tag=""自定义标签" ...

  3. css3 平行四边形 、大括弧

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. hdfs深入:02、今日课程内容大纲以及hdfs的基本实现

    1.hadoop第三天课程内容 hdfs:分布式文件存储系统hdfs的架构图hdfs的副本机制以及block块hdfs的元数据信息fsimage与editshdfs的文件读写过程hdfs的javaAP ...

  5. 查找BUG的方法

    1)测试环境 1)代码调试 2)问题重现 3)思考问题所在 2)生产环境 1)思考 2)测试本地环境是否存在问题 3)打开日志查看 4)思考是否是数据原因 5)拷贝数据到本地进行重现 3)未知错误 1 ...

  6. struts2与常用表格ajax操作的json传值问题

    struts与常用的dataTables和jqueryGrid等表格进行ajax传值时,经常会传值不适配的问题,这是因为struts在进行ajax操作时已经对你要操作的json数据进行了处理,所以不需 ...

  7. idea导入本地idea的web项目(服务器用的是tomcat)

    开始吧!!! 点击import project. 我以SpringMVCPro3为例,选中,点击OK 点击next 继续next 随便吧,我点击yes 选中工程,点击next lib1不要钩,然后点击 ...

  8. 零基础入门学习Python(28)--文件

    知识点 Python中使用open(...)这个内置函数来打开文件,并返回文件对象 open()函数参数说明: open(file, mode='r', buffering=-1, encoding= ...

  9. PDO、PDOStatement、PDOException

    最近在学PDO  比较详细的资料 出处:http://blog.csdn.net/hsst027/article/details/23682003 PDO中包含三个预定义的类,它们分别是PDO.PDO ...

  10. 多.h项目出现的问题:使用了预编译头依然出现error LNK2005:***obj已在***obj中定义与c++ error C2011: “xxx”:“class”类型重定义解决办法

    使用了预编译头依然出现error LNK2005:***obj已在***obj中定义 造成该问题的可能性比较多,本人将在今后遇到时添加进来,今天先放出本人遇到的一种情况. 多重包含含有变量定义的.h文 ...