[重大更新] 新增 ruoyi-common-bus 消息总线组件 基于MQ跨服务投递事件消息
parent
d28cdcd0e1
commit
9a27f42867
|
|
@ -85,6 +85,16 @@ spring:
|
||||||
# 控制台地址 从1.3.0开始使用 server-name 注册
|
# 控制台地址 从1.3.0开始使用 server-name 注册
|
||||||
# dashboard: localhost:8718
|
# 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通用配置 子服务可以自行配置进行覆盖
|
# redis通用配置 子服务可以自行配置进行覆盖
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,10 @@
|
||||||
<groupId>org.dromara</groupId>
|
<groupId>org.dromara</groupId>
|
||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dromara</groupId>
|
||||||
|
<artifactId>ruoyi-common-bus</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
package org.dromara.workflow.api.domain.event;
|
package org.dromara.workflow.api.domain.event;
|
||||||
|
|
||||||
import lombok.Data;
|
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.Serial;
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 总体流程监听
|
* 总体流程监听
|
||||||
*
|
*
|
||||||
* @author may
|
* @author may
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ProcessEvent implements Serializable {
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ProcessEvent extends RemoteApplicationEvent {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -37,4 +39,8 @@ public class ProcessEvent implements Serializable {
|
||||||
*/
|
*/
|
||||||
private boolean submit;
|
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;
|
package org.dromara.workflow.api.domain.event;
|
||||||
|
|
||||||
import lombok.Data;
|
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.Serial;
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流程办理监听
|
* 流程办理监听
|
||||||
*
|
*
|
||||||
* @author may
|
* @author may
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ProcessTaskEvent implements Serializable {
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ProcessTaskEvent extends RemoteApplicationEvent {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
@ -37,4 +39,7 @@ public class ProcessTaskEvent implements Serializable {
|
||||||
*/
|
*/
|
||||||
private String businessKey;
|
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-websocket</module>
|
||||||
<module>ruoyi-common-social</module>
|
<module>ruoyi-common-social</module>
|
||||||
<module>ruoyi-common-nacos</module>
|
<module>ruoyi-common-nacos</module>
|
||||||
|
<module>ruoyi-common-bus</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -224,6 +224,12 @@
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.dromara</groupId>
|
||||||
|
<artifactId>ruoyi-common-bus</artifactId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
</project>
|
</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 {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
org.dromara.common.bus.config.BusCustomConfiguration
|
||||||
|
|
@ -69,7 +69,7 @@ public class WebSocketUtils {
|
||||||
broadcastMessage.setMessage(webSocketMessage.getMessage());
|
broadcastMessage.setMessage(webSocketMessage.getMessage());
|
||||||
broadcastMessage.setSessionKeys(unsentSessionKeys);
|
broadcastMessage.setSessionKeys(unsentSessionKeys);
|
||||||
RedisUtils.publish(WEB_SOCKET_TOPIC, broadcastMessage, consumer -> {
|
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());
|
WEB_SOCKET_TOPIC, unsentSessionKeys, webSocketMessage.getMessage());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,12 @@
|
||||||
<artifactId>ruoyi-common-sensitive</artifactId>
|
<artifactId>ruoyi-common-sensitive</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 测试消息总线使用 搭配 TestBusController -->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.dromara</groupId>-->
|
||||||
|
<!-- <artifactId>ruoyi-api-workflow</artifactId>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<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…
Reference in New Issue