From e7e980a6276f2986564dfc0afaaf592c592b913b Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期一, 02 二月 2026 14:37:22 +0800
Subject: [PATCH] 1
---
/dev/null | 17 ---
zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/MessageListener.java | 49 +++++++++
zy-acs-hex/src/main/resources/application.yml | 27 +++++
zy-acs-hex/pom.xml | 55 ++++++++++
zy-acs-hex/src/main/java/com/zy/acs/hex/config/RabbitMQConfig.java | 106 +++++++++++++++++++++
zy-acs-hex/src/main/java/com/zy/acs/hex/HexApplication.java | 14 ++
zy-acs-hex/src/main/java/com/zy/acs/hex/config/MessageConverterConfig.java | 26 +++++
7 files changed, 275 insertions(+), 19 deletions(-)
diff --git a/zy-acs-hex/pom.xml b/zy-acs-hex/pom.xml
index 01cd777..e35f5e7 100644
--- a/zy-acs-hex/pom.xml
+++ b/zy-acs-hex/pom.xml
@@ -12,9 +12,60 @@
<artifactId>zy-acs-hex</artifactId>
<properties>
- <maven.compiler.source>17</maven.compiler.source>
- <maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <spring-boot.version>2.5.3</spring-boot.version>
+ <fastjson.version>1.2.58</fastjson.version>
</properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.zy</groupId>
+ <artifactId>acs-common</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+
+ <!-- SpringBoot Web -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <!-- SpringBoot RabbitMQ -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-amqp</artifactId>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+
+ <!-- Lombok -->
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>1.18.30</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>${fastjson.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>rcs-hex</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
diff --git a/zy-acs-hex/src/main/java/com/zy/Main.java b/zy-acs-hex/src/main/java/com/zy/Main.java
deleted file mode 100644
index 7fe4b6a..0000000
--- a/zy-acs-hex/src/main/java/com/zy/Main.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.zy;
-
-//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
-// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
-public class Main {
- public static void main(String[] args) {
- //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
- // to see how IntelliJ IDEA suggests fixing it.
- System.out.printf("Hello and welcome!");
-
- for (int i = 1; i <= 5; i++) {
- //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
- // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
- System.out.println("i = " + i);
- }
- }
-}
\ No newline at end of file
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/HexApplication.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/HexApplication.java
new file mode 100644
index 0000000..b69817d
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/HexApplication.java
@@ -0,0 +1,14 @@
+package com.zy.acs.hex;
+
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class HexApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(HexApplication.class, args);
+ }
+
+}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/config/MessageConverterConfig.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/config/MessageConverterConfig.java
new file mode 100644
index 0000000..8830925
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/config/MessageConverterConfig.java
@@ -0,0 +1,26 @@
+package com.zy.acs.hex.config;
+
+
+import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
+import org.springframework.amqp.support.converter.MessageConverter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 娑堟伅杞崲鍣ㄩ厤缃紝鐢ㄤ簬娑堟伅鐨勫簭鍒楀寲鍜屽弽搴忓垪鍖�
+ *
+ * @author ken
+ */
+@Configuration
+public class MessageConverterConfig {
+
+ /**
+ * 閰嶇疆Fastjson2娑堟伅杞崲鍣�
+ *
+ * @return 娑堟伅杞崲鍣�
+ */
+ @Bean
+ public MessageConverter fastJsonMessageConverter() {
+ return new Jackson2JsonMessageConverter();
+ }
+}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/config/RabbitMQConfig.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/config/RabbitMQConfig.java
new file mode 100644
index 0000000..9431ade
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/config/RabbitMQConfig.java
@@ -0,0 +1,106 @@
+package com.zy.acs.hex.config;
+
+
+import org.springframework.amqp.core.*;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+
+/**
+ * RabbitMQ鏍稿績閰嶇疆绫伙紝瀹氫箟浜ゆ崲鏈恒�侀槦鍒楀拰缁戝畾鍏崇郴
+ *
+ * @author ken
+ */
+@Configuration
+public class RabbitMQConfig {
+
+
+ // ========================== 涓婚妯″紡 ==========================
+ /**
+ * 涓婚浜ゆ崲鏈哄悕绉�
+ */
+ public static final String TOPIC_EXCHANGE = "rcs_topic_exchange";
+ /**
+ * 涓婚闃熷垪1锛堜笂琛岋級
+ */
+ public static final String TOPIC_QUEUE_UP = "TOPIC_QUEUE_UP";
+ /**
+ * 涓婚闃熷垪2锛堜笅琛岋級
+ */
+ public static final String TOPIC_QUEUE_DOWN = "TOPIC_QUEUE_DOWN";
+
+ // 灞炴�� 鏈嶅姟 浜嬩欢
+ //Properties, services, and events
+ /**
+ * 涓婅璺敱閿墠缂�,绗竴涓唬琛ㄨ澶囩紪鍙凤紝绗簩涓唬琛ㄧ被鍨�
+ */
+ public static final String ROUTING_KEY_UP = "rcs.up.*.*";
+ /**
+ * 涓嬭璺敱閿墠缂�,绗竴涓唬琛ㄨ澶囩紪鍙凤紝绗簩涓唬琛ㄧ被鍨�
+ */
+ public static final String ROUTING_KEY_DOWN = "rcs.down.*.*";
+
+
+ /**
+ * 鍒涘缓涓婚浜ゆ崲鏈�
+ *
+ * @return 浜ゆ崲鏈哄疄渚�
+ */
+// @Bean
+// public TopicExchange topicExchange() {
+// return new TopicExchange(TOPIC_EXCHANGE, true, false);
+// }
+
+// /**
+// * 鍒涘缓涓婅涓婚闃熷垪
+// *
+// * @return 闃熷垪瀹炰緥
+// */
+// @Bean
+// public Queue topicQueueUp() {
+// return QueueBuilder.durable(TOPIC_QUEUE_UP)
+// .autoDelete()
+// .exclusive()
+// .build();
+// }
+//
+// /**
+// * 鍒涘缓涓嬭涓婚闃熷垪
+// *
+// * @return 闃熷垪瀹炰緥
+// */
+// @Bean
+// public Queue topicQueueDown() {
+// return QueueBuilder.durable(TOPIC_QUEUE_DOWN)
+// .exclusive()
+// .build();
+// }
+//
+//
+//
+// /**
+// * 缁戝畾涓婅闃熷垪鍒颁富棰樹氦鎹㈡満
+// *
+// * @return 缁戝畾鍏崇郴
+// */
+// @Bean
+// public Binding topicBindingOrder() {
+// return BindingBuilder.bind(topicQueueUp())
+// .to(topicExchange())
+// .with(ROUTING_KEY_UP);
+// }
+//
+// /**
+// * 缁戝畾涓嬭闃熷垪鍒颁富棰樹氦鎹㈡満
+// *
+// * @return 缁戝畾鍏崇郴
+// */
+// @Bean
+// public Binding topicBindingUser() {
+// return BindingBuilder.bind(topicQueueDown())
+// .to(topicExchange())
+// .with(ROUTING_KEY_DOWN);
+// }
+
+
+}
\ No newline at end of file
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/MessageListener.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/MessageListener.java
new file mode 100644
index 0000000..2068ce9
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/MessageListener.java
@@ -0,0 +1,49 @@
+package com.zy.acs.hex.consumer;
+
+import com.zy.acs.hex.config.RabbitMQConfig;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Exchange;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.QueueBinding;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.support.AmqpHeaders;
+import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+
+/**
+ * 娑堣垂鑰�
+ */
+@Slf4j
+@Component
+public class MessageListener {
+
+ public static final String durable = "true";
+
+ @RabbitListener(bindings = @QueueBinding(
+ value = @Queue(name = RabbitMQConfig.TOPIC_QUEUE_UP, durable = durable),
+ exchange = @Exchange(name = RabbitMQConfig.TOPIC_EXCHANGE),
+ key = RabbitMQConfig.ROUTING_KEY_UP
+ ))
+ public void receiveFromUpData(Message message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, RabbitProperties.Cache.Channel channel) throws IOException {
+ log.info("receive message: {}" + "msgId:" + message.getMessageProperties().getMessageId());
+ // 杩涘叆娑堟伅娑堣垂涓氬姟閫昏緫銆�
+ System.out.println("鏀跺埌娑堟伅锛�" + new String(message.getBody()));
+
+ }
+
+ @RabbitListener(bindings = @QueueBinding(
+ value = @Queue(name = RabbitMQConfig.TOPIC_QUEUE_DOWN, durable = durable),
+ exchange = @Exchange(name = RabbitMQConfig.TOPIC_EXCHANGE),
+ key = RabbitMQConfig.ROUTING_KEY_DOWN
+ ))
+ public void receiveFromDownData(Message message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, RabbitProperties.Cache.Channel channel) throws IOException {
+ log.info("receive message: {}" + "msgId:" + message.getMessageProperties().getMessageId());
+ // 杩涘叆娑堟伅娑堣垂涓氬姟閫昏緫銆�
+ System.out.println("鏀跺埌娑堟伅锛�" + new String(message.getBody()));
+
+ }
+}
diff --git a/zy-acs-hex/src/main/resources/application.yml b/zy-acs-hex/src/main/resources/application.yml
new file mode 100644
index 0000000..4f44d2f
--- /dev/null
+++ b/zy-acs-hex/src/main/resources/application.yml
@@ -0,0 +1,27 @@
+
+spring:
+ application:
+ name: rcs-hex
+ # RabbitMQ閰嶇疆
+ rabbitmq:
+ host: localhost
+ port: 5672
+ username: admin
+ password: 123456
+ virtual-host: /
+ # 鐢熶骇鑰呯‘璁ら厤缃�
+ publisher-confirm-type: correlated
+ publisher-returns: true
+ # 娑堣垂鑰呴厤缃�
+ listener:
+ simple:
+ # 鎵嬪姩纭妯″紡
+ acknowledge-mode: manual
+ # 娑堣垂鑰呯嚎绋嬫暟
+ concurrency: 1
+ # 鏈�澶ф秷璐硅�呯嚎绋嬫暟
+ max-concurrency: 5
+ # 姣忔浠庨槦鍒椾腑鑾峰彇鐨勬秷鎭暟閲�
+ prefetch: 1
+ direct:
+ acknowledge-mode: manual
--
Gitblit v1.9.1