diff --git a/config/nacos/application-common.yml b/config/nacos/application-common.yml index 29cd9b3f..8249270b 100644 --- a/config/nacos/application-common.yml +++ b/config/nacos/application-common.yml @@ -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: diff --git a/ruoyi-api/ruoyi-api-workflow/pom.xml b/ruoyi-api/ruoyi-api-workflow/pom.xml index 5e9df772..45c32d06 100644 --- a/ruoyi-api/ruoyi-api-workflow/pom.xml +++ b/ruoyi-api/ruoyi-api-workflow/pom.xml @@ -22,6 +22,10 @@ org.dromara ruoyi-common-core + + org.dromara + ruoyi-common-bus + diff --git a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessEvent.java b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessEvent.java index 5b7b121f..67d41bbb 100644 --- a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessEvent.java +++ b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessEvent.java @@ -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)); + } + } diff --git a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessTaskEvent.java b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessTaskEvent.java index 75a4cf39..73e972bc 100644 --- a/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessTaskEvent.java +++ b/ruoyi-api/ruoyi-api-workflow/src/main/java/org/dromara/workflow/api/domain/event/ProcessTaskEvent.java @@ -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)); + } } diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 204db8dd..ff6f5581 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -43,6 +43,7 @@ ruoyi-common-websocket ruoyi-common-social ruoyi-common-nacos + ruoyi-common-bus ruoyi-common diff --git a/ruoyi-common/ruoyi-common-bom/pom.xml b/ruoyi-common/ruoyi-common-bom/pom.xml index 6ac85cd7..ec97ca72 100644 --- a/ruoyi-common/ruoyi-common-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-bom/pom.xml @@ -224,6 +224,12 @@ ${revision} + + org.dromara + ruoyi-common-bus + ${revision} + + diff --git a/ruoyi-common/ruoyi-common-bus/pom.xml b/ruoyi-common/ruoyi-common-bus/pom.xml new file mode 100644 index 00000000..d89de614 --- /dev/null +++ b/ruoyi-common/ruoyi-common-bus/pom.xml @@ -0,0 +1,30 @@ + + + + org.dromara + ruoyi-common + ${revision} + + 4.0.0 + + ruoyi-common-bus + + + ruoyi-common-bus 模块 + + + + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + + + + + + + + diff --git a/ruoyi-common/ruoyi-common-bus/src/main/java/org/dromara/common/bus/config/BusCustomConfiguration.java b/ruoyi-common/ruoyi-common-bus/src/main/java/org/dromara/common/bus/config/BusCustomConfiguration.java new file mode 100644 index 00000000..68423b4d --- /dev/null +++ b/ruoyi-common/ruoyi-common-bus/src/main/java/org/dromara/common/bus/config/BusCustomConfiguration.java @@ -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 { + +} diff --git a/ruoyi-common/ruoyi-common-bus/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/ruoyi-common/ruoyi-common-bus/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..3b5376e9 --- /dev/null +++ b/ruoyi-common/ruoyi-common-bus/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.dromara.common.bus.config.BusCustomConfiguration diff --git a/ruoyi-common/ruoyi-common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java b/ruoyi-common/ruoyi-common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java index b245117a..696ac3c5 100644 --- a/ruoyi-common/ruoyi-common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java +++ b/ruoyi-common/ruoyi-common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java @@ -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()); }); } diff --git a/ruoyi-example/ruoyi-demo/pom.xml b/ruoyi-example/ruoyi-demo/pom.xml index 1b359c06..f9ca57a6 100644 --- a/ruoyi-example/ruoyi-demo/pom.xml +++ b/ruoyi-example/ruoyi-demo/pom.xml @@ -103,6 +103,12 @@ ruoyi-common-sensitive + + + + + + org.springframework.boot spring-boot-starter-test diff --git a/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestBusController.java b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestBusController.java new file mode 100644 index 00000000..3d2fe3cc --- /dev/null +++ b/ruoyi-example/ruoyi-demo/src/main/java/org/dromara/demo/controller/TestBusController.java @@ -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; + + +/** + * 测试消息总线 + *

+ * 需要在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()); +// } + +}