初始化
commit
43c8437f41
|
@ -0,0 +1,47 @@
|
|||
######################################################################
|
||||
# Build Tools
|
||||
|
||||
.gradle
|
||||
/build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
######################################################################
|
||||
# IDE
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### JRebel ###
|
||||
rebel.xml
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/*
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
target/
|
||||
|
||||
######################################################################
|
||||
# Others
|
||||
*.log
|
||||
*.xml.versionsBackup
|
||||
*.swp
|
||||
|
||||
!*/build/*.java
|
||||
!*/build/*.html
|
||||
!*/build/*.xml
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<parent>
|
||||
<artifactId>menghang-common</artifactId>
|
||||
<groupId>com.bawei</groupId>
|
||||
<version>3.6.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<version>3.6.0</version>
|
||||
<artifactId>menghang-common-rabbit</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>menghang-public</id>
|
||||
<name>梦航-public</name>
|
||||
<url>http://192.168.111.130:8081/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>menghang-releases</id>
|
||||
<name>梦航-releases</name>
|
||||
<url>http://192.168.111.130:8081/repository/maven-releases/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.bawei</groupId>
|
||||
<artifactId>menghang-common-core</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</dependency>
|
||||
<!-- rabbit MQ 消息队列 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,46 @@
|
|||
package com.bawei.common.rabbit.config;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||
import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig implements RabbitListenerConfigurer {
|
||||
|
||||
// 可以将json串反序列化为对象
|
||||
@Override
|
||||
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
|
||||
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(messageHandlerMethodFactory());
|
||||
}
|
||||
|
||||
@Bean
|
||||
MessageHandlerMethodFactory messageHandlerMethodFactory(){
|
||||
DefaultMessageHandlerMethodFactory messageHandlerMethodFactory = new DefaultMessageHandlerMethodFactory();
|
||||
messageHandlerMethodFactory.setMessageConverter(mappingJackson2MessageConverter());
|
||||
return messageHandlerMethodFactory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MappingJackson2MessageConverter mappingJackson2MessageConverter(){
|
||||
return new MappingJackson2MessageConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供自定义RabbitTemplate,将对象序列化为json串
|
||||
* @param connectionFactory
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RabbitTemplate jacksonRabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||
rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
|
||||
return rabbitTemplate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.bawei.common.rabbit.constant;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 队列常量
|
||||
* @Date 2022-10-21 下午 01:59
|
||||
*/
|
||||
public class QueueConstant {
|
||||
|
||||
/**
|
||||
* 测试队列名称
|
||||
*/
|
||||
public static final String TEST_NAME = "test";
|
||||
|
||||
/**
|
||||
* 商品新增队列
|
||||
*/
|
||||
public static final String PRODUCT_ADD = "product_add";
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.bawei.common.rabbit.domain;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bawei.common.core.utils.uuid.IdUtils;
|
||||
import com.bawei.common.core.web.domain.BaseEntity;
|
||||
|
||||
import javax.swing.text.html.parser.Entity;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: RabbitMq消息体
|
||||
* @Date 2022-10-21 上午 09:14
|
||||
*/
|
||||
public class Message<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 消息ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 消息创建时间
|
||||
*/
|
||||
private long createTime;
|
||||
|
||||
/**
|
||||
* 消息主体
|
||||
*/
|
||||
private T body;
|
||||
|
||||
public Message () {
|
||||
}
|
||||
|
||||
public Message (String id, T body) {
|
||||
this.id = id;
|
||||
this.createTime = System.currentTimeMillis();
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动生成消息ID
|
||||
* @param body 消息主体
|
||||
* @return
|
||||
*/
|
||||
public static <T> Message<T> builderMsg(T body){
|
||||
return new Message(IdUtils.fastUUID(), body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成消息主题
|
||||
* @param id 唯一标识
|
||||
* @param body 消息主体
|
||||
* @return
|
||||
*/
|
||||
public static <T> Message<T> builderMsg(String id, T body){
|
||||
return new Message(id, body);
|
||||
}
|
||||
|
||||
|
||||
public String getId () {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId (String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getCreateTime () {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime (long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public T getBody () {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody (T body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
return "Message{" +
|
||||
"id='" + id + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", body=" + JSONObject.toJSONString(body) +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.bawei.common.rabbit.enums;
|
||||
|
||||
import com.bawei.common.rabbit.constant.QueueConstant;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 队列枚举
|
||||
* @Date 2022-10-21 下午 01:44
|
||||
*/
|
||||
public enum QueueEnum {
|
||||
|
||||
|
||||
TEST(QueueConstant.TEST_NAME, "测试队列"),
|
||||
PRODUCT_ADD(QueueConstant.PRODUCT_ADD, "商品新增队列"),
|
||||
;
|
||||
|
||||
private String queueName;
|
||||
|
||||
private String queueDesc;
|
||||
|
||||
public String queueName () {
|
||||
return queueName;
|
||||
}
|
||||
|
||||
public String queueDesc () {
|
||||
return queueDesc;
|
||||
}
|
||||
|
||||
public String queueStr(){
|
||||
return new StringBuilder(this.queueName).append("(").append(this.queueDesc).append(")").toString();
|
||||
}
|
||||
|
||||
QueueEnum (String queueName, String queueDesc) {
|
||||
this.queueName = queueName;
|
||||
this.queueDesc = queueDesc;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.bawei.common.rabbit.config.RabbitMQConfig
|
Loading…
Reference in New Issue