微服务架构近年来非常的火,阿里 的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. 网络编程Socket知识点回复

    Socket又称“套接字”,应用程序通常通过“套接字”向网络发出请求或者应答网络请求. Socket和ServerSocket类库位置java.net包中,ServerSocket用于服务器端,Soc ...

  2. ngular ionic select ng-options 默认选择第一个值的写法

    1. html <select ng-model="selectOrderState" style="border:none;left:0" ng-opt ...

  3. 【python】入门指南:控制语句

    条件控制 if,if-else,if-elseif-else #!/bin/python a = 'test' if a == 'test': print('a is %s' %(a)) else: ...

  4. ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

  5. HBase数据库集群配置【转】

    https://www.cnblogs.com/ejiyuan/p/5591613.html HBase简介 HBase是Apache Hadoop中的一个子项目,是一个HBase是一个开源的.分布式 ...

  6. Pyqt5的事例讲解

    1.第一个gui程序 import sys from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QMainWind ...

  7. xadmin系列之启动、注册、分发

    a.启动首先要加载settings中定义的INSTALLED_APPS列表中的app b.我们进入xadmin的XadminConfig文件 from django.apps import AppCo ...

  8. java_15 System类

    1.System类 2.System类方法 (1)currentTimeMillis() public static void main(String[] args) { long start = S ...

  9. Python爬虫项目--爬取某宝男装信息

    本次爬取用到的知识点有: 1. selenium 2. pymysql 3  pyquery 正文 1. 分析目标网站 1. 打开某宝首页, 输入"男装"后点击"搜索&q ...

  10. three.map.control

    网址:https://github.com/anvaka/three.map.control 在threejs群里发现的一个很有意思的问题之前没有接触过: 存在的问题:  我在微信小游戏中,用orbi ...