hsf dubbo学习四--连接方式
来源:互联网 发布:2017 seo教程百度云 编辑:程序博客网 时间:2024/06/14 13:55
直连提供者
在开发及测试环境下,经常需要绕过注册中心,只测试指定服务提供者,这时可能需要点对点直连。
(1)如果是线上需求需要点对点,可在<dubbo:reference>中配置url指向提供者,将绕过注册中心,多个地址用分号隔开。
(2)在JVM启动参数中加入-D参数映射服务地址(key为服务名,value为服务提供者url,此配置优先级最高)
(3)发果服务比较多,也可以用文件映射(用-Ddubbo.resolve.file指定映射文件路径,此配置优先级高于<dubbo:reference>中的配置)
只订阅
可以让服务提供者开发方,只订阅服务,而不注册正在开发的服务,通过直连测试正在开发的服务。
禁用注册配置:
<dubbo:registry address="10.20.153.10:9090" register="false" />
或者
<dubbo:regisytry address="10.20.154.10:9090?register=false" />
只注册
可以让服务提供者,只注册服务到另一注册中心,而不从另一注册中心订阅服务。
禁用订阅配置:
<dubbo:registry id="qdRegistry" address="10.20.141.150:9090" subscribe="false" />
或者
dubbo:registry id="qdRegistry" address="10.20.141.150:9090?subscribe=false" />
静态服务
有时候希望人工管理服务提供者的上线和下线,此时需要将注册中心标识为动态管理模式。
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();Registry registry = registryFactory.getRegistry(URL.valueOf("zookeeper://10.20.153.10:2181"));registry.register(URL.valueOf("memcached://10.20.153.11/com.foo.BarService?category=providers&dynamic=false&application=foo"));
服务提供者初次注册时为禁用状态,需要工启用,断线时,将不会被自动删除,需人工禁用。
多协议
(1)不同服务不同协议
比如:不同服务在性能上适用不同协议进行传输
provider.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="world" /> <dubbo:registry id="registry" address="10.20.141.150:9090" username="admin" password="hello1234" /> <!-- 多协议配置 --> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:protocol name="rmi" port="1099" /> <!-- 使用dubbo协议暴露服务 --> <dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" protocol="dubbo" /> <!-- 使用rmi协议暴露服务 --> <dubbo:service interface="com.alibaba.hello.api.DemoService" version="1.0.0" ref="demoService" protocol="rmi" /> </beans>
(2)多协议暴露服务
provider.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="world" /> <dubbo:registry id="registry" address="10.20.141.150:9090" username="admin" password="hello1234" /> <!-- 多协议配置 --> <dubbo:protocol name="dubbo" port="20880" /> <dubbo:protocol name="hessian" port="8080" /> <!-- 使用多个协议暴露服务 --> <dubbo:service id="helloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" protocol="dubbo,hessian" /> </beans>
多注册中心
(1)多注册中注册
provider.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="world" /> <!-- 多注册中心配置 --> <dubbo:registry id="hangzhouRegistry" address="10.20.141.150:9090" /> <dubbo:registry id="qingdaoRegistry" address="10.20.141.151:9010" default="false" /> <!-- 向多个注册中心注册 --><dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="hangzhouRegistry,qingdaoRegistry" /> </beans>
(2)不同服务使用不同注册中心
provider.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="world" /> <!-- 多注册中心配置 --> <dubbo:registry id="chinaRegistry" address="10.20.141.150:9090" /> <dubbo:registry id="intlRegistry" address="10.20.154.177:9010" default="false" /> <!-- 向中文站注册中心注册 --><dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" registry="chinaRegistry" /> <!-- 向国际站注册中心注册 --> <dubbo:service interface="com.alibaba.hello.api.DemoService" version="1.0.0" ref="demoService" registry="intlRegistry" /> </beans>
(3)多注册中心引用
consumer.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="world" /> <!-- 多注册中心配置 --> <dubbo:registry id="chinaRegistry" address="10.20.141.150:9090" /> <dubbo:registry id="intlRegistry" address="10.20.154.177:9010" default="false" /> <!-- 引用中文站服务 --><dubbo:reference id="chinaHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="chinaRegistry" /> <!-- 引用国际站站服务 --><dubbo:reference id="intlHelloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" registry="intlRegistry" /> </beans>
- hsf dubbo学习四--连接方式
- 分布式服务框架HSF学习 Dubbo VS HSF
- hsf dubbo学习八--延迟连接,粘滞连接,令牌验证,路由规则
- hsf开源dubbo学习-2-配置
- hsf开源dubbo学习-1-服务提供者&服务消费者&依赖
- hsf开源dubbo学习三--集群,线程模型
- hsf dubbo学习九--服务降级,优雅停机,日志
- HSF学习
- HSF和dubbo的区别
- hsf dubbo学习五--服务分组,多版本,参数验证,结果缓存
- hsf dubbo学习六--泛化,回声测试,上下文信息,隐式传参,异步调用,本地调用
- hsf dubbo学习七--参数回调,本地存根,延迟暴露,并发控制
- dubbo&hsf&spring-cloud简单介绍
- dubbo&hsf&spring-cloud简单介绍
- HSF和Dubbo有什么区别
- HSF和Dubbo有什么区别
- Dubbo学习(四):集群容错
- Dubbo学习(四)服务分组
- clang token def
- MySQL5.6 数据库主从(Master/Slave)同步安装与配置详解
- tomcat+nginx搭建服务器负载均衡集群
- <转>Spark机器学习6·聚类模型
- 四道Java经典基础题
- hsf dubbo学习四--连接方式
- java的static块执行时机
- <转>Spark的调度策略详解
- 解决Retrofit文件下载进度显示问题
- 二叉搜索树与双向链表
- Swift - 第三方日历组件CVCalendar使用详解1(配置、基本用法)
- iOS开发权限
- 通向架构师的道路(第四天)之Tomcat性能调优-让小猫飞奔
- 我的第一篇博客