(十六)springmvc+mybatis+dubbo+zookeeper分布式架构 整合 - dubbo服务接口定义

约定不等于承诺〃 2021-09-20 12:20 297阅读 0赞

在前面的章节中,我们着手介绍了dubbo的相关知识,在这个基础之上,我们可以考虑将dubbo服务应用于我们的分布式系统了,从今天开始,我们会详细介绍如何将dubbo和spring集成并应用于我们的分布式系统。

  1. 创建ant-bookmark-facade项目(dubbo服务接口),其中pom.xml文件定义如下:

    <?xml version=”1.0”?>

    1. <project
    2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    3. xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    4. <modelVersion>4.0.0</modelVersion>
    5. <parent>
    6. <groupId>com.sml.sz</groupId>
    7. <artifactId>ant-project</artifactId>
    8. <version>1.0.0</version>
    9. </parent>
    10. <artifactId>ant-member-facade</artifactId>
    11. <packaging>jar</packaging>
    12. <name>ant-member-facade</name>
    13. <url>http://maven.apache.org</url>
    14. <description>ant的收藏模块Dubbo服务接口包,提供相关的Dubbo服务入口</description>
    15. <properties>
    16. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    17. </properties>
    18. <dependencies>
    19. <!-- ant framework begin -->
    20. <!-- 系统核心框架包 -->
    21. <dependency>
    22. <groupId>com.sml.sz</groupId>
    23. <artifactId>ant-framework</artifactId>
    24. </dependency>
    25. <!-- ant framework end -->
    26. </dependencies>
    27. </project>
    28. <?xml version="1.0"?>
    29. <project
    30. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    31. xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    32. <modelVersion>4.0.0</modelVersion>
    33. <parent>
    34. <groupId>com.sml.sz</groupId>
    35. <artifactId>ant-project</artifactId>
    36. <version>1.0.0</version>
    37. </parent>
    38. <artifactId>ant-member-facade</artifactId>
    39. <packaging>jar</packaging>
    40. <name>ant-member-facade</name>
    41. <url>http://maven.apache.org</url>
    42. <description>ant的会员模块Dubbo服务接口包,提供相关的Dubbo服务入口</description>
    43. <properties>
    44. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    45. </properties>
    46. <dependencies>
    47. <!-- ant framework begin -->
    48. <!-- 系统核心框架包 -->
    49. <dependency>
    50. <groupId>com.sml.sz</groupId>
    51. <artifactId>ant-framework</artifactId>
    52. </dependency>
    53. <!-- ant framework end -->
    54. </dependencies>
    55. </project></span>

  2. 定义实体entity,因为接口中的对象要使用

  1. <span style="font-size: 16px;">package com.sml.sz.bookmark.entity;
  2. import org.hibernate.validator.constraints.Length;
  3. import com.sml.sz.common.persistence.DataEntity;
  4. /**
  5. * 我的收藏链接管理Entity
  6. *
  7. * @author ant
  8. * @version 2016-01-30
  9. */
  10. public class Bookmark extends DataEntity<Bookmark> {
  11. private static final long serialVersionUID = 1L;
  12. private String tagId;
  13. private BookmarkTag bookmarkTag; // 业务主表ID 父类
  14. private String bookmarkname; // 名称
  15. private String bookmarkurl; // 名称
  16. public Bookmark() {
  17. super();
  18. }
  19. public Bookmark(String id) {
  20. super(id);
  21. }
  22. public Bookmark(BookmarkTag bookmarkTag) {
  23. this.tagId = bookmarkTag.getId();
  24. this.bookmarkTag = bookmarkTag;
  25. }
  26. @Length(min = 1, max = 64, message = "业务主表ID长度必须介于 1 和 64 之间")
  27. public String getTagId() {
  28. return tagId;
  29. }
  30. public void setTagId(String tagId) {
  31. this.tagId = tagId;
  32. }
  33. @Length(min = 1, max = 100, message = "名称长度必须介于 1 和 100 之间")
  34. public String getBookmarkname() {
  35. return bookmarkname;
  36. }
  37. public void setBookmarkname(String bookmarkname) {
  38. this.bookmarkname = bookmarkname;
  39. }
  40. @Length(min = 1, max = 100, message = "名称长度必须介于 1 和 100 之间")
  41. public String getBookmarkurl() {
  42. return bookmarkurl;
  43. }
  44. public void setBookmarkurl(String bookmarkurl) {
  45. this.bookmarkurl = bookmarkurl;
  46. }
  47. public BookmarkTag getBookmarkTag() {
  48. return bookmarkTag;
  49. }
  50. public void setBookmarkTag(BookmarkTag bookmarkTag) {
  51. this.bookmarkTag = bookmarkTag;
  52. }
  53. }</span>

  

  1. <span style="font-size: 16px;">package com.sml.sz.bookmark.entity;
  2. import java.util.List;
  3. import org.hibernate.validator.constraints.Length;
  4. import com.google.common.collect.Lists;
  5. import com.sml.sz.common.persistence.DataEntity;
  6. /**
  7. * 我的收藏链接管理Entity
  8. * @author ant
  9. * @version 2016-01-30
  10. */
  11. public class BookmarkTag extends DataEntity<BookmarkTag> {
  12. private static final long serialVersionUID = 1L;
  13. private String bookmarktagname; // 标签名称
  14. private List<Bookmark> bookmarkList = Lists.newArrayList(); // 子表列表
  15. public BookmarkTag() {
  16. super();
  17. }
  18. public BookmarkTag(String id){
  19. super(id);
  20. }
  21. @Length(min=1, max=64, message="标签名称长度必须介于 1 和 64 之间")
  22. public String getBookmarktagname() {
  23. return bookmarktagname;
  24. }
  25. public void setBookmarktagname(String bookmarktagname) {
  26. this.bookmarktagname = bookmarktagname;
  27. }
  28. public List<Bookmark> getBookmarkList() {
  29. return bookmarkList;
  30. }
  31. public void setBookmarkList(List<Bookmark> bookmarkList) {
  32. this.bookmarkList = bookmarkList;
  33. }
  34. }</span>

  3. 定义接口类,此类会在dubbo生产者和dubbo消费者之间被引用

  1. <span style="font-size: 16px;">package com.sml.sz.bookmark.service;
  2. import java.util.List;
  3. import com.sml.sz.bookmark.entity.BookmarkTag;
  4. import com.sml.sz.common.persistence.Page;
  5. /**
  6. * 我的收藏链接管理Service
  7. *
  8. * @author ant
  9. * @version 2016-01-30
  10. */
  11. public interface BookmarkTagFacade {
  12. public BookmarkTag get(String id);
  13. public List<BookmarkTag> findList(BookmarkTag bookmarkTag);
  14. public Page<BookmarkTag> findPage(Page<BookmarkTag> page, BookmarkTag bookmarkTag);
  15. public void save(BookmarkTag bookmarkTag);
  16. public void delete(BookmarkTag bookmarkTag);
  17. }</span>

  

架构代码如下:

1

资料和源码来源

转载于:https://www.cnblogs.com/xiamudaren/p/8443893.html

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读

    相关 dubbo分布式服务架构

    Dubbo是什么      Dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。 Dubbo的特点 远程通讯:提供透