[重大更新] 新增 ruoyi-common-bus 消息总线组件 基于MQ跨服务投递事件消息

2.X
疯狂的狮子Li 7 months ago
parent d28cdcd0e1
commit 9a27f42867

@ -85,6 +85,16 @@ spring:
# 控制台地址 从1.3.0开始使用 server-name 注册
# dashboard: localhost:8718
bus:
id: ${spring.application.name}
base-packages: org.dromara.**.event
# 消息总线 也可以使用 kafka 参考 spring-cloud-bus 用法
rabbitmq:
host: localhost
port: 5672
username: ruoyi
password: ruoyi123
# redis通用配置 子服务可以自行配置进行覆盖
data:
redis:

@ -22,6 +22,10 @@
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-bus</artifactId>
</dependency>
</dependencies>

@ -1,18 +1,20 @@
package org.dromara.workflow.api.domain.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.core.utils.SpringUtils;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import java.io.Serial;
import java.io.Serializable;
/**
*
*
* @author may
*/
@Data
public class ProcessEvent implements Serializable {
@EqualsAndHashCode(callSuper = true)
public class ProcessEvent extends RemoteApplicationEvent {
@Serial
private static final long serialVersionUID = 1L;
@ -37,4 +39,8 @@ public class ProcessEvent implements Serializable {
*/
private boolean submit;
public ProcessEvent() {
super(new Object(), SpringUtils.getApplicationName(), DEFAULT_DESTINATION_FACTORY.getDestination(null));
}
}

@ -1,18 +1,20 @@
package org.dromara.workflow.api.domain.event;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.core.utils.SpringUtils;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import java.io.Serial;
import java.io.Serializable;
/**
*
*
* @author may
*/
@Data
public class ProcessTaskEvent implements Serializable {
@EqualsAndHashCode(callSuper = true)
public class ProcessTaskEvent extends RemoteApplicationEvent {
@Serial
private static final long serialVersionUID = 1L;
@ -37,4 +39,7 @@ public class ProcessTaskEvent implements Serializable {
*/
private String businessKey;
public ProcessTaskEvent() {
super(new Object(), SpringUtils.getApplicationName(), DEFAULT_DESTINATION_FACTORY.getDestination(null));
}
}

@ -43,6 +43,7 @@
<module>ruoyi-common-websocket</module>
<module>ruoyi-common-social</module>
<module>ruoyi-common-nacos</module>
<module>ruoyi-common-bus</module>
</modules>
<artifactId>ruoyi-common</artifactId>

@ -224,6 +224,12 @@
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-bus</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

@ -0,0 +1,30 @@
<?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>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ruoyi-common-bus</artifactId>
<description>
ruoyi-common-bus 模块
</description>
<dependencies>
<!-- rabbitmq -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<!-- kafka -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-bus-kafka</artifactId>-->
<!-- </dependency>-->
</dependencies>
</project>

@ -0,0 +1,15 @@
package org.dromara.common.bus.config;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan;
/**
* bus
*
* @author Lion Li
*/
@AutoConfiguration
@RemoteApplicationEventScan(basePackages = "${spring.cloud.bus.base-packages}")
public class BusCustomConfiguration {
}

@ -69,7 +69,7 @@ public class WebSocketUtils {
broadcastMessage.setMessage(webSocketMessage.getMessage());
broadcastMessage.setSessionKeys(unsentSessionKeys);
RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> {
log.info(" WebSocket发送主题订阅消息topic:{} session keys:{} message:{}",
log.info("WebSocket发送主题订阅消息topic:{} session keys:{} message:{}",
WEB_SOCKET_TOPIC, unsentSessionKeys, webSocketMessage.getMessage());
});
}

@ -103,6 +103,12 @@
<artifactId>ruoyi-common-sensitive</artifactId>
</dependency>
<!-- 测试消息总线使用 搭配 TestBusController -->
<!-- <dependency>-->
<!-- <groupId>org.dromara</groupId>-->
<!-- <artifactId>ruoyi-api-workflow</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

@ -0,0 +1,31 @@
package org.dromara.demo.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 线
* <p>
* pom ruoyi-api-workflow
*
*
* @author Lion Li
*/
@Slf4j
@RestController
@RequestMapping("/bus")
public class TestBusController {
// @EventListener(condition = "#processEvent.key.startsWith('leave')")
// public void processHandler(ProcessEvent processEvent) {
// log.info(processEvent.toString());
// }
//
// @EventListener(condition = "#processTaskEvent.key=='leave1' && #processTaskEvent.taskDefinitionKey=='Activity_14633hx'")
// public void processTaskHandler(ProcessTaskEvent processTaskEvent) {
// log.info(processTaskEvent.toString());
// }
}
Loading…
Cancel
Save