dubbo API的使用方式
本文使用maven方式
1:pom文件
<dependencies>
<!-- 引入spring的jar -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.2.RELEASE</version>
</dependency> <!-- 引入zk -->
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.3</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.5</version>
</dependency> <!-- 引入dubbo -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.7</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency> </dependencies>
2:服务端
//服务端的代码
public class DubboServer { public static void main(String[] args) throws IOException {
initServer();
} public static void initServer() throws IOException {
//设置应用名称
ApplicationConfig config = new ApplicationConfig();
config.setName("dubboAppServer"); //连接注册中心
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("192.168.30.128:2181"); //本地虚拟机的地址
registryConfig.setProtocol("zookeeper"); //设置协议
ProtocolConfig protocolConfigRmi = new ProtocolConfig();
protocolConfigRmi.setPort(12880);
protocolConfigRmi.setName("rmi"); //设置rmi的协议 ProtocolConfig protocolConfigDubbo = new ProtocolConfig();
protocolConfigDubbo.setPort(12881);
protocolConfigDubbo.setName("dubbo"); //设置dubbo的协议 //服务提供者暴露服务
ServiceConfig<OrderService> serviceServiceConfig = new ServiceConfig<OrderService>();
serviceServiceConfig.setApplication(config); //设置应用名称
serviceServiceConfig.setRegistry(registryConfig); //设置注册中心
serviceServiceConfig.
setProtocols(Arrays.asList(protocolConfigRmi,protocolConfigDubbo)); //设置两个协议 serviceServiceConfig.setInterface(OrderService.class); //设置接口
serviceServiceConfig.setRef(new OrderServiceImpl()); //设置具体实现类 serviceServiceConfig.export(); //暴露和注册服务 System.in.read(); }
3:消费端
//消费端代码
public class DubboConsumer { public static void main(String[] args) {
initConsumer();
} public static void initConsumer(){
//设置应用名称
ApplicationConfig config = new ApplicationConfig();
config.setName("dubboAppConsumer"); //连接注册中心
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("192.168.30.128:2181"); //本地虚拟机的地址
registryConfig.setProtocol("zookeeper"); ReferenceConfig<OrderService> referenceConfig = new ReferenceConfig<OrderService>();
referenceConfig.setApplication(config);
referenceConfig.setRegistry(registryConfig);
referenceConfig.setInterface(OrderService.class);
referenceConfig.setProtocol("dubbo"); OrderService order = referenceConfig.get();
Integer num = order.buyShop(); //具体的调用
referenceConfig.destroy(); System.out.println(num); }
dubbo API的使用方式的更多相关文章
- 关于RESTFUL API 安全认证方式的一些总结
常用认证方式 在之前的文章REST API 安全设计指南与使用 AngularJS & NodeJS 实现基于 token 的认证应用两篇文章中,[译]web权限验证方法说明中也详细介绍,一般 ...
- 关于 RESTFUL API 安全认证方式的一些总结
常用认证方式 在之前的文章REST API 安全设计指南与使用 AngularJS & NodeJS 实现基于 token 的认证应用两篇文章中,[译]web权限验证方法说明中也详细介绍,一般 ...
- dubbo服务启动的方式
dubbo服务启动的方式: 1.dubbo自带的脚本, 2.直接用main方法启动dubbo的spring容器,参见dubbo-test里的各个例子 3.dubbo的spring boot start ...
- 利用SparkLauncher 类以JAVA API 编程的方式提交Spark job
一.环境说明和使用软件的版本说明: hadoop-version:hadoop-2.9.0.tar.gz spark-version:spark-2.2.0-bin-hadoop2.7.tgz jav ...
- 深入了解Kubernetes REST API的工作方式
关于Kubernetes REST API的工作方式: 在哪里以及如何定义从REST路径到处理REST调用的函数的映射? 与etcd的交互发生在哪里? 从客户端发出请求到保存在etcd中对象的端到端路 ...
- 几种部署Goku API Gateway的方式,最快一分钟可使用上网关
本文将介绍几种部署Goku API Gateway的方式,最快一分钟可使用上为网关,详情请看全文. 什么是Goku API Gateway? Goku API Gateway (中文名:悟空 API ...
- RESTFUL API 安全认证方式
一般基于REST API 安全设计常用方式有: HTTP Basic Basic admin:admin Basic YWRtaW46YWRtaW4= Authorization: Basic YWR ...
- java:struts框架2(方法的动态和静态调用,获取Servlet API三种方式(推荐IOC(控制反转)),拦截器,静态代理和动态代理(Spring AOP))
1.方法的静态和动态调用: struts.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCT ...
- dubbo学习(三)配置dubbo API方式配置
provider(生产者) import com.alibaba.dubbo.config.ApplicationConfig; import com.alibaba.dubbo.config.Pro ...
随机推荐
- 增强篇1 PO保存增强
公众号文章地址:https://mp.weixin.qq.com/s?__biz=Mzg4MzI1OTM0OA==&mid=2247484108&idx=7&sn=90e561 ...
- akka java
https://www.cnblogs.com/lixiang-share/p/5833846.html
- 迅速生成项目-vue-cli-service
推荐指数:
- 【Leetcode_easy】1030. Matrix Cells in Distance Order
problem 1030. Matrix Cells in Distance Order 参考 1. Leetcode_easy_1030. Matrix Cells in Distance Orde ...
- colaboratory安装指定版本的tensorflow
查看当前安装的tensorflow版本 !pip show tensorflow 安装指定版本 !pip install tensorflow==2.0 这速度,香不香.
- GridView取不到值的问题总结
在ASP.NET开发过程中,使用GridView进行数据表现的时候遇到过两次取不到值的问题.分别是初学的时候与 用了一年多以后.出现的问题并不是身边么高深的技术,但是可能会经常遇到,所以这里我做一下总 ...
- Session中清除对象方法比较
转载. https://blog.csdn.net/u014401141/article/details/51816308 Session中清除对象方法比较 http://blog.csdn.ne ...
- C++ enable_if 模板特化实例(函数返回值特化、函数参数特化、模板参数特化、模板重载)
1. enable_if 原理 关于 enable_if 原理这里就不细说了,网上有很多,可以参考如下教程,这里只讲解用法实例,涵盖常规使用全部方法. 文章1 文章2 文章3 1. 所需头文件 #in ...
- python 之 数据库(创建表的完整语法、基本数据类型)
10.4 创建表的完整语法 create table 表名( 字段名1 类型[(宽度) 约束条件], 字段名2 类型[(宽度) 约束条件], 字段名3 类型[(宽度) 约束条件] ); #类型:使用限 ...
- Python socket编程 (2)--实现文件验证登入
可以实现从客户端输入账号和密码然后发送到服务器进行验证,实现用户登入校正操作. 服务器: import socket import json server = socket.socket() serv ...