dubbo入门
来源:互联网 发布:拓展人脉的软件 编辑:程序博客网 时间:2024/06/06 11:02
Dubbo架构:
服务注册中心使用zookeeper,部署在Linux(192.168.80.129)上。
Maven pom.xml文件:
<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.zzj</groupId> <artifactId>dubble</artifactId> <version>0.0.1</version> <packaging>jar</packaging> <name>dubble</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>2.5.5</version></dependency><dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.3</version></dependency> </dependencies></project>
服务接口类:
package com.zzj.dubble.demo;public interface DemoService {String sayHello(String name);}
接口实现类:
package com.zzj.dubble.demo.provider;import com.zzj.dubble.demo.DemoService;public class DemoServiceImpl implements DemoService {public String sayHello(String name) { return "Hello " + name; }}
Dobbo提供者:
package com.zzj.dubble;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * Hello world! * */public class Provider {public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] {"classpath:dubbo-demo-provider.xml"}); context.start(); System.out.println("Dubbo provider started!"); System.in.read(); // press any key to exit System.out.println("exit!"); }}
提供者配置文件:
<?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="demo-provider"/> <dubbo:registry protocol="zookeeper" address="192.168.80.129:2181" /> <!-- 默认协议端口20880 --> <!-- <dubbo:protocol name="dubbo" port="20880"/> --> <dubbo:service interface="com.zzj.dubble.demo.DemoService" ref="demoService"/> <bean id="demoService" class="com.zzj.dubble.demo.provider.DemoServiceImpl"/></beans>Dubbo消费者:
package com.zzj.dubble;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.zzj.dubble.demo.DemoService;public class Consumer {public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[]{"classpath:dubbo-demo-consumer.xml"}); context.start(); DemoService demoService = (DemoService) context.getBean("demoService"); // obtain proxy object for remote invocation String hello = demoService.sayHello("world"); // execute remote invocation System.out.println(hello); // show the result context.close(); }}
消费者配置文件:
<?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="demo-consumer"/> <dubbo:registry protocol="zookeeper" address="192.168.80.129:2181" /> <dubbo:reference id="demoService" interface="com.zzj.dubble.demo.DemoService"/></beans>启动提供者:
Dubbo provider started!运行消费者:
Hello world
阅读全文
0 0
- [dubbo入门] dubbo入门
- Dubbo入门
- dubbo入门
- dubbo入门
- Dubbo入门
- Dubbo入门
- dubbo入门
- Dubbo入门
- dubbo入门
- Dubbo入门
- dubbo入门
- Dubbo入门
- dubbo入门
- Dubbo入门
- Dubbo入门
- dubbo 入门
- Dubbo入门
- Dubbo入门
- C++中的多态
- mybatis和hibernate的区别
- 剑指offer:按之字形顺序打印二叉树
- 用小说的形式讲解Spring(2) —— 注入方式哪家强
- Linux Shell学习
- dubbo入门
- 常见数据类型的克隆(内含对象的深度克隆)
- wsdl加入header部分
- textview加矩形边框和圆角边框
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Minimum Distance in a Star Graph
- mybatis的动态SQL(一)if标签的使用
- 数据库中的事务隔离级别和锁的关系
- 如何设置USB为第一引导
- 前端loading