前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >服务治理的要求

服务治理的要求

作者头像
用户1215919
发布2021-12-28 12:38:05
4760
发布2021-12-28 12:38:05
举报
文章被收录于专栏:大大的微笑

服务的调用方式多种多样,从一开始的webservice(基于SOAP)提供wsdl的方式, 再比如EJB,RMI,restful等,每种服务在当时都有其特定的使用价值,但是随着架构体系的升级,技术的发展单单是实现远程通信是远远不够的。这个时候可能就需要使用服务治理。 服务治理可能要求: 注册中心链路跟踪通信异常处理负载均衡

为什么使用dubbo,因为他能够满足服务治理的要求 。

dubbo是一种RPC框架。 那么RPC框架所需要具备的基本功能:网络通信(服务调用)、序列化/反序列化、动态代理(serviceA->serviceB的方式改为了serviceA直接通过RPC调用ServiceB那么肯定会存在代理)、负载均衡、容错等

代码语言:javascript
复制
一个服务serviceA->调用服务serviceB
那么通过这个RPC框架已经把需要做的这一系列例如: 
动态代理->序列化/反序列化->网络通信等操作给封装好,
相当于在本地调用服务那样直接使用。
代码语言:javascript
复制
<!-- 服务端的XML -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    <!-- 应用名,唯一 -->
    <dubbo:application name="pay-provider" />

    <!--注册中心地址-->
    <dubbo:registry address="N/A"/>
    <!--服务提供的方式和端口,(可选),因为会默认提供地址-->
    <dubbo:protocol name="dubbo" port="20880"/>
    <!--服务提供的接口-->
    <dubbo:service interface="xxx.IPayService" ref="payService"/>

    <!--接口实现-->
    <bean class="xxx.provider.PayServiceImpl" id="payService"/>


</beans>
代码语言:javascript
复制
 // 启动
  ClassPathXmlApplicationContext loader = new ClassPathXmlApplicationContext(new String[]{"application.xml"});
        loader.start();
        System.in.read();
代码语言:javascript
复制
	<dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.7.3</version>
        </dependency>
代码语言:javascript
复制
dubbo://0.0.0.0:20880/xxx.api.IPayService?anyhost=true&application=provider&bean.name=xxx.IPayService&bind.ip=0.0.0.0&bind.port=20880&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=xxx.IPayService&methods=doPay&pid=5676&register=true&release=2.7.3&side=provider&timestamp=1570123868318, dubbo version: 2.7.3, current host: 0.0.0.0

同理客户端的配置:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
    <!-- 应用名,唯一 -->
    <dubbo:application name="pay-client" />

    <!--注册中心地址-->
    <dubbo:registry address="N/A"/>
    <!--服务提供的接口-->
    <dubbo:reference id="payService" interface="xxx.IPayService" url="dubbo://0.0.0.0:20880/xxx.IPayService"/>

</beans>
代码语言:javascript
复制
 ClassPathXmlApplicationContext loader =
                new ClassPathXmlApplicationContext(new String[]{"application.xml"});
        loader.start();
        IPayService payService = (IPayService)loader.getBean("payService");
        payService.doPay();
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档