Dubbo框架的搭建以及入门案例

来源:互联网 发布:我国网络安全形势 编辑:程序博客网 时间:2024/06/05 19:35

1.dubbo的介绍

dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2000+个服务提供3.000.000.000+次访问量的支持,并被广泛应用域阿里巴巴集团的各成员站点。

2.dubbo框架的原理简单介绍

这里写图片描述
1.服务提供方把服务提供到注册中心
2.服务消费方通过注册中心找需要的服务
3.服务消费方通过注册中心运用服务

3.zookepper单机版搭建

1.上传zookeeper压缩包至linux,通过http://dubbo.io 下载压缩包
2.解压 tar -zxvf zookeeper-3.4.6.tar.gz -c/
3.在解压文件夹zookeeper-3.4.6中创建data、logs两个文件夹
4.配置zoo.cfg
cp zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg
vim zookeeper-3.4.6/conf/zoo.cfg
修改此处
5.进入到zookeeper-3.4.6/bin目录启动
./zkServer.sh start

4.dubbo搭建

1.服务提供方搭建

<beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"    xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    xsi:schemaLocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd         http://www.springframework.org/schema/mvc         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd         http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-4.0.xsd         http://www.springframework.org/schema/aop         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd         http://www.springframework.org/schema/tx         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd        http://www.springframework.org/schema/task        http://www.springframework.org/schema/task/spring-task-4.0.xsd        http://code.alibabatech.com/schema/dubbo                http://code.alibabatech.com/schema/dubbo/dubbo.xsd">    <!-- 服务提供方 -->    <!-- 1:此服务启个名称 -->    <dubbo:application name="shopping-service-product" />    <!-- 2:连接zookeeper  redis -->    <dubbo:registry address="192.168.9.129:2181" protocol="zookeeper" />    <!-- 3:配置暴露给注册中心的 ip  port  默认20880 -->    <dubbo:provider host="127.0.0.1" port="20880" />    <!-- 4:配置暴露 接口 -->    <dubbo:service interface="open.shopping.service.TestUserService" ref="testUserServiceImpl" /></beans>

2.服务消费方搭建

<beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"    xmlns:context="http://www.springframework.org/schema/context"    xmlns:aop="http://www.springframework.org/schema/aop"     xmlns:tx="http://www.springframework.org/schema/tx"    xmlns:task="http://www.springframework.org/schema/task"    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"    xsi:schemaLocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd         http://www.springframework.org/schema/mvc         http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd         http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-4.0.xsd         http://www.springframework.org/schema/aop         http://www.springframework.org/schema/aop/spring-aop-4.0.xsd         http://www.springframework.org/schema/tx         http://www.springframework.org/schema/tx/spring-tx-4.0.xsd        http://www.springframework.org/schema/task        http://www.springframework.org/schema/task/spring-task-4.0.xsd        http://code.alibabatech.com/schema/dubbo                http://code.alibabatech.com/schema/dubbo/dubbo.xsd">    <!-- 服务消费方 -->    <!-- 1:此服务启个名称 -->    <dubbo:application name="shopping-web-console"/>    <!-- 2:连接zookeeper  redis -->    <dubbo:registry address="192.168.200.128:2181" protocol="zookeeper"/>    <!-- 3:配置 获取 接口 -->    <dubbo:reference interface="open.shopping.service.TestUserService" id="testUserServiceImpl" /></beans>

3.注意事项
使用Dubbo框架、服务提供方与服务消费方之传递的参数必须实现序列化接口

原创粉丝点击