瀏覽代碼

:whale: send

渔民小镇 1 年之前
父節點
當前提交
51800c742f

+ 6 - 8
logic/a-logic-common/pom.xml

@@ -26,6 +26,12 @@
             <version>${project.parent.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.iohao.game</groupId>
+            <artifactId>light-game-room</artifactId>
+            <version>${ioGame.version}</version>
+        </dependency>
+
         <dependency>
             <groupId>com.iohao.game</groupId>
             <artifactId>light-domain-event</artifactId>
@@ -56,13 +62,5 @@
             <artifactId>javafaker</artifactId>
             <version>${javafaker.version}</version>
         </dependency>
-
-        <!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
-        <dependency>
-            <groupId>com.alibaba.fastjson2</groupId>
-            <artifactId>fastjson2</artifactId>
-            <version>${fastjson2.version}</version>
-        </dependency>
-
     </dependencies>
 </project>

+ 46 - 0
logic/a-logic-common/src/main/java/com/iohao/mmo/config/LogicServerCommandLineRunner.java

@@ -0,0 +1,46 @@
+/*
+ * ioGame
+ * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
+ * # iohao.com . 渔民小镇
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.iohao.mmo.config;
+
+import com.iohao.game.widget.light.domain.event.DomainEventContext;
+import com.iohao.game.widget.light.domain.event.DomainEventContextParam;
+import com.iohao.mmo.domain.event.send.CommonSendDomainEventHandler;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author 渔民小镇
+ * @date 2023-07-28
+ */
+@Component
+public class LogicServerCommandLineRunner implements CommandLineRunner {
+    @Override
+    public void run(String... args) {
+        extractedSend();
+    }
+
+    private static void extractedSend() {
+        // 领域事件上下文参数
+        DomainEventContextParam contextParam = new DomainEventContextParam();
+        contextParam.addEventHandler(new CommonSendDomainEventHandler());
+        // 启动事件驱动
+        var domainEventContext = new DomainEventContext(contextParam);
+        domainEventContext.startup();
+    }
+}

+ 5 - 8
logic/map-logic/src/main/java/com/iohao/mmo/map/send/MapSend.java → logic/a-logic-common/src/main/java/com/iohao/mmo/domain/event/send/CommonSend.java

@@ -16,23 +16,20 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-package com.iohao.mmo.map.send;
+package com.iohao.mmo.domain.event.send;
 
 import com.iohao.game.action.skeleton.core.flow.FlowContext;
 import com.iohao.game.widget.light.room.AbstractFlowContextSend;
 
 /**
+ * 通过的推送领域事件
+ *
  * @author 渔民小镇
  * @date 2023-07-27
  */
-public class MapSend extends AbstractFlowContextSend {
+public class CommonSend extends AbstractFlowContextSend {
 
-    public MapSend(FlowContext flowContext) {
+    public CommonSend(FlowContext flowContext) {
         super(flowContext);
     }
-
-    @Override
-    public void send() {
-        this.execute();
-    }
 }

+ 36 - 0
logic/a-logic-common/src/main/java/com/iohao/mmo/domain/event/send/CommonSendDomainEventHandler.java

@@ -0,0 +1,36 @@
+/*
+ * ioGame
+ * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
+ * # iohao.com . 渔民小镇
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.iohao.mmo.domain.event.send;
+
+import com.iohao.game.widget.light.domain.event.message.DomainEventHandler;
+import com.iohao.game.widget.light.room.AbstractFlowContextSend;
+
+/**
+ * 通过的推送领域事件消费者
+ *
+ * @author 渔民小镇
+ * @date 2023-07-28
+ */
+public class CommonSendDomainEventHandler implements DomainEventHandler<AbstractFlowContextSend> {
+    @Override
+    public void onEvent(AbstractFlowContextSend event, boolean endOfBatch) {
+        // 执行推送
+        event.execute();
+    }
+}

+ 0 - 6
logic/map-logic/pom.xml

@@ -32,12 +32,6 @@
             <version>${project.parent.version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>com.iohao.game</groupId>
-            <artifactId>light-game-room</artifactId>
-            <version>${ioGame.version}</version>
-        </dependency>
-
 
     </dependencies>
 </project>

+ 2 - 2
logic/map-logic/src/main/java/com/iohao/mmo/map/room/MapRoom.java

@@ -21,7 +21,7 @@ package com.iohao.mmo.map.room;
 import com.iohao.game.action.skeleton.core.flow.FlowContext;
 import com.iohao.game.widget.light.room.AbstractFlowContextSend;
 import com.iohao.game.widget.light.room.AbstractRoom;
-import com.iohao.mmo.map.send.MapSend;
+import com.iohao.mmo.domain.event.send.CommonSend;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.Setter;
@@ -41,6 +41,6 @@ public class MapRoom extends AbstractRoom {
     @Override
     @SuppressWarnings("unchecked")
     protected <T extends AbstractFlowContextSend> T createSend(FlowContext flowContext) {
-        return (T) new MapSend(flowContext);
+        return (T) new CommonSend(flowContext);
     }
 }