Dubbo之消费者
2024-09-07 12:00:58
在写 dubbbo调用时候
<dubbo:reference 不能有空格!
项目结构:
pom:
<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>
<parent>
<groupId>com.toov5</groupId>
<artifactId>toov5-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>toov5-order-dubbo-service</artifactId> <dependencies>
<dependency>
<groupId>com.toov5</groupId>
<artifactId>toov5-member-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency> <dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.5.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </project>
业务:
package com.toov5.dubbo.consumer; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.toov5.api.member.service.MemberService; public class OderToMemberTest {
public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("dubbo-consumer.xml");
MemberService memberService = applicationContext.getBean(MemberService.class);
String resultUser = memberService.getUser(12L);
System.out.println("调用服务后的返回结果"+resultUser);
}
}
dubbo配置
<?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-admin 或 dubbo-monitor 会显示这个名字,方便辨识 -->
<dubbo:application name="demotest-consumer" />
<!--使用 zookeeper 注册中心暴露服务,注意要先开启 zookeeper -->
<dubbo:registry address="zookeeper://192.168.91.5:2181" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!--使用 dubbo 协议实现定义好的 MemberService 接口 -->
<dubbo:reference id="memberService" interface="com.toov5.api.member.service.MemberService"/>
</beans>
启动:
只引入了接口 没有实现。 实现都是通过底层转换成rpc dubbo协议进行调用的
最新文章
- 以项目谈WebGIS中Web制图的设计和实现
- 菜鸟学JS(五)——window.onload与$(document).ready()
- 一。常用UIView的属性和方法
- 实现JavaScript自定义函数的整合、链式调用及类的封装
- java读取properties配置文件的方法
- shell 实例收集
- fil_space_t
- Python中,如何初始化不同的变量类型为空值
- c++继承构造子类调用父类构造函数的问题及关于容器指针的问题及当容器里储存指针时,记得要手动释放
- C语言 &#183; 区间K大数查询
- children
- UVALive 2517	Moving Object Recognition(模拟)
- Spring详解(二)------IOC控制反转
- 好的Qt学习资料
- web安全之机器学习入门——2.机器学习概述
- 微信小程序:一起玩连线,一个算法来搞定
- Windows平台上谷歌浏览器损害电池
- (转)MySQL优化笔记(八)--锁机制超详细解析(锁分类、事务并发、引擎并发控制)
- Android JUnit 入门指南
- win10自带虚拟机安装CentOS7系统(转)