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

php建网站百度趋势搜索

php建网站,百度趋势搜索,做的网站怎么让百度收索时搜,受欢迎的模板网站建设快速上手 Dubbo 融合 Nacos 成为注册中心的操作步骤非常简单#xff0c;大致步骤可分为“增加 Maven 依赖”以及“配置注册中心“。 增加 Maven 依赖 只需要依赖Dubbo客户端即可#xff0c;关于推荐的使用版本#xff0c;请参考Dubbo官方文档或者咨询Dubbo开发人员#…快速上手 Dubbo 融合 Nacos 成为注册中心的操作步骤非常简单大致步骤可分为“增加 Maven 依赖”以及“配置注册中心“。 增加 Maven 依赖 只需要依赖Dubbo客户端即可关于推荐的使用版本请参考Dubbo官方文档或者咨询Dubbo开发人员 dependencies...dependencygroupIdcom.alibaba/groupIdartifactIddubbo/artifactIdversion3.0.5/version/dependency!-- Dubbo Nacos registry dependency --dependencygroupIdcom.alibaba/groupIdartifactIddubbo-registry-nacos/artifactIdversion3.0.5/version/dependency!-- Alibaba Spring Context extension --dependencygroupIdcom.alibaba.spring/groupIdartifactIdspring-context-support/artifactIdversion1.0.11/version/dependency.../dependencies配置注册中心 假设您 Dubbo 应用使用 Spring Framework 装配将有两种配置方法可选分别为Dubbo Spring 外部化配置以及 Spring XML 配置文件以及笔者强烈推荐前者。 Dubbo Spring 外部化配置 Dubbo Spring 外部化配置是由 Dubbo 2.5.8 引入的新特性可通过 Spring Environment 属性自动地生成并绑定 Dubbo 配置 Bean实现配置简化并且降低微服务开发门槛。 假设您 Dubbo 应用的使用 Nacos 作为注册中心并且其服务器 IP 地址为10.20.153.10同时该注册地址作为 Dubbo 外部化配置属性存储在 dubbo-config.properties 文件如下所示 ## application dubbo.application.name your-dubbo-application## 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 应用的使用 Nacos 作为注册中心并且其服务器 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 /!-- 使用 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 服务。 示例接口与实现 完整代码归档位置 https://github.com/nacos-group/nacos-examples/tree/master/nacos-dubbo-example 首先定义示例接口如下所示 package com.alibaba.nacos.example.dubbo.service;public interface DemoService {String sayName(String name); }提供以上接口的实现类 package com.alibaba.nacos.example.dubbo.service;import com.alibaba.dubbo.config.annotation.Service; import com.alibaba.dubbo.rpc.RpcContext; import org.springframework.beans.factory.annotation.Value;/*** Default {link DemoService}* https://nacos.io/zh-cn/docs/use-nacos-with-dubbo.html* 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 demoServicedubbo.application.qosEnablefalse 实现服务提供方引导类 - DemoServiceProviderBootstrap package com.alibaba.nacos.example.dubbo.provider;import com.alibaba.nacos.example.dubbo.service.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; import java.io.IOException;/*** {link DemoService} provider demo* https://nacos.io/zh-cn/docs/use-nacos-with-dubbo.html*/ EnableDubbo(scanBasePackages com.alibaba.nacos.example.dubbo.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.0dubbo.application.qosEnablefalse同样地dubbo.registry.address 属性指向 Nacos 注册中心其他 Dubbo 服务相关的元信息通过 Nacos 注册中心获取。 实现服务消费方引导类 - DemoServiceConsumerBootstrap package com.alibaba.nacos.example.dubbo.consumer;import com.alibaba.nacos.example.dubbo.service.DemoService; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.PropertySource; import javax.annotation.PostConstruct; import java.io.IOException;/*** {link DemoService} consumer demo* https://nacos.io/zh-cn/docs/use-nacos-with-dubbo.html*/ EnableDubbo PropertySource(value classpath:/consumer-config.properties) public class DemoServiceConsumerBootstrap {DubboReference(version ${demo.service.version})private DemoService demoService;PostConstructpublic void init() {for (int i 0; i 10; i) {System.out.println(demoService.sayName(Nacos));}}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(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos运行无误并且服务消费方使用了负载均衡策略将十次 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.nacos.example.dubbo.service.DemoService refdemoService version2.0.0/!-- 和本地bean一样实现服务 --bean iddemoService classcom.alibaba.nacos.example.dubbo.service.DefaultService/ /beans实现服务提供方引导类 - DemoServiceProviderXmlBootstrap package com.alibaba.nacos.example.dubbo.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.nacos.example.dubbo.service.DemoService version2.0.0//beans实现服务消费方引导类 - DemoServiceConsumerXmlBootstrap package com.alibaba.nacos.example.dubbo.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(Nacos));}context.close();} }运行 XML 配置驱动示例 同样地先启动两个 DemoServiceProviderXmlBootstrap 引导类观察 Nacos 注册中心服务提供者变化 XML 配置驱动的服务版本为 2.0.0因此注册服务无误。 再运行服务消费者引导类 DemoServiceConsumerXmlBootstrap观察控制台输出内容 Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos Service [name :demoService , port : 20880] sayName(Nacos) : Hello,Nacos结果同样运行和负载均衡正常不过由于当前示例尚未添加属性 demo.service.name 的缘故因此“name”部分信息输出为 null。
http://www.dnsts.com.cn/news/88552.html

相关文章:

  • 网站浏览器兼容性通用泰安千橙网络
  • 网站建设流程新闻网页设计图片格式
  • 专门做ppt的网站名称网站可以做无形资产
  • 安庆做网站淮南网站网站建设
  • 企业网站客户案例哪些网站的做的好看的图片
  • 专业的网站建设运营如何制作聊天软件
  • 展厅网站网站建成后 再添加小功能麻烦吗
  • 北京网站制作培训班如何让WordPress快起来
  • 往网站上做新东西需要什么七色鱼设计平台
  • 网站流量在哪设置学校网站建设说明材料
  • 大型门户网站制作教程奉贤做网站公司
  • 网站建设公司初心android应用软件开发
  • 定制化网站开发公司宁波宇丰建设有限公司网站
  • 网站连接如何做二维码包装设计展开图图片
  • wordpress题网络优化关键词
  • 网站配置番禺建设网站策划
  • 国际贸易网站大全承德在线
  • 东莞教育网站建设添加qq好友的超链接做网站
  • 行业网站导航源码网站风格有哪些类型
  • 电脑pc端网站建设是什么意思手机网站用什么做的
  • 如何用易语言做网站辅助百度指数的需求指数
  • 台州市建设规划局网站班子成员个人备案网站名称怎么写
  • 二手书屋网站开发的意义网站建设 中企动力 东莞
  • 专业做室内设计的网站有哪些方面书店网站建设
  • 做芯片哪个网站推广wordpress 公众号插件
  • 微信网站可以免费做么怎么看得出网站是哪个公司做的
  • 无锡手机网站制作费用建筑工程公司网站模板下载
  • wordpress怎么编辑网站抖音网站开发
  • 交互有趣的网站大学网站建设招标
  • 温州网站建设推广服务利用大平台做网站