一 、RabbitMQ基础组件整体功能概述
二、基础组件开发
4各模块 common、api、core-product、task
(一)、父工程 rabbit-parent
1.pom文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.bfxy.base.rabbit</groupId> <artifactId>rabbit-parent</artifactId> <packaging>pom</packaging> <name>rabbit-parent</name> <description>rabbit-parent</description> <version>0.0.1-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>8</java.version> <fasterxml.uuid.version>3.1.4</fasterxml.uuid.version> <org.codehaus.jackson.version>1.9.13</org.codehaus.jackson.version> <druid.version>1.0.24</druid.version> <elastic-job.version>2.1.4</elastic-job.version> <guava.version>20.0</guava.version> <commons-lang3.version>3.3.1</commons-lang3.version> <commons-io.version>2.4</commons-io.version> <commons-collections.version>3.2.2</commons-collections.version> <curator.version>2.11.0</curator.version> <fastjson.version>1.1.26</fastjson.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!--对json格式的支持 --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${org.codehaus.jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>com.fasterxml.uuid</groupId> <artifactId>java-uuid-generator</artifactId> <version>${fasterxml.uuid.version}</version> </dependency> </dependencies> <modules> <module>rabbit-common</module> <module>rabbit-api</module> <module>rabbit-core-producer</module> <module>rabbit-task</module> </modules> </project>
(二)、子模块API封装 rabbit-api
1、Message 消息的规划
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package com.bfxy.rabbit.api; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import lombok.Data; /** * $Message * @author Alienware * */ @Data public class Message implements Serializable { private static final long serialVersionUID = 841277940410721237L; /* 消息的唯一ID */ private String messageId; /* 消息的主题 */ private String topic; /* 消息的路由规则 */ private String routingKey = ""; /* 消息的附加属性 */ private Map<String, Object> attributes = new HashMap<String, Object>(); /* 延迟消息的参数配置 */ private int delayMills; /* 消息类型:默认为confirm消息类型 */ private String messageType = MessageType.CONFIRM; public Message() { } public Message(String messageId, String topic, String routingKey, Map<String, Object> attributes, int delayMills) { this.messageId = messageId; this.topic = topic; this.routingKey = routingKey; this.attributes = attributes; this.delayMills = delayMills; } public Message(String messageId, String topic, String routingKey, Map<String, Object> attributes, int delayMills, String messageType) { this.messageId = messageId; this.topic = topic; this.routingKey = routingKey; this.attributes = attributes; this.delayMills = delayMills; this.messageType = messageType; } }