dubbo安装和使用
转载: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安装和使用的更多相关文章
- DUBBO安装配置注意事项
DUBBO安装配置注意事项 参考URL:http://blog.csdn.net/lichunan/article/details/40349645 ====== 管理端: 记得更改TOMCAT的端口 ...
- Dubbo安装及其实战1
一.Dubbo安装 (1)安装zk和tomcat yum 安装tomcat 默认路径为 /usr/share/tomcat zookeeper 我这里采用的是使用zookeeper管理的.所以要安装z ...
- dubbo 安装部署
dubbo 安装部署 1 安装zookeeper 2 安装dubbo 1 下载源码 https://github.com/alibaba/dubbo 2 编译 mvn clean packa ...
- Dubbo 安装监控中心
一.Dubbo 安装服务管理控制台 1.在官方Github下载Dubbo OPS 2.下载incubator-dubbo-ops源码后,解压修改配置文件Zookeeper注册中心地址 3.maven打 ...
- zookeeper和dubbo安装与搭建
Zookeeper+Dubbo安装与搭建 (原创:黑小子-余) 本文有借鉴:https://www.cnblogs.com/UncleYong/p/10737119.html (一)zookeeper ...
- Linux系统下Dubbo安装的详细教程
Linux系统下Dubbo安装的详细教程 1.Dubbo的简介 Dubbo是 [1] 阿里巴巴公司开源的一个高性能优秀的服务框架,使得应用可通过高性能的 RPC 实现服务的输出和输入功能,可以和 [ ...
- zookeeper和dubbo安装与搭建(2)
Zookeeper+Dubbo安装与搭建(2) (原创:黑小子-余) 一.环境配置:zookeeper3.6.0 + dubbo3.5.4 + maven3.6.1 + jdk1.8 + tomcat ...
- dubbo 安装部署Windows
1 安装zookeeper 2 安装dubbo 1 下载源码 https://github.com/alibaba/dubbo 2 编译 mvn clean package install -D ...
- dubbo安装(转载)
1. 概述 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护.名字服务.分布式同步.组服务等.ZooKeeper的目标就是封装好复杂 ...
- windows下 zookeeper dubbo 安装+配置+demo 详细图文教程
Java集群优化——dubbo+zookeeper构建 互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,Dubbo是一个分布式服务框架,在这 ...
随机推荐
- Nodejs AES加密不一致问题的解决
最近在做android游戏,客户端与Nodejs服务端数据的交互用AES进行加密,发现Nodejs与java的加密形式不一样.查询N久资料发现java端需要对密钥再MD5加密一遍(我了个大擦),本来对 ...
- addslashes,stripslashes
官方介绍: (PHP 4, PHP 5) addslashes — 使用反斜线引用字符串 返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线.这些字符是单引号(’).双引号(”). ...
- RDO、SAD、SATD、λ相关概念【转】
率失真优化概述: 率失真优化(Rate D isto r t i on Op t i m ized)策略是在率失真理论[3 ]的基础上提出的一种代价函数方案, RDO 的主要思想是, 在计算代价函数时 ...
- java实现的单点登录
摘要:单点登录(SSO)的技术被越来越广泛地运用到各个领域的软件系统当中.本文从业务的角度分析了单点登录的需求和应用领域:从技术本身的角度分析了单点登录技术的内部机制和实现手段,并且给出Web-SSO ...
- CAD参数绘制多行文字(com接口)
在CAD设计时,需要绘制多行文字,用户可以设置设置绘制文字的高度等属性. 主要用到函数说明: _DMxDrawX::DrawMText 绘制一个多行文字.详细说明如下: 参数 说明 DOUBLE dP ...
- mac vim编辑器常用操作快捷方式
0 行首$ (shift+6)行尾gg 文首G(shift+g) 文尾A(Shift+a)文尾,并编辑ctrl+f 向上翻页ctrl+b 向下翻页ctrl+u 向上翻半页ctrl+d 向下翻半页数字+ ...
- 第2节 hive基本操作:9、hive当中创建外部表的语法及外部表的操作&分区表的语法和操作
外部表: 外部表说明: 外部表因为是指定其他的hdfs路径的数据加载到表当中来,所以hive表会认为自己不完全独占这份数据,所以删除hive表的时候,数据仍然存放在hdfs当中,不会删掉 管理表和外部 ...
- python circle nested
#!/usr/bin/python # -*- coding:utf- -*- # @filename: tmp2 # @author:vickey # @date: // : def circle_ ...
- forEach的使用方法
[-] 1 js 数组循环遍历 2 forEach 函数 3 让IE兼容forEach方法 4 如何跳出循环 1. js 数组循环遍历. 数组循环变量,最先想到的就是 for(var i= ...
- [0] Hello World
受不了CSDN了,广告多,慢,编辑器难用,还限制博客数量.