当前位置: 首页 > news >正文

网站免费站建筑图纸怎么学看图

网站免费站,建筑图纸怎么学看图,预测2025年网络营销的发展,如何开通微信公众号平台转载自 Dubbo 融合 Nacos 成为注册中心 Nacos 作为 Dubbo 生态系统中重要的注册中心实现#xff0c;本文将会介绍如何进行 Dubbo 对接 Nacos 注册中心的工作。 预备工作 请确保后台已经启动 Nacos 服务#xff0c;可先行参考 Nacos 快速入门。 快速上手 Dubbo 融合 Nac…转载自  Dubbo 融合 Nacos 成为注册中心 Nacos 作为 Dubbo 生态系统中重要的注册中心实现本文将会介绍如何进行 Dubbo 对接 Nacos 注册中心的工作。 预备工作 请确保后台已经启动 Nacos 服务可先行参考 Nacos 快速入门。 快速上手 Dubbo 融合 Nacos 成为注册中心的操作步骤非常简单大致步骤可分为“增加 Maven 依赖”以及“配置注册中心“。 增加 Maven 依赖 只需要依赖Dubbo客户端即可关于推荐的使用版本请参考Dubbo官方文档或者咨询Dubbo开发人员 dependencies...!-- Dubbo dependency --dependencygroupIdcom.alibaba/groupIdartifactIddubbo/artifactIdversion[latest version]/version/dependency!-- 使用Spring装配方式时可选: --dependencygroupIdcom.alibaba.spring/groupIdartifactIdspring-context-support/artifactIdversion[latest version]/version/dependency.../dependencies配置注册中心 假设您 Dubbo 应用使用 Spring Framework 装配将有两种配置方法可选分别为Dubbo Spring 外部化配置以及 Spring XML 配置文件以及笔者强烈推荐前者。 Dubbo Spring 外部化配置 Dubbo Spring 外部化配置是由 Dubbo 2.5.8 引入的新特性可通过 Spring Environment 属性自动地生成并绑定 Dubbo 配置 Bean实现配置简化并且降低微服务开发门槛。 假设您 Dubbo 应用的使用 Zookeeper 作为注册中心并且其服务器 IP 地址为10.20.153.10同时该注册地址作为 Dubbo 外部化配置属性存储在 dubbo-config.properties 文件如下所示 ## application dubbo.application.name your-dubbo-application## Zookeeper registry address dubbo.registry.address zookeeper://10.20.153.10:2181 ...假设您的 Nacos Server 同样运行在服务器 10.20.153.10 上并使用默认 Nacos 服务端口 8848您只需将 dubbo.registry.address 属性调整如下 ## 其他属性保持不变## Nacos registry address dubbo.registry.address nacos://10.20.153.10:8848 ##如果要使用自己创建的命名空间可以使用下面2种方式 #dubbo.registry.address nacos://10.20.153.10:8848?namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 #dubbo.registry.parameters.namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 ...随后重启您的 Dubbo 应用Dubbo 的服务提供和消费信息在 Nacos 控制台中可以显示 如图所示服务名前缀为 providers: 的信息为服务提供者的元信息consumers: 则代表服务消费者的元信息。点击“详情”可查看服务状态详情 如果您正在使用 Spring XML 配置文件装配 Dubbo 注册中心的话请参考下一节。 Spring XML 配置文件 同样假设您 Dubbo 应用的使用 Zookeeper 作为注册中心并且其服务器 IP 地址为10.20.153.10并且装配 Spring Bean 在 XML 文件中如下所示 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:dubbohttp://dubbo.apache.org/schema/dubboxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd!-- 提供方应用信息用于计算依赖关系 --dubbo:application namedubbo-provider-xml-demo /!-- 使用 Zookeeper 注册中心 --dubbo:registry addresszookeeper://10.20.153.10:2181 /... /beans与 Dubbo Spring 外部化配置 配置类似只需要调整 address 属性配置即可 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:dubbohttp://dubbo.apache.org/schema/dubboxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd!-- 提供方应用信息用于计算依赖关系 --dubbo:application namedubbo-provider-xml-demo /!-- 使用 Nacos 注册中心 --dubbo:registry addressnacos://10.20.153.10:8848 /!-- 如果要使用自己创建的命名空间可以使用下面配置 --!-- dubbo:registry addressnacos://10.20.153.10:8848?namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 / --... /beans重启 Dubbo 应用后您同样也能发现服务提供方和消费方的注册元信息呈现在 Nacos 控制台中 您是否绝对配置或切换 Nacos 注册中心超级 Easy 呢如果您仍旧意犹未尽或者不甚明白的话可参考以下完整的示例。 完整示例 以上图片中的元数据源于 Dubbo Spring 注解驱动示例以及 Dubbo Spring XML 配置驱动示例下面将分别介绍两者您可以选择自己偏好的编程模型。在正式讨论之前先来介绍两者的预备工作因为它们皆依赖 Java 服务接口和实现。同时请确保本地127.0.0.1环境已启动 Nacos 服务。 示例接口与实现 首先定义示例接口如下所示 package com.alibaba.dubbo.demo.service;/*** DemoService** since 2.6.5*/ public interface DemoService {String sayName(String name);}提供以上接口的实现类 package com.alibaba.dubbo.demo.service;import com.alibaba.dubbo.config.annotation.Service; import com.alibaba.dubbo.rpc.RpcContext;import org.springframework.beans.factory.annotation.Value;/*** Default {link DemoService}** since 2.6.5*/ Service(version ${demo.service.version}) public class DefaultService implements DemoService {Value(${demo.service.name})private String serviceName;public String sayName(String name) {RpcContext rpcContext RpcContext.getContext();return String.format(Service [name :%s , port : %d] %s(\%s\) : Hello,%s,serviceName,rpcContext.getLocalPort(),rpcContext.getMethodName(),name,name);} }接口与实现准备妥当后下面将采用注解驱动和 XML 配置驱动各自实现。 Spring 注解驱动示例 Dubbo 2.5.7 重构了 Spring 注解驱动的编程模型。 服务提供方注解驱动实现 定义 Dubbo 提供方外部化配置属性源 - provider-config.properties ## application dubbo.application.name dubbo-provider-demo## Nacos registry address dubbo.registry.address nacos://127.0.0.1:8848 ##如果要使用自己创建的命名空间可以使用下面2种方式 #dubbo.registry.address nacos://127.0.0.1:8848?namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 #dubbo.registry.parameters.namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932## Dubbo Protocol dubbo.protocol.name dubbo dubbo.protocol.port -1# Provider Service version demo.service.version1.0.0 demo.service.name demoService实现服务提供方引导类 - DemoServiceProviderBootstrap package com.alibaba.dubbo.demo.provider;import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; import com.alibaba.dubbo.demo.service.DemoService;import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource;import java.io.IOException;/*** {link DemoService} provider demo*/ EnableDubbo(scanBasePackages com.alibaba.dubbo.demo.service) PropertySource(value classpath:/provider-config.properties) public class DemoServiceProviderBootstrap {public static void main(String[] args) throws IOException {AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext();context.register(DemoServiceProviderBootstrap.class);context.refresh();System.out.println(DemoService provider is starting...);System.in.read();} } 其中注解 EnableDubbo 激活 Dubbo 注解驱动以及外部化配置其 scanBasePackages 属性扫描指定 Java 包将所有标注 Service 的服务接口实现类暴露为 Spring Bean随即被导出 Dubbo 服务。 PropertySource 是 Spring Framework 3.1 引入的标准导入属性配置资源注解它将为 Dubbo 提供外部化配置。 服务消费方注解驱动实现 定义 Dubbo 消费方外部化配置属性源 - consumer-config.properties ## Dubbo Application info dubbo.application.name dubbo-consumer-demo## Nacos registry address dubbo.registry.address nacos://127.0.0.1:8848 ##如果要使用自己创建的命名空间可以使用下面2种方式 #dubbo.registry.address nacos://127.0.0.1:8848?namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 #dubbo.registry.parameters.namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932# Reference version demo.service.version 1.0.0同样地dubbo.registry.address 属性指向 Nacos 注册中心其他 Dubbo 服务相关的元信息通过 Nacos 注册中心获取。 实现服务消费方引导类 - DemoServiceConsumerBootstrap package com.alibaba.dubbo.demo.consumer;import com.alibaba.dubbo.config.annotation.Reference; import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; import com.alibaba.dubbo.demo.service.DemoService;import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource;import javax.annotation.PostConstruct; import java.io.IOException;/*** {link DemoService} consumer demo*/ EnableDubbo PropertySource(value classpath:/consumer-config.properties) public class DemoServiceConsumerBootstrap {Reference(version ${demo.service.version})private DemoService demoService;PostConstructpublic void init() {for (int i 0; i 10; i) {System.out.println(demoService.sayName(小马哥mercyblitz));}}public static void main(String[] args) throws IOException {AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext();context.register(DemoServiceConsumerBootstrap.class);context.refresh();context.close();} } 同样地EnableDubbo 注解激活 Dubbo 注解驱动和外部化配置不过当前属于服务消费者无需指定 Java 包名扫描标注 Service 的服务实现。 Reference 是 Dubbo 远程服务的依赖注入注解需要服务提供方和消费端约定接口interface、版本version以及分组group信息。在当前服务消费示例中DemoService 的服务版本来源于属性配置文件 consumer-config.properties。 PostConstruct 部分代码则说明当 DemoServiceConsumerBootstrap Bean 初始化时执行十次 Dubbo 远程方法调用。 运行注解驱动示例 在本地启动两次 DemoServiceProviderBootstrap注册中心将出现两个健康服务 再运行 DemoServiceConsumerBootstrap运行结果如下 Service [name :demoService , port : 20880] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20881] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20880] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20880] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20881] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20881] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20880] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20880] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20881] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :demoService , port : 20881] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz运行无误并且服务消费方使用了负载均衡策略将十次 RPC 调用平均分摊到两个 Dubbo 服务提供方实例中。 Spring XML 配置驱动示例 Spring XML 配置驱动是传统 Spring 装配组件的编程模型。 服务提供方 XML 配置驱动 定义服务提供方 XML 上下文配置文件 - /META-INF/spring/dubbo-provider-context.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:dubbohttp://dubbo.apache.org/schema/dubboxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd!-- 提供方应用信息用于计算依赖关系 --dubbo:application namedubbo-provider-xml-demo/!-- 使用 Nacos 注册中心 --dubbo:registry addressnacos://127.0.0.1:8848/!-- 如果要使用自己创建的命名空间可以使用下面配置 --!-- dubbo:registry addressnacos://127.0.0.1:8848?namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 / --!-- 用dubbo协议在随机端口暴露服务 --dubbo:protocol namedubbo port-1/!-- 声明需要暴露的服务接口 --dubbo:service interfacecom.alibaba.dubbo.demo.service.DemoService refdemoService version2.0.0/!-- 和本地bean一样实现服务 --bean iddemoService classcom.alibaba.dubbo.demo.service.DefaultService/ /beans实现服务提供方引导类 - DemoServiceProviderXmlBootstrap package com.alibaba.dubbo.demo.provider;import com.alibaba.dubbo.demo.service.DemoService;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.io.IOException;/*** {link DemoService} provider demo XML bootstrap*/ public class DemoServiceProviderXmlBootstrap {public static void main(String[] args) throws IOException {ClassPathXmlApplicationContext context new ClassPathXmlApplicationContext();context.setConfigLocation(/META-INF/spring/dubbo-provider-context.xml);context.refresh();System.out.println(DemoService provider (XML) is starting...);System.in.read();} }服务消费方 XML 配置驱动 定义服务消费方 XML 上下文配置文件 - /META-INF/spring/dubbo-consumer-context.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:dubbohttp://dubbo.apache.org/schema/dubboxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd!-- 提供方应用信息用于计算依赖关系 --dubbo:application namedubbo-consumer-xml-demo/!-- 使用 Nacos 注册中心 --dubbo:registry addressnacos://127.0.0.1:8848/!-- 如果要使用自己创建的命名空间可以使用下面配置 --!-- dubbo:registry addressnacos://127.0.0.1:8848?namespace5cbb70a5-xxx-xxx-xxx-d43479ae0932 / --!-- 引用服务接口 --dubbo:reference iddemoService interfacecom.alibaba.dubbo.demo.service.DemoService version2.0.0//beans实现服务消费方引导类 - DemoServiceConsumerXmlBootstrap package com.alibaba.dubbo.demo.consumer;import com.alibaba.dubbo.demo.service.DemoService;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.io.IOException;/*** {link DemoService} consumer demo XML bootstrap*/ public class DemoServiceConsumerXmlBootstrap {public static void main(String[] args) throws IOException {ClassPathXmlApplicationContext context new ClassPathXmlApplicationContext();context.setConfigLocation(/META-INF/spring/dubbo-consumer-context.xml);context.refresh();System.out.println(DemoService consumer (XML) is starting...);DemoService demoService context.getBean(demoService, DemoService.class);for (int i 0; i 10; i) {System.out.println(demoService.sayName(小马哥mercyblitz));}context.close();} }运行 XML 配置驱动示例 同样地先启动两个 DemoServiceProviderXmlBootstrap 引导类观察 Nacos 注册中心服务提供者变化 XML 配置驱动的服务版本为 2.0.0因此注册服务无误。 再运行服务消费者引导类 DemoServiceConsumerXmlBootstrap观察控制台输出内容 Service [name :null , port : 20882] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20882] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20883] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20882] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20882] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20883] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20882] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20883] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20883] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz Service [name :null , port : 20883] sayName(小马哥mercyblitz) : Hello,小马哥mercyblitz结果同样运行和负载均衡正常不过由于当前示例尚未添加属性 demo.service.name 的缘故因此“name”部分信息输出为 null。 如果您关注或喜爱 Dubbo 以及 Nacos 等开源工程不妨为它们点 “star”加油打气链接 Apache Dubbohttps://github.com/apache/dubboDubbo Nacos Registryhttps://github.com/apache/dubbo/tree/master/dubbo-registry/dubbo-registry-nacosAlibaba Nacoshttps://github.com/alibaba/nacos
http://www.zqtcl.cn/news/258369/

相关文章:

  • 网站数据分析案例怎样在网上做广告
  • 网站页头图片怎么做几个版面的网站
  • 网站 f型网站建设 大公司
  • 做网站最好选什么语言百度域名服务器
  • 网站维护一般多久西宁的网站建设
  • 网站建设需要什么工具投诉百度最有效的电话
  • 做家政网站公司策划公司英文
  • 自己建设个人网站要花费多少自己怎么制作微信网页链接
  • 邢台网站设计哪家专业php图书管理系统网站开发
  • 怎么去建一个网站艺术设计专业
  • 中国优秀设计网站有哪些内容万能影视免费观看app
  • 网站做响应式还是移动端广告创意设计模板
  • 企业网站建设的要求标准营销型网站定做价格
  • 兰溪优秀高端网站设计郑州正规网站制作公司
  • 霸气业务网站源码网站建设运营服务公司
  • 做seo对网站推广有什么作用网站开发程序流程图
  • 旅游网站怎么建设网站开发+搜索
  • 三分钟做网站传统企业建设营销型网站
  • 必须在当地网站备案化妆品做备案的网站
  • 网站建设7个主要流程图创建全国文明城市工作要求
  • 张店网站开发招聘怎样做网站变手机软件
  • 聊城做网站的公司流程网页设计网站模板
  • 宿迁网站建设哪家专业做网站宁夏
  • 静态网站规范贵州城乡建设厅施工员报名网站
  • 湖北长安建设集团股份有限公司网站wordpress主题套用
  • 本地门户网站系统小米应用商店
  • 网站建设怎么用宁波建设网网点
  • 购物网站二级页面模板国家企业信用公示信息系统官网app
  • tp框架做餐饮网站快速建站教程网
  • php自己做网站wordpress下拉刷新