微服务架构近年来非常的火,阿里 的dubbo 是其中的一种解决方案。

dubbo 的微服务主要分为以下几部分:

1.注册中心

2.服务提供者

3.消费者

4.监控平台

1.一般流程服务提供者向注册中心注册服务。

2.客户端向注册中心请求服务。

3.注册中心通知客户端访问提供者。

4.监控负责服务是否可用。

1.注册中心的安装

就是安装zookeeper ,为了测试我们可以简单的安装一台就好,也可以安装多台做集群。

将conf 目录下的 zoo_sample.cfg 改名成为 zoo.cfg 编辑上面两项 就好了。

2.实现微服务的provider 。

实现 服务接口

public interface DemoService {
String sayHello(String name);
}

写个简单的实现

public class DemoServiceImpl implements DemoService {

@Override
public String sayHello(String name) { return "hello:" + name;
} }

然后做spring配置。

配置文件如下

<?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://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:application name="hello-world-app" /> <!-- 使用multicast广播注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://192.168.31.77:2181" /> <!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="2088" /> <!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="demo.DemoService" ref="demoService" /> <!-- 和本地bean一样实现服务 -->
<bean id="demoService" class="demo.impl.DemoServiceImpl" />
</beans>

这样provider就玩成了。

需要再平台中引入相关的jar包。

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.12.0</version>
</dependency>

3.安装dubbo WEB 管理

包下载地址 https://github.com/apache/incubator-dubbo-ops/

将项目导入 eclipse

执行 mvn clean package 需要注意的是可能会报错

再pom.xml 中增加

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
</plugin>

修改配置文件

执行 java -jar dubbo-admin-0.0.1-SNAPSHOT.jar 这样 dubbo 管理控制台就可以运行了。

4.开发客户端

增加配置文件

<?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://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd"> <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="consumer-of-helloworld-app" /> <!-- 使用multicast广播注册中心暴露发现服务地址 -->
<dubbo:registry address="zookeeper://192.168.31.77:2181" /> <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="demoServiceClient" interface="demo.DemoService" />
</beans>

开发java代码如下

public class DubboComsumerTest extends SimpleBaseTestCase{
@Resource
DemoService demoService; @Test
public void hello(){
String rtn=demoService.sayHello("ray");
System.out.println(rtn);
}
}
@RunWith(JUnit4ClassRunner.class)
@ContextConfiguration({"classpath:spring-test.xml"})
public class SimpleBaseTestCase { }

  这样执行单元测试就可以看到效果了。

集成 dubbo 微服务的更多相关文章

  1. 使用Redis为注册中心的Dubbo微服务架构(基于SpringBoot)

    title: 使用Redis为注册中心的Dubbo微服务架构(基于SpringBoot) date: 2019-07-30 14:06:29 categories: 架构 author: mrzhou ...

  2. k8s-1-交付dubbo微服务

    一.Dubbo微服务概述 1.1: dubbo介绍 1.2: 部署内容 二.实验环境架构 2.1: 架构 1.1 架构图解 1.最上面一排为K8S集群外服务 1.1 代码仓库使用基于git的gitee ...

  3. Docker 系列七(Dubbo 微服务部署实践).

    一.前言 之前我们公司部署服务,就是大家都懂的那一套(安装JDK.Tomcat —> 编译好文件或者打war包上传 —> 启动Tomcat),这种部署方式一直持续了很久,带来的问题也很多: ...

  4. ZooKeeper分布式专题与Dubbo微服务入门

    第1章 分布式系统概念与ZooKeeper简介对分布式系统以及ZooKeeper进行简介,使得大家对其有大致的了解1-1 zookeeper简介1-2 什么是分布式系统1-3 分布式系统的瓶颈以及zk ...

  5. 交付Dubbo微服务到kubernetes集群

    1.基础架构 1.1.架构图 Zookeeper是Dubbo微服务集群的注册中心 它的高可用机制和k8s的etcd集群一致 java编写,需要jdk环境 1.2.节点规划 主机名 角色 ip hdss ...

  6. (转)实验文档2:实战交付一套dubbo微服务到kubernetes集群

    基础架构 主机名 角色 ip HDSS7-11.host.com k8s代理节点1,zk1 10.4.7.11 HDSS7-12.host.com k8s代理节点2,zk2 10.4.7.12 HDS ...

  7. Dubbo 微服务系列(03)服务注册

    Dubbo 微服务系列(03)服务注册 [TOC] Spring Cloud Alibaba 系列目录 - Dubbo 篇 1. 背景介绍 图1 Dubbo经典架构图 注:本图来源 Dubbo官方架构 ...

  8. 8.实战交付一套dubbo微服务到k8s集群(1)之Zookeeper部署

    1.基础架构 主机名 角色 ip HDSS7-11.host.com K8S代理节点1,zk1 10.4.7.11 HDSS7-12.host.com K8S代理节点2,zk2 10.4.7.12 H ...

  9. 实战交付一套dubbo微服务到k8s集群(1)之Zookeeper部署

    基础架构 主机名 角色 IP地址 mfyxw10.mfyxw.com K8S代理节点1,zk1 192.168.80.10 mfyxw20.mfyxw.com K8S代理节点2,zk2 192.168 ...

随机推荐

  1. PTA 7-50 畅通工程之局部最小花费问题(最小生成树Kruskal)

    某地区经过对城镇交通状况的调查,得到现有城镇间快速道路的统计数据,并提出“畅通工程”的目标:使整个地区任何两个城镇间都可以实现快速交通(但不一定有直接的快速道路相连,只要互相间接通过快速路可达即可). ...

  2. Volley框架原理

    Volley有如下优点: 1. 自动调度网络请求 2. 多并发请求 (源于开了多个线程)3. 本地Cache自动缓存网络请求结果 4. 支持设置请求优先级 5. 支持取消单个请求或者取消所有请求 6. ...

  3. 浅谈XListView的使用

    XListView是github上的开源第三方控件 内部封装好的一个类XListView 其内部包含XListViewFooter XListViewHeader 两个自定义类(控件)如此实现上拉加载 ...

  4. ios 后台发送邮件之SKPSMTPMessage的使用

    skpsmtpmessage 是ios第三方后台发送邮件库 https://github.com/jetseven/skpsmtpmessage.git 1.由于skpsmtpmessage是非ARC ...

  5. golang 常用的正则查找与替换

    package main; import ( "regexp" "fmt" "strings" ) func main() { //1.过正 ...

  6. css让内层div自动撑开外层div

    .clear{clear:both;height:0px;font-size: 1px;line-height: 0px;} <div class="audi_items"& ...

  7. jQuery封装和优化

    封装和优化插件 --封装插件 (function($){ //自定义插件代码 })(jQuery) --------------- (function($){ $.fn.extend({ //函数列表 ...

  8. N! (大数,优化)

    Problem Description 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入 ...

  9. iOS.Crash.Case-[__NSArrayM objectForKeyedSubscript:]

    1. [__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance - source code and s ...

  10. git回退文件修改

    假设git仓库某个文件的提交信息如下: [cxy@localhost-live mate-power-manager]$ git log -n3 SPECS/mate-power-manager.sp ...