移除data-bus模块

This commit is contained in:
cuizhibin 2025-06-25 21:03:39 +08:00
parent 5f49a0ecc2
commit 7306aaccd2
9 changed files with 0 additions and 256 deletions

View File

@ -1,32 +0,0 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dite.znpt</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>data-bus</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.dite.znpt</groupId>
<artifactId>core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,90 +0,0 @@
package com.dite.znpt.data.bus.config;
import cn.hutool.extra.spring.SpringUtil;
import com.dite.znpt.data.bus.entity.CommonMessage;
import com.dite.znpt.data.bus.enums.MQTypeEnum;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Component
public class MQConfig {
@Autowired
private ConnectionFactory connectionFactory;
@Bean
public RabbitAdmin rabbitAdmin() {
RabbitAdmin admin = new RabbitAdmin(connectionFactory);
admin.setAutoStartup(true);
return admin;
}
@Bean
public TopicExchange topicExchange() {
return new TopicExchange("data.topic.exchange");
}
@Bean
public Declarables declarables(TopicExchange exchange) {
List<Declarable> declarables = new ArrayList<>();
declarables.add(exchange);
for (MQTypeEnum typeEnum : MQTypeEnum.values()) {
String queueName = typeEnum.getType() + ".queue";
Queue queue = new Queue(queueName, true);
declarables.add(queue);
Binding binding = BindingBuilder.bind(queue)
.to(exchange)
.with(typeEnum.getType() + ".*");
declarables.add(binding);
}
return new Declarables(declarables);
}
@Bean
public List<SimpleMessageListenerContainer> registerListeners(Declarables declarables) {
List<SimpleMessageListenerContainer> messageListeners = new ArrayList<>();
for (MQTypeEnum typeEnum : MQTypeEnum.values()) {
String queueName = typeEnum.getType() + ".queue";
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(queueName);
container.setMessageListener(message -> {
String body = new String(message.getBody());
log.debug("队列: " + queueName + " 收到消息: " + body);
try {
ObjectMapper objectMapper = new ObjectMapper();
CommonMessage<?> msg = objectMapper.readValue(body,
objectMapper.getTypeFactory().constructParametricType(CommonMessage.class, typeEnum.getDto()));
MQHandle<?> handle = SpringUtil.getBean(typeEnum.getImpl());
handleMessageWithType(handle, msg);
} catch (Exception e) {
log.error("mq队列处理出错", e);
}
});
messageListeners.add(container);
// 启动监听
container.start();
}
log.info("mq监听启动完成");
return messageListeners;
}
@SuppressWarnings("unchecked")
private <T> void handleMessageWithType(MQHandle<T> handler, CommonMessage<?> message) {
handler.handle((CommonMessage<T>) message);
}
}

View File

@ -1,21 +0,0 @@
package com.dite.znpt.data.bus.config;
import com.dite.znpt.data.bus.entity.CommonMessage;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* @author cuizhibin
* @date 2025/04/22 17:03
* @description mq处理接口
*/
public interface MQHandle<T> {
/**
* 功能描述mq处理类
*
* @param msg 消息
* @author cuizhibin
* @date 2025/04/22 17:03
**/
void handle(CommonMessage<T> msg);
}

View File

@ -1,10 +0,0 @@
package com.dite.znpt.data.bus.entity;
import com.dite.znpt.data.bus.enums.MQOperationEnum;
import lombok.Data;
@Data
public class CommonMessage<T> {
private MQOperationEnum operation;
private T payload;
}

View File

@ -1,12 +0,0 @@
package com.dite.znpt.data.bus.entity.req;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@NoArgsConstructor
@Data
public class ProjectDTO {
}

View File

@ -1,33 +0,0 @@
package com.dite.znpt.data.bus.enums;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
@Getter
public enum MQOperationEnum {
ADD("add", "新增"),
UPDATE("update", "修改"),
DEL("del", "删除"),
;
private final String code;
private final String desc;
MQOperationEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
@JsonValue
public String getCode() {
return code;
}
@JsonCreator
public static MQOperationEnum fromCode(String code) {
for (MQOperationEnum s : values()) {
if (s.code.equals(code)) return s;
}
throw new IllegalArgumentException("Unknown code: " + code);
}
}

View File

@ -1,31 +0,0 @@
package com.dite.znpt.data.bus.enums;
import com.dite.znpt.data.bus.config.MQHandle;
import com.dite.znpt.data.bus.entity.req.ProjectDTO;
import com.dite.znpt.data.bus.handles.ProjectHandleImpl;
import lombok.Getter;
/**
* @author cuizhibin
* @date 2025/04/22 17:05
* @description mq类型枚举
*/
@Getter
public enum MQTypeEnum {
PROJECT("project", "项目", ProjectHandleImpl.class, ProjectDTO.class),
CREW("crew", "机组", ProjectHandleImpl.class, ProjectDTO.class),
PARTS("parts", "部件", ProjectHandleImpl.class, ProjectDTO.class),
;
private final String type;
private final String desc;
private final Class<? extends MQHandle<?>> impl;
private final Class<?> dto;
MQTypeEnum(String type, String desc, Class<? extends MQHandle<?>> impl, Class<?> dto) {
this.type = type;
this.desc = desc;
this.impl = impl;
this.dto = dto;
}
}

View File

@ -1,26 +0,0 @@
package com.dite.znpt.data.bus.handles;
import com.dite.znpt.data.bus.config.MQHandle;
import com.dite.znpt.data.bus.entity.CommonMessage;
import com.dite.znpt.data.bus.entity.req.ProjectDTO;
import org.springframework.stereotype.Service;
/**
* @author cuizhibin
* @date 2025/04/22 17:11
* @description 项目处理
*/
@Service
public class ProjectHandleImpl implements MQHandle<ProjectDTO> {
/**
* 功能描述mq处理类
*
* @param msg 消息
* @author cuizhibin
* @date 2025/04/22 17:03
**/
@Override
public void handle(CommonMessage<ProjectDTO> msg) {
}
}

View File

@ -14,7 +14,6 @@
<module>core</module> <module>core</module>
<module>sip</module> <module>sip</module>
<module>web</module> <module>web</module>
<module>data-bus</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>