(十六) 构建dubbo分布式平台-dubbo服务接口定义
在前面的章节中,我们着手介绍了dubbo的相关知识,在这个基础之上,我们可以考虑将dubbo服务应用于我们的分布式系统了,从今天开始,我们会详细介绍如何将dubbo和spring集成并应用于我们的分布式系统。
1. 创建ant-bookmark-facade项目(dubbo服务接口),其中pom.xml文件定义如下:
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.sml.sz</groupId> <artifactId>ant-project</artifactId> <version>1.0.0</version> </parent> <artifactId>ant-member-facade</artifactId> <packaging>jar</packaging> <name>ant-member-facade</name> <url>http://maven.apache.org</url> <description>ant的收藏模块Dubbo服务接口包,提供相关的Dubbo服务入口</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- ant framework begin --> <!-- 系统核心框架包 --> <dependency> <groupId>com.sml.sz</groupId> <artifactId>ant-framework</artifactId> </dependency> <!-- ant framework end --> </dependencies> </project> <?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.sml.sz</groupId> <artifactId>ant-project</artifactId> <version>1.0.0</version> </parent> <artifactId>ant-member-facade</artifactId> <packaging>jar</packaging> <name>ant-member-facade</name> <url>http://maven.apache.org</url> <description>ant的会员模块Dubbo服务接口包,提供相关的Dubbo服务入口</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- ant framework begin --> <!-- 系统核心框架包 --> <dependency> <groupId>com.sml.sz</groupId> <artifactId>ant-framework</artifactId> </dependency> <!-- ant framework end --> </dependencies> </project>
2. 定义实体entity,因为接口中的对象要使用
package com.sml.sz.bookmark.entity; import org.hibernate.validator.constraints.Length; import com.sml.sz.common.persistence.DataEntity; /** * 我的收藏链接管理Entity * * @author ant * @version 2016-01-30 */ public class Bookmark extends DataEntity<Bookmark> { private static final long serialVersionUID = 1L; private String tagId; private BookmarkTag bookmarkTag; // 业务主表ID 父类 private String bookmarkname; // 名称 private String bookmarkurl; // 名称 public Bookmark() { super(); } public Bookmark(String id) { super(id); } public Bookmark(BookmarkTag bookmarkTag) { this.tagId = bookmarkTag.getId(); this.bookmarkTag = bookmarkTag; } @Length(min = 1, max = 64, message = "业务主表ID长度必须介于 1 和 64 之间") public String getTagId() { return tagId; } public void setTagId(String tagId) { this.tagId = tagId; } @Length(min = 1, max = 100, message = "名称长度必须介于 1 和 100 之间") public String getBookmarkname() { return bookmarkname; } public void setBookmarkname(String bookmarkname) { this.bookmarkname = bookmarkname; } @Length(min = 1, max = 100, message = "名称长度必须介于 1 和 100 之间") public String getBookmarkurl() { return bookmarkurl; } public void setBookmarkurl(String bookmarkurl) { this.bookmarkurl = bookmarkurl; } public BookmarkTag getBookmarkTag() { return bookmarkTag; } public void setBookmarkTag(BookmarkTag bookmarkTag) { this.bookmarkTag = bookmarkTag; } }
package com.sml.sz.bookmark.entity; import java.util.List; import org.hibernate.validator.constraints.Length; import com.google.common.collect.Lists; import com.sml.sz.common.persistence.DataEntity; /** * 我的收藏链接管理Entity * @author ant * @version 2016-01-30 */ public class BookmarkTag extends DataEntity<BookmarkTag> { private static final long serialVersionUID = 1L; private String bookmarktagname; // 标签名称 private List<Bookmark> bookmarkList = Lists.newArrayList(); // 子表列表 public BookmarkTag() { super(); } public BookmarkTag(String id){ super(id); } @Length(min=1, max=64, message="标签名称长度必须介于 1 和 64 之间") public String getBookmarktagname() { return bookmarktagname; } public void setBookmarktagname(String bookmarktagname) { this.bookmarktagname = bookmarktagname; } public List<Bookmark> getBookmarkList() { return bookmarkList; } public void setBookmarkList(List<Bookmark> bookmarkList) { this.bookmarkList = bookmarkList; } }
3. 定义接口类,此类会在dubbo生产者和dubbo消费者之间被引用
package com.sml.sz.bookmark.service; import java.util.List; import com.sml.sz.bookmark.entity.BookmarkTag; import com.sml.sz.common.persistence.Page; /** * 我的收藏链接管理Service * * @author ant * @version 2016-01-30 */ public interface BookmarkTagFacade { public BookmarkTag get(String id); public List<BookmarkTag> findList(BookmarkTag bookmarkTag); public Page<BookmarkTag> findPage(Page<BookmarkTag> page, BookmarkTag bookmarkTag); public void save(BookmarkTag bookmarkTag); public void delete(BookmarkTag bookmarkTag); }
欢迎大家跟我一起学习《构建dubbo分布式平台》,希望大家持续关注后面的文章!