dubbo框架搭建
来源:互联网 发布:免费微信一键转发软件 编辑:程序博客网 时间:2024/05/24 06:27
dubbo官网:http://dubbo.io/
源码地址:https://github.com/jxq0816/dubbo_demo
一、dubbo项目组织结构
二、编码
1、dubbo-demo
pom.xml
<?xml version="1.0" encoding="UTF-8"?><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.weeking</groupId> <artifactId>dubbo-demo</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>dubbo-server</module> <module>dubbo-client</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.6.RELEASE</version> </dependency> <!-- dubbo begin --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.3</version> </dependency> <!-- dubbo end --> <!-- 注册中心zookeeper begin --> <!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.5.3-beta</version> <type>pom</type> </dependency> <!--A zookeeper client, that makes life a little easier.--> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.8</version> </dependency> </dependencies> </dependencyManagement></project>
2. dubbo-server
① pom.xml
<?xml version="1.0" encoding="UTF-8"?><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>dubbo</groupId> <artifactId>dubbo-server</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>com.weeking</groupId> <artifactId>dubbo-demo</artifactId> <version>1.0-SNAPSHOT</version> </parent> <dependencies> <!-- spring begin --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <!-- spring end --> <!-- dubbo begin --> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> </dependency> <!-- dubbo end --> <!-- 注册中心zookeeper begin --> <!-- https://mvnrepository.com/artifact/org.apache.zookeeper/zookeeper --> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <type>pom</type> </dependency> <!-- 注册中心zookeeper end --> <!-- The Netty project is an effort to provide an asynchronous event-driven network application framework and tools for rapid development of maintainable high performance and high scalability protocol servers and clients. In other words, Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket server. --> <dependency> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> <version>3.2.0.Final</version> </dependency> <!--A zookeeper client, that makes life a little easier.--> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> </dependency> </dependencies></project>
② ServerMain
package com.jxq.main;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.io.IOException;/** * Created by jiangxingqi on 2017/2/8. */public class ServerMain { public static void main(String[] args) throws IOException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationProvider.xml" }); context.start(); System.out.println("输入任意按键退出 ~ "); System.in.read(); context.close(); }}③ DubboService
package com.jxq.service;/** * Created by jiangxingqi on 2017/2/8. */public interface DubboService { String sayHello(String name);}
④DubboServiceImpl
package com.jxq.service.impl;import com.jxq.service.DubboService;/** * Created by jiangxingqi on 2017/2/8. */public class DubboServiceImpl implements DubboService { public String sayHello(String name) { System.out.println("init : " + name); return "hello " + name; }}
⑤ 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 "> <dubbo:application name="dubbo-demo" /> <!-- zookeeper注册中心 --> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <dubbo:protocol name="dubbo" port="20880" /> <!-- 和本地bean一样实现服务 --> <bean id="demoService" class="com.jxq.service.impl.DubboServiceImpl" /> <!-- 向注册中心注册暴漏服务地址,注册服务 --> <dubbo:service interface="com.jxq.service.DubboService" ref="demoService" executes="10" /></beans>
3. dubbo-client
①ClientMain
package com.jxq.service;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * Created by jiangxingqi on 2017/2/8. */public class ClientMain { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "applicationConsumer.xml" }); context.start(); DubboService service = (DubboService) context.getBean("demoService"); System.out.println(service.sayHello("world")); context.close(); }}
②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="consumer-of-dubbo-demo" /> <dubbo:registry address="zookeeper://127.0.0.1:2181" /> <!-- 向注册中心订阅服务 --> <dubbo:reference id="demoService" interface="com.jxq.service.DubboService" /></beans>
二、联调
启动zookeep
consumer请求server所提供的sayHello接口
1、run ServerMain 启动服务提供方
2、run ClientMain 启动消费方
阅读全文
0 0
- dubbo框架搭建
- dubbo框架搭建
- dubbo框架及dubbo环境搭建
- spring maven 搭建dubbo框架(dubbo-admin)
- dubbo框架及dubbo环境搭建
- Dubbo框架搭建通用接口
- maven搭建Dubbo框架服务
- Spring+Dubbo+Zookeeper框架搭建--<二>Dubbo-admin安装
- 分布式服务框架 dubbo/dubbox 的搭建
- spring maven 搭建dubbo框架 (准备工作)
- spring maven 搭建dubbo框架 服务端
- spring maven 搭建dubbo框架 消费端
- dubbo框架学习(一)-搭建开发环境
- Dubbo框架的搭建以及入门案例
- 【Java】Dubbo+zookeeper搭建分布式服务框架
- Idea 简易搭建dubbo+zookeeper分布式框架
- 分布式服务框架DUBBO(二)搭建dubbo服务-zookeeper与dubbo-admin的安装
- dubbo搭建
- 【c语言】利用库函数进行快速排序(升)
- RUP与设计模式
- JSP的指令元素的概述;Page指令包含的属性Taglib指令JSP的指令-include和taglib指令
- 领域驱动视频(四)
- Hadoop性能调优
- dubbo框架搭建
- 关于《Yann LeCun:已解决CIFAR-10,目标 ImageNet》采访的总结
- Linux shell echo与printf
- linux 下一些命令
- Fabric 远端 批量部署
- springmvc@ModelAttribute注解
- Android:ListView之ViewHolder
- 无人机驾驶员培训学习记录(十五)
- JAVA 并发编程