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

优质公司网站建筑业管理平台登录

优质公司网站,建筑业管理平台登录,开发网络新技术的平台,高端企业门户网站建设1.Dubbo中的版本号 每个接口都应定义版本号,为后续不兼容升级提供可能。当一个接口有不同的实现,项目早期使用的一个实现类, 之后创建接口的新的实现类。区分不同的接口实现使用 version。 特别是项目需要把早期接口的实现全部换位新的实现类…

1.Dubbo中的版本号

每个接口都应定义版本号,为后续不兼容升级提供可能。当一个接口有不同的实现,项目早期使用的一个实现类, 之后创建接口的新的实现类。区分不同的接口实现使用 version。

特别是项目需要把早期接口的实现全部换位新的实现类,也需要使用 version。

可以用版本号从早期的接口实现过渡到新的接口实现,版本号不同的服务相互间不引用。

可以按照以下的步骤进行版本迁移:

  • 在低压力时间段,先升级一半提供者为新版本
  • 再将所有消费者升级为新版本
  • 然后将剩下的一半提供者升级为新版本

2.案例分析

最近两天一直都在学习Dubbo,说来说去,那开始依旧是三个工程(第一个是maven java工程、后两个是maven web工程)。 下面是这三个工程的架构。

2.1 第一个是maven java工程

这其中提供的是服务模型(实体Bean)、服务接口(对外提供的方法),这个工程不需要添加任何依赖。

package com.szh.dubbo.model;import java.io.Serializable;/****/
public class User implements Serializable {private Integer id;private String username;//getter and setter
}
package com.szh.dubbo.service;import com.szh.dubbo.model.User;/****/
public interface UserService {User queryUserById(Integer id,String username);}

2.2 第二个是maven web工程

这个代表的是服务提供者,其中包含对第一个maven java工程中服务接口方法的实现。但是我们这里为服务接口提供两个实现类,来体现对版本号version的使用。

package com.szh.dubbo.service.impl;import com.szh.dubbo.model.User;
import com.szh.dubbo.service.UserService;/****/
public class UserServiceImpl implements UserService {@Overridepublic User queryUserById(Integer id, String username) {User user=new User();user.setId(id);user.setUsername(username + "-1");return user;}
}
package com.szh.dubbo.service.impl;import com.szh.dubbo.model.User;
import com.szh.dubbo.service.UserService;/****/
public class UserServiceImpl2 implements UserService {@Overridepublic User queryUserById(Integer id, String username) {User user=new User();user.setId(id);user.setUsername(username + "-2");return user;}
}

然后是dubbo服务提供者的配置文件。这里仍然使用zookeeper注册中心,将服务接口的两个实现类加载到spring容器中,最后在web.xml中配置spring的监听器,同时读取dubbo配置文件。

<?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://dubbo.apache.org/schema/dubbo"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="009-zk-userservice-multi-provider"/><dubbo:protocol name="dubbo" port="20880"/><dubbo:registry address="zookeeper://localhost:2181"/><dubbo:service interface="com.szh.dubbo.service.UserService" ref="userServiceImpl" version="1.0.0"/><dubbo:service interface="com.szh.dubbo.service.UserService" ref="userServiceImpl2" version="2.0.0"/><bean id="userServiceImpl" class="com.szh.dubbo.service.impl.UserServiceImpl"/><bean id="userServiceImpl2" class="com.szh.dubbo.service.impl.UserServiceImpl2"/></beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:dubbo-userservice-multi-provider.xml</param-value></context-param></web-app>

pom文件中的相关依赖。

    <!-- Spring依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.5.RELEASE</version></dependency><!-- SpringMVC依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.2.5.RELEASE</version></dependency><!-- Dubbo依赖 --><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.2</version></dependency><!-- 接口工程依赖 --><dependency><groupId>com.szh.dubbo</groupId><artifactId>006-zk-interface</artifactId><version>1.0.0</version></dependency><!-- Zookeeper依赖 --><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.1.0</version></dependency>

2.3 第三个是maven web工程

这个代表的是服务消费者,其中包含一个控制层方法的实现,去响应之前的服务接口。

package com.szh.dubbo.controller;import com.szh.dubbo.model.User;
import com.szh.dubbo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;/****/
@Controller
public class UserController {@Autowiredprivate UserService userService1;@Autowiredprivate UserService userService2;@RequestMapping(value = "/userDetail")public String userDetail(Model model,Integer id,String username) {User user1=userService1.queryUserById(id,username);User user2=userService2.queryUserById(id,username);model.addAttribute("user1",user1);model.addAttribute("user2",user2);return "userDetail";}
}

然后是dubbo服务消费者的配置文件、Spring配置文件。

<?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://dubbo.apache.org/schema/dubbo"xmlns:dubo="http://code.alibabatech.com/schema/dubbo"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 http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:application name="010-zk-multi-consumer"/><dubo:registry address="zookeeper://localhost:2181"/><dubbo:reference id="userService1" interface="com.szh.dubbo.service.UserService" version="1.0.0"/><dubbo:reference id="userService2" interface="com.szh.dubbo.service.UserService" version="2.0.0"/></beans>
<?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:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scan base-package="com.szh.dubbo.controller"/><mvc:annotation-driven/><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/"/><property name="suffix" value=".jsp"/></bean></beans>

最后是web.xml和控制层方法对应的jsp页面。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><servlet><servlet-name>DispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml,classpath:dubbo-multi-consumer.xml</param-value></init-param></servlet><servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
</web-app>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<html>
<head><title>$</title>
</head>
<body><h3>用户1的信息</h3><div>用户编号:${user1.id}</div><div>用户姓名:${user1.username}</div><hr/><h3>用户2的信息</h3><div>用户编号:${user2.id}</div><div>用户姓名:${user2.username}</div>
</body>
</html>

2.4 启动测试!!!

步骤在上一篇博文中已经说过了,链接:Dubbo——使用Zookeeper注册中心实现Dubbo_zookeeper中的dubbo-CSDN博客

下面是测试结果:

http://www.yayakq.cn/news/594009/

相关文章:

  • 网站建设与维护可行性报告温州集团网站建设公司
  • linux如何架设网站wordpress怎么用ftp上传插件
  • 网站建设 东营远见网络公司域名批量注册查询
  • 网站建设需要了解哪些信息网站建设广告
  • 免费网站自己做最好用的搜索神器
  • 网站计算器代码国内最专业的设计网站建设
  • 计算机作业做网站进入公众号平台
  • 中石油网页设计与网站建设分类信息多城市网站
  • ps网站交互设计帮别人做网站怎么赚钱
  • 网站建设明薇通网络保险官网
  • 怎么查看网站空间大小学校建设网站前的市场分析
  • 建设部网站官网查询广告公司现状
  • 用网站还是阿里巴巴做soho上海本地生活的网站
  • 英文网站建设 淮安花2w学ui值得吗
  • 电子商务基础网站建设用wordpress开发网站
  • 宿迁做网站哪家好嘉兴学网站建设
  • 资料库网站开发报价定制软件的平台
  • 做网站可以申请国家补助吗网站建设企业有哪些
  • 泰州网站制作报价软件项目管理心得体会
  • 建手机网站自己怎么制作假山
  • 慈利做网站在哪里建设公司网站费用怎么做账
  • 做国外网站推广网络营销运营外包
  • 晋江建设局网站网站海外推广
  • 哪里有做商城的网站网站建设英文术语
  • 深圳移动网站建设公司价格wordpress 实现动画
  • 展馆设计效果图图片 展厅seo排名推广工具
  • 官方网站制作哪家专业北京同仁医院眼科医生免费咨询
  • 企业建设网站应如何申请信阳企业网站建设
  • 建立一个属于自己的网站网站前期推广
  • 建立网站 知乎做微商网站制作