转载: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. 解剖嵌入式设备开发时以SD卡启动时SD卡的存储结构(以三星exynos4412为例)

    目前面对高性能产品的嵌入式开发中,用SD卡来代替以往的JLINK显得备受大家喜欢,而且MCU厂家也对以SD卡启动的支持度越来越大,反而对JLINK不在那么重视(不过依旧保留着).一些以开发开发板的公司 ...

  2. tf.app.run() got unexpected keyword argument 'argv'

    运行的代码是mnist_with_summaries.py.出现的问题是 tf.app.run() got unexpected keyword argument 'argv' 昨天一直以为是我自己不 ...

  3. HTTP请求报文与响应报文格式

    请求报文包含三部分: a.请求行:包含请求方法.URI.HTTP版本信息 b.请求首部字段 c.请求内容实体 响应报文包含三部分: a.状态行:包含HTTP版本.状态码.状态码的原因短语 b.响应首部 ...

  4. C#面试问题及答案

    1.遇到高并发的问题如何解决? 优化SQL语句 多线程 分布式服务器 集群 拆表2.Dictionary和ConurrentDictionary的区别? 后者是线程安全的 前者适用于单线程3.Dict ...

  5. Linux运维到底是做什么的?在开始学习之前,你必须了解这些!

    首先祝贺你选择学习Linux,你可能即将踏上Linux的工作之旅,出发之前,让我带你来看一看关于Linux和Linux运维的一切. Linux因其高效率.易于裁剪.应用广等优势,成为了当今中高端服务器 ...

  6. 【原】jq简易教程

    https://www.jianshu.com/p/3522fe70de19 https://www.jianshu.com/p/6de3cfdbdb0e 1. jq简介 jq可以对json数据进行分 ...

  7. bash基础——管道符、通配符

    1.多命令顺序执行 多命令顺序执行 格式 作用 ; 命令1 ; 命令2 多个命令之间没有任何逻辑联系 && 命令1&&命令2 逻辑与 当命令1正确执行,则命令2才会执行 ...

  8. 2.10.2 section元素

    section元素 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...

  9. SQL表变量与临时表区别 + 非游标临时表遍历

    SQL表变量与临时表区别 + 非游标临时表遍历 分类: SQL Server2009-11-27 17:01 1196人阅读 评论(2) 收藏 举报 sqlinsert存储sql servermicr ...

  10. react之webpack

    1. 下载相关模块包 * 创建package.json ``` npm init ``` * react相关库 package-lock.json ``` npm install react reac ...