From 692c1a185d768a18c2007348806d775b2fbdeaa7 Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期五, 23 二月 2024 09:45:19 +0800
Subject: [PATCH] 增加MQ 示例
---
springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java | 106 ++++++
springboot-vue3/springboot-vue3.iml | 13
springboot-vue3/.idea/libraries/Maven__org_springframework_retry_spring_retry_1_2_5_RELEASE.xml | 13
springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java | 160 ++------
springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_0.xml | 24
springboot-vue3/pom.xml | 32 +
springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_0.xml | 24
springboot-vue3/src/main/java/com/example/springboot/controller/MessageController.java | 55 +++
springboot-vue3/src/main/java/com/example/springboot/common/MessageSender.java | 45 ++
springboot-vue3/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_amqp_2_3_2_RELEASE.xml | 13
springboot-vue3/src/main/java/com/example/springboot/component/MessageQueueReader.java | 47 ++
springboot-vue3/src/main/java/com/example/springboot/common/MessageReceiver.java | 37 ++
springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java | 2
springboot-vue3/src/main/java/com/example/springboot/component/ModuleB.java | 27 +
springboot-vue3/src/main/java/com/example/springboot/common/RabbitConfig.java | 67 +++
springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_rabbit_2_2_9_RELEASE.xml | 13
springboot-vue3/src/main/java/com/example/springboot/component/ModuleA.java | 46 ++
springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_0.xml | 24
springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java | 48 +-
springboot-vue3/.idea/libraries/Maven__com_rabbitmq_amqp_client_5_13_1.xml | 13
springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_amqp_2_2_9_RELEASE.xml | 13
springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java | 87 +++-
springboot-vue3/src/main/resources/application.properties | 6
springboot-vue3/src/main/java/com/example/springboot/component/PLCAutomaticParameterSettingReview2.java | 48 +
springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java | 11
25 files changed, 754 insertions(+), 220 deletions(-)
diff --git a/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_11_1.xml b/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_0.xml
similarity index 67%
rename from springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_11_1.xml
rename to springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_0.xml
index 3aa8175..3b442a5 100644
--- a/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_11_1.xml
+++ b/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_13_0.xml
@@ -1,13 +1,13 @@
-<component name="libraryTable">
- <library name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.1">
- <CLASSES>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.11.1/jackson-annotations-2.11.1.jar!/" />
- </CLASSES>
- <JAVADOC>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.11.1/jackson-annotations-2.11.1-javadoc.jar!/" />
- </JAVADOC>
- <SOURCES>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.11.1/jackson-annotations-2.11.1-sources.jar!/" />
- </SOURCES>
- </library>
+<component name="libraryTable">
+ <library name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.13.0">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.13.0/jackson-annotations-2.13.0.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.13.0/jackson-annotations-2.13.0-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.13.0/jackson-annotations-2.13.0-sources.jar!/" />
+ </SOURCES>
+ </library>
</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_11_1.xml b/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_0.xml
similarity index 67%
rename from springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_11_1.xml
rename to springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_0.xml
index bd0d979..14a2ac5 100644
--- a/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_11_1.xml
+++ b/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_13_0.xml
@@ -1,13 +1,13 @@
-<component name="libraryTable">
- <library name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.1">
- <CLASSES>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.11.1/jackson-core-2.11.1.jar!/" />
- </CLASSES>
- <JAVADOC>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.11.1/jackson-core-2.11.1-javadoc.jar!/" />
- </JAVADOC>
- <SOURCES>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.11.1/jackson-core-2.11.1-sources.jar!/" />
- </SOURCES>
- </library>
+<component name="libraryTable">
+ <library name="Maven: com.fasterxml.jackson.core:jackson-core:2.13.0">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.13.0/jackson-core-2.13.0.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.13.0/jackson-core-2.13.0-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.13.0/jackson-core-2.13.0-sources.jar!/" />
+ </SOURCES>
+ </library>
</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_11_1.xml b/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_0.xml
similarity index 66%
rename from springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_11_1.xml
rename to springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_0.xml
index 08c0010..351a7a9 100644
--- a/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_11_1.xml
+++ b/springboot-vue3/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_13_0.xml
@@ -1,13 +1,13 @@
-<component name="libraryTable">
- <library name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.1">
- <CLASSES>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.11.1/jackson-databind-2.11.1.jar!/" />
- </CLASSES>
- <JAVADOC>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.11.1/jackson-databind-2.11.1-javadoc.jar!/" />
- </JAVADOC>
- <SOURCES>
- <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.11.1/jackson-databind-2.11.1-sources.jar!/" />
- </SOURCES>
- </library>
+<component name="libraryTable">
+ <library name="Maven: com.fasterxml.jackson.core:jackson-databind:2.13.0">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.13.0/jackson-databind-2.13.0.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.13.0/jackson-databind-2.13.0-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.13.0/jackson-databind-2.13.0-sources.jar!/" />
+ </SOURCES>
+ </library>
</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__com_rabbitmq_amqp_client_5_13_1.xml b/springboot-vue3/.idea/libraries/Maven__com_rabbitmq_amqp_client_5_13_1.xml
new file mode 100644
index 0000000..2f88086
--- /dev/null
+++ b/springboot-vue3/.idea/libraries/Maven__com_rabbitmq_amqp_client_5_13_1.xml
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: com.rabbitmq:amqp-client:5.13.1">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/rabbitmq/amqp-client/5.13.1/amqp-client-5.13.1.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/rabbitmq/amqp-client/5.13.1/amqp-client-5.13.1-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/rabbitmq/amqp-client/5.13.1/amqp-client-5.13.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_amqp_2_2_9_RELEASE.xml b/springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_amqp_2_2_9_RELEASE.xml
new file mode 100644
index 0000000..fbc85ec
--- /dev/null
+++ b/springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_amqp_2_2_9_RELEASE.xml
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: org.springframework.amqp:spring-amqp:2.2.9.RELEASE">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-amqp/2.2.9.RELEASE/spring-amqp-2.2.9.RELEASE.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-amqp/2.2.9.RELEASE/spring-amqp-2.2.9.RELEASE-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-amqp/2.2.9.RELEASE/spring-amqp-2.2.9.RELEASE-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_rabbit_2_2_9_RELEASE.xml b/springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_rabbit_2_2_9_RELEASE.xml
new file mode 100644
index 0000000..84deb37
--- /dev/null
+++ b/springboot-vue3/.idea/libraries/Maven__org_springframework_amqp_spring_rabbit_2_2_9_RELEASE.xml
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: org.springframework.amqp:spring-rabbit:2.2.9.RELEASE">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-rabbit/2.2.9.RELEASE/spring-rabbit-2.2.9.RELEASE.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-rabbit/2.2.9.RELEASE/spring-rabbit-2.2.9.RELEASE-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/amqp/spring-rabbit/2.2.9.RELEASE/spring-rabbit-2.2.9.RELEASE-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_amqp_2_3_2_RELEASE.xml b/springboot-vue3/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_amqp_2_3_2_RELEASE.xml
new file mode 100644
index 0000000..c3c5c57
--- /dev/null
+++ b/springboot-vue3/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_amqp_2_3_2_RELEASE.xml
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: org.springframework.boot:spring-boot-starter-amqp:2.3.2.RELEASE">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-amqp/2.3.2.RELEASE/spring-boot-starter-amqp-2.3.2.RELEASE.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-amqp/2.3.2.RELEASE/spring-boot-starter-amqp-2.3.2.RELEASE-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-amqp/2.3.2.RELEASE/spring-boot-starter-amqp-2.3.2.RELEASE-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
diff --git a/springboot-vue3/.idea/libraries/Maven__org_springframework_retry_spring_retry_1_2_5_RELEASE.xml b/springboot-vue3/.idea/libraries/Maven__org_springframework_retry_spring_retry_1_2_5_RELEASE.xml
new file mode 100644
index 0000000..c246014
--- /dev/null
+++ b/springboot-vue3/.idea/libraries/Maven__org_springframework_retry_spring_retry_1_2_5_RELEASE.xml
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: org.springframework.retry:spring-retry:1.2.5.RELEASE">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/retry/spring-retry/1.2.5.RELEASE/spring-retry-1.2.5.RELEASE.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/retry/spring-retry/1.2.5.RELEASE/spring-retry-1.2.5.RELEASE-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/springframework/retry/spring-retry/1.2.5.RELEASE/spring-retry-1.2.5.RELEASE-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
diff --git a/springboot-vue3/pom.xml b/springboot-vue3/pom.xml
index 04328bd..916560c 100644
--- a/springboot-vue3/pom.xml
+++ b/springboot-vue3/pom.xml
@@ -144,6 +144,38 @@
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
+
+ <dependency>
+ <groupId>com.rabbitmq</groupId>
+ <artifactId>amqp-client</artifactId>
+ <version>5.13.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-amqp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.12.2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.13.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.13.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.13.0</version>
+ </dependency>
</dependencies>
<build>
diff --git a/springboot-vue3/springboot-vue3.iml b/springboot-vue3/springboot-vue3.iml
index 473e79f..3457dde 100644
--- a/springboot-vue3/springboot-vue3.iml
+++ b/springboot-vue3/springboot-vue3.iml
@@ -93,9 +93,6 @@
<orderEntry type="library" name="Maven: io.jsonwebtoken:jjwt-api:0.10.7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.jsonwebtoken:jjwt-impl:0.10.7" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: io.jsonwebtoken:jjwt-jackson:0.10.7" level="project" />
- <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.1" level="project" />
- <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.1" level="project" />
- <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-spring-boot-starter:1.8.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-spring:1.8.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.shiro:shiro-core:1.8.0" level="project" />
@@ -117,7 +114,6 @@
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.3.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.2.8.RELEASE" level="project" />
- <orderEntry type="library" name="Maven: org.springframework:spring-tx:5.2.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-core:3.2.0" level="project" />
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-annotation:3.2.0" level="project" />
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:2.1" level="project" />
@@ -183,5 +179,14 @@
<orderEntry type="library" name="Maven: org.springframework:spring-websocket:5.2.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: com.github.xingshuangs:iot-communication:1.4.2" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.9" level="project" />
+ <orderEntry type="library" name="Maven: com.rabbitmq:amqp-client:5.13.1" level="project" />
+ <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-amqp:2.3.2.RELEASE" level="project" />
+ <orderEntry type="library" name="Maven: org.springframework.amqp:spring-rabbit:2.2.9.RELEASE" level="project" />
+ <orderEntry type="library" name="Maven: org.springframework.amqp:spring-amqp:2.2.9.RELEASE" level="project" />
+ <orderEntry type="library" name="Maven: org.springframework.retry:spring-retry:1.2.5.RELEASE" level="project" />
+ <orderEntry type="library" name="Maven: org.springframework:spring-tx:5.2.8.RELEASE" level="project" />
+ <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.13.0" level="project" />
+ <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.13.0" level="project" />
+ <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.13.0" level="project" />
</component>
</module>
\ No newline at end of file
diff --git a/springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java b/springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java
index e56023f..313f463 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/AuthorityApplication.java
@@ -1,10 +1,14 @@
package com.example.springboot;
+import com.example.springboot.common.MessageSender;
+import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import com.example.springboot.component.*;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@@ -17,6 +21,13 @@
SpringApplication springApplication = new SpringApplication(AuthorityApplication.class);
ConfigurableApplicationContext configurableApplicationContext = springApplication.run(args);
WebSocketServer.setApplicationContext(configurableApplicationContext);
+
+
+
+
+
+
+
}
}
diff --git a/springboot-vue3/src/main/java/com/example/springboot/common/MessageReceiver.java b/springboot-vue3/src/main/java/com/example/springboot/common/MessageReceiver.java
new file mode 100644
index 0000000..1274235
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/common/MessageReceiver.java
@@ -0,0 +1,37 @@
+package com.example.springboot.common;
+
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.amqp.support.AmqpHeaders;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+import com.rabbitmq.client.Channel;
+import java.io.IOException;
+
+
+@Component
+public class MessageReceiver {
+
+ @RabbitListener(queues = RabbitConfig.QUEUE_NAME)
+ public void receiveMessage(String message) {
+ System.out.println("Received message: " + message);
+
+ // 鎵嬪姩纭娑堟伅
+ //channel.basicAck(deliveryTag, false);
+ }
+
+ @RabbitListener(queues = RabbitConfig.SECOND_QUEUE_NAME)
+ public void receiveMessage2(MessageSender.Person person) {
+ // 瀵规帴鏀跺埌鐨凱erson瀵硅薄杩涜澶勭悊
+ String name = person.getName();
+ int age = person.getAge();
+
+
+ System.out.println("Received Person message: " + name +age);
+ }
+
+
+
+}
+
diff --git a/springboot-vue3/src/main/java/com/example/springboot/common/MessageSender.java b/springboot-vue3/src/main/java/com/example/springboot/common/MessageSender.java
new file mode 100644
index 0000000..f535bca
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/common/MessageSender.java
@@ -0,0 +1,45 @@
+package com.example.springboot.common;
+
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.io.Serializable;
+
+@Component
+public class MessageSender {
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ public void sendMessage(String message) {
+ rabbitTemplate.convertAndSend(RabbitConfig.DIRECT_EXCHANGE_NAME, RabbitConfig.ROUTING_KEY, message);
+ System.out.println("send message: " + message);
+ }
+
+ public void sendMessage2(Person person) {
+ rabbitTemplate.convertAndSend(RabbitConfig.DIRECT_EXCHANGE_NAME, RabbitConfig.SECOND_ROUTING_KEY, person);
+ }
+
+ public static class Person implements Serializable {
+ private String name;
+ private int age;
+
+ public Person(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ // getter鍜宻etter鏂规硶鐪佺暐
+ }
+
+}
+
diff --git a/springboot-vue3/src/main/java/com/example/springboot/common/RabbitConfig.java b/springboot-vue3/src/main/java/com/example/springboot/common/RabbitConfig.java
new file mode 100644
index 0000000..47dd93f
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/common/RabbitConfig.java
@@ -0,0 +1,67 @@
+package com.example.springboot.common;
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.DirectExchange;
+import org.springframework.amqp.core.Queue;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RabbitConfig {
+
+ // 瀹氫箟浜ゆ崲鏈哄悕绉�
+ public static final String DIRECT_EXCHANGE_NAME = "direct.exchange";
+ // 瀹氫箟闃熷垪鍚嶇О
+ public static final String QUEUE_NAME = "canadames";
+ // 瀹氫箟璺敱閿�
+ public static final String ROUTING_KEY = "message.routingKey";
+ // 瀹氫箟绗簩涓槦鍒楀悕绉�
+ public static final String SECOND_QUEUE_NAME = "anotherQueue";
+ // 瀹氫箟绗簩涓矾鐢遍敭
+ public static final String SECOND_ROUTING_KEY = "another.routingKey";
+
+ // 瀹氫箟浜ゆ崲鏈�
+
+ // 鐩磋繛浜ゆ崲鏈猴紙Direct Exchange锛夛細鐩磋繛浜ゆ崲鏈烘槸鏈�绠�鍗曠殑涓�绉嶄氦鎹㈡満绫诲瀷銆傚畠鏍规嵁娑堟伅鐨勮矾鐢遍敭锛圧outing Key锛夊皢娑堟伅鍙戦�佸埌涓庝箣瀹屽叏鍖归厤鐨勯槦鍒椼��
+ // 涓婚浜ゆ崲鏈猴紙Topic Exchange锛夛細涓婚浜ゆ崲鏈哄厑璁搁�氳繃浣跨敤閫氶厤绗︾殑鏂瑰紡鏉ヨ繘琛屾秷鎭殑璺敱銆傚畠灏嗘秷鎭牴鎹尮閰嶇殑瑙勫垯锛堥�氶厤绗︼級鍙戦�佸埌涓�涓垨澶氫釜闃熷垪涓�
+ //鎵囧舰浜ゆ崲鏈猴紙Fanout Exchange锛夛細鎵囧舰浜ゆ崲鏈轰細灏嗘敹鍒扮殑鎵�鏈夋秷鎭箍鎾埌鎵�鏈夌粦瀹氱殑闃熷垪涓娿�傚畠蹇界暐娑堟伅鐨勮矾鐢遍敭锛屽彧闇�灏嗘秷鎭彂閫佺粰鎵�鏈夌粦瀹氱殑闃熷垪銆�
+ @Bean
+ public DirectExchange directExchange() {
+ return new DirectExchange(DIRECT_EXCHANGE_NAME);
+ }
+
+ // 瀹氫箟闃熷垪
+ @Bean
+ public Queue queue() {
+ return new Queue(QUEUE_NAME);
+ }
+
+ // 瀹氫箟绗簩涓槦鍒�
+ @Bean
+ public Queue secondQueue() {
+ return new Queue(SECOND_QUEUE_NAME);
+ }
+
+//绗簩涓弬鏁拌〃绀洪槦鍒楁槸鍚︿负鎸佷箙鍖栫殑锛屽鏋滀綘鎯宠鍒涘缓涓�涓寔涔呭寲鐨勯槦鍒楋紝鍙互灏嗚鍙傛暟璁剧疆涓� true銆�
+// 鎸佷箙鍖栭槦鍒楀彲浠ュ湪 RabbitMQ 鏈嶅姟鍣ㄩ噸鍚悗缁х画瀛樺湪锛屼互闃叉娑堟伅涓㈠け銆�
+ //绗笁涓弬鏁� exclusive 璁剧疆涓� false锛岃〃绀洪槦鍒楅潪鎺掍粬鎬э紱
+ // 灏嗙鍥涗釜鍙傛暟 autoDelete 璁剧疆涓� false锛岃〃绀洪槦鍒椾笉浼氳嚜鍔ㄥ垹闄わ紱
+ // 灏嗙浜斾釜鍙傛暟 arguments 璁剧疆涓� null锛岃〃绀轰笉鎸囧畾鍏朵粬鍙傛暟銆�
+// @Bean
+// public Queue queue() {
+// return new Queue(QUEUE_NAME, false, false, false, null);
+// }
+
+ // 灏嗛槦鍒楃粦瀹氬埌浜ゆ崲鏈轰笂锛屽苟鎸囧畾璺敱閿�
+ @Bean
+ public Binding binding() {
+ return BindingBuilder.bind(queue()).to(directExchange()).with(ROUTING_KEY);
+ }
+
+ // 灏嗙浜屼釜闃熷垪缁戝畾鍒颁氦鎹㈡満涓婏紝骞舵寚瀹氱浜屼釜璺敱閿�
+ @Bean
+ public Binding secondBinding() {
+ return BindingBuilder.bind(secondQueue()).to(directExchange()).with(SECOND_ROUTING_KEY);
+ }
+}
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java b/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java
index a361cef..d8311d6 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/ExcelToJsonConverter.java
@@ -90,6 +90,8 @@
}
}
+
+
private static String extractAddressIndex(String address) {
// Assuming the address format is "DB103.DBW0" or "DB103.DBB100~DBB113"
if (address.startsWith("DB") && address.contains(".DBW")) {
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/MessageQueueReader.java b/springboot-vue3/src/main/java/com/example/springboot/component/MessageQueueReader.java
new file mode 100644
index 0000000..da7ce81
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/MessageQueueReader.java
@@ -0,0 +1,47 @@
+package com.example.springboot.component;
+
+import com.rabbitmq.client.*;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class MessageQueueReader {
+
+ private static final String QUEUE_NAME = "hangzhoumes";
+
+ public static void main(String[] args) throws Exception {
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+
+ List<String> messages = new ArrayList<>();
+
+ try (Connection connection = factory.newConnection();
+ Channel channel = connection.createChannel()) {
+ boolean autoAck = false;
+ // autoAck 鍙傛暟璁剧疆涓� false锛岀劧鍚庢墜鍔ㄧ‘璁ゆ秷鎭鐞嗗畬鎴�
+ // 寰幆鑾峰彇闃熷垪涓殑鎵�鏈夋秷鎭�
+// while (true) {
+ GetResponse response = channel.basicGet(QUEUE_NAME, autoAck);
+
+ if (response != null) {
+ String message = new String(response.getBody(), "UTF-8");
+ messages.add(message);
+
+ // 鎵嬪姩纭娑堟伅澶勭悊瀹屾垚
+ long deliveryTag = response.getEnvelope().getDeliveryTag();
+ channel.basicAck(deliveryTag, false);
+// } else {
+// // 濡傛灉闃熷垪涓虹┖锛屽垯閫�鍑哄惊鐜�
+// break;
+// }
+ }
+ }
+
+ // 鎵撳嵃鎵�鏈夋秷鎭唴瀹�
+ for (String message : messages) {
+ System.out.println("Received message: " + message);
+ }
+ }
+}
+
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/ModuleA.java b/springboot-vue3/src/main/java/com/example/springboot/component/ModuleA.java
new file mode 100644
index 0000000..5a3d2f9
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/ModuleA.java
@@ -0,0 +1,46 @@
+package com.example.springboot.component;
+
+import com.rabbitmq.client.*;
+
+public class ModuleA {
+ private final static String QUEUE_NAME = "hangzhoumes";
+
+ public static void main(String[] argv) throws Exception {
+ // 鍒涘缓杩炴帴宸ュ巶
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+
+ try (Connection connection = factory.newConnection();
+ //channel 鏄�氳繃 connection 鍒涘缓鐨勪竴涓� AMQP 淇¢亾瀵硅薄
+ Channel channel = connection.createChannel()) {
+ // `channel.queueDeclare(QUEUE_NAME, false, false, false, null);` 鏄敤鏉ュ0鏄庝竴涓槦鍒楃殑鏂规硶
+ //璇ユ柟娉曟湁浜斾釜鍙傛暟锛�
+ //1. `QUEUE_NAME`锛氭寚瀹氶槦鍒楃殑鍚嶇О锛岃繖閲屼娇鐢ㄤ簡涔嬪墠澹版槑鐨勫父閲廯"module_queue"`浣滀负闃熷垪鍚嶇О銆�
+ //2. `false`锛氭寚瀹氶槦鍒楁槸鍚︿负鎸佷箙鍖栫殑銆傚湪杩欓噷璁剧疆涓篳false`锛岃〃绀轰笉灏嗛槦鍒楁寔涔呭寲鍒扮鐩橈紝涓�鏃abbitMQ鏈嶅姟鍋滄鎴栧穿婧冿紝闃熷垪灏嗕細涓㈠け銆�
+ //3. `false`锛氭寚瀹氭槸鍚﹀彧鍏佽褰撳墠杩炴帴澹版槑姝ら槦鍒椼�傚湪杩欓噷璁剧疆涓篳false`锛岃〃绀哄彲鍏佽鍏朵粬杩炴帴涔熷0鏄庡悓鍚嶇殑闃熷垪銆�
+ //4. `false`锛氭寚瀹氭槸鍚﹀湪涓嶅啀浣跨敤鏃惰嚜鍔ㄥ垹闄ら槦鍒椼�傚湪杩欓噷璁剧疆涓篳false`锛岃〃绀哄綋娌℃湁娑堣垂鑰呮垨鑰呮墍鏈夋秷璐硅�呮柇寮�杩炴帴鍚庯紝闃熷垪涓嶄細鑷姩鍒犻櫎銆�
+ //5. `null`锛氭寚瀹氬叾浠栭槦鍒楀睘鎬х殑鍙傛暟銆傚湪杩欓噷璁剧疆涓篳null`锛岃〃绀烘病鏈夊叾浠栧睘鎬ч渶瑕佽缃��
+ //鎵ц`channel.queueDeclare()`鏂规硶鍚庯紝濡傛灉闃熷垪涓嶅瓨鍦紝灏嗕細鍒涘缓涓�涓柊鐨勯槦鍒楋紝濡傛灉闃熷垪宸茬粡瀛樺湪锛屽垯涓嶅仛浠讳綍鎿嶄綔銆�
+ channel.queueDeclare(QUEUE_NAME, false, false, false, null);
+
+
+
+ String message = "浣犲ソ妯″潡A2";
+
+ for ( int i=1;i< 10000;i++)
+ {
+ message+="浣犲ソ妯″潡A2";
+
+ }
+
+ message+="b";
+
+
+
+ // 灏嗘秷鎭彂甯冨埌鎸囧畾鐨勯槦鍒椾腑銆傜┖瀛楃涓�""琛ㄧず榛樿鐨勪氦鎹㈡満锛孮UEUE_NAME鎸囧畾浜嗙洰鏍囬槦鍒楀悕绉帮紝null琛ㄧず娌℃湁鎸囧畾鍏朵粬灞炴�э紝message.getBytes()灏嗘秷鎭唴瀹硅浆鎹负瀛楄妭鏁扮粍杩涜浼犺緭銆�
+ channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
+ System.out.println(" [x] Sent '" + message + "'");
+ }
+ }
+}
+
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/ModuleB.java b/springboot-vue3/src/main/java/com/example/springboot/component/ModuleB.java
new file mode 100644
index 0000000..e4d6b44
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/ModuleB.java
@@ -0,0 +1,27 @@
+package com.example.springboot.component;
+
+import com.rabbitmq.client.*;
+
+public class ModuleB {
+ private final static String QUEUE_NAME = "hangzhoumes";
+
+ public static void main(String[] argv) throws Exception {
+ // 鍒涘缓杩炴帴宸ュ巶
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+ try (Connection connection = factory.newConnection();
+ Channel channel = connection.createChannel()) {
+ // 澹版槑闃熷垪
+ channel.queueDeclare(QUEUE_NAME, false, false, false, null);
+ // 鍒涘缓娑堣垂鑰�
+ DeliverCallback deliverCallback = (consumerTag, delivery) -> {
+ String receivedMessage = new String(delivery.getBody(), "UTF-8");
+ System.out.println(" [x] Received '" + receivedMessage + "'");
+ };
+ // 寮�濮嬫秷璐规秷鎭�
+ channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {
+ });
+ }
+ }
+}
+
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java b/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java
index 6e6ef8a..33a3c43 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutoMes.java
@@ -1,5 +1,11 @@
package com.example.springboot.component;
+
+
+
+
+import com.example.springboot.entity.device.PlcParameterObject;
+
import com.example.springboot.entity.device.PlcBitObject;
import com.example.springboot.entity.device.PlcParameterObject;
@@ -7,16 +13,16 @@
import java.util.ArrayList;
import java.util.List;
-import static com.example.springboot.component.InitUtil.readAndUpdateBitValues;
-import static com.example.springboot.component.InitUtil.readAndUpdateWordValues;
-
public class PLCAutoMes extends Thread {
// 鐢ㄤ簬瀛樺偍搴旂敤绋嬪簭鐨勯厤缃俊鎭�
private Configuration config;
private static InitUtil initUtil;
+ public static PlcParameterObject plcParameterObject;
// 鍒涘缓涓�涓嚜瀹氫箟鐨� S7 鎺у埗鍣ㄦ秷鎭鐞嗗櫒瀵硅薄
MessageHandler customS7Control = new MessageHandler();
+;
+
// 鍗曚緥瀹炰緥
private static PLCAutoMes instance;
@@ -44,43 +50,62 @@
} catch (InterruptedException e) {
e.printStackTrace();
}
-
-
-
- String jsonFilePath = PLCAutoMes.class.getResource("/JsonFile/PlcMes.json").getPath();
-
- String jsonFilePath2 = PLCAutoMes.class.getResource("/JsonFile/PlcRead.json").getPath();
- // String jsonFilePath3 = PLCAutoMes.class.getResource("/JsonFile/Plcframe.json").getPath();
- // System.out.println(jsonFilePath);
-
+ String jsonFilePath = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcParameter.json").getPath();
+ // String jsonFilePath2 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcSign.json").getPath();
+ //String jsonFilePath4 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcState.json").getPath();
+ //System.out.println(jsonFilePath4);
// 璋冪敤initword鏂规硶
- PlcParameterObject PlcMesObject= initUtil.initword(jsonFilePath);
- // 璋冪敤initbit鏂规硶
- PlcParameterObject PlcReadObject= initUtil.initword(jsonFilePath2);
+ plcParameterObject = initUtil.initword(jsonFilePath);
+
+// List<String> addresses = new ArrayList<>();
+// addresses.add("conveyorVelocity(AutoFAST)");
+// addresses.add("A02ID");
+// addresses.add("conveyorVelocity(Manual)");
+//
+// PlcParameterObject paramObject = PLCAutomaticParameterSettingReview2.plcParameterObject;
+//
+//
+//
+// List<String> address = paramObject.getAddressListByCodeId(addresses);
+// System.out.println(address);
+
+
+ //PLCAutomaticParameterSettingReview2 plc ;
+
+// String jsonFilePath = PLCAutoMes.class.getResource("/JsonFile/PlcMes.json").getPath();
+//
+// String jsonFilePath2 = PLCAutoMes.class.getResource("/JsonFile/PlcRead.json").getPath();
+// // String jsonFilePath3 = PLCAutoMes.class.getResource("/JsonFile/Plcframe.json").getPath();
+// // System.out.println(jsonFilePath);
+//
+// // 璋冪敤initword鏂规硶
+// PlcMesObject= initUtil.initword(jsonFilePath);
+// // 璋冪敤initbit鏂规硶
+// PlcParameterObject PlcReadObject= initUtil.initword(jsonFilePath2);
// // 璋冪敤initbit鏂规硶
// PlcParameterObject PlcframeObject= initUtil.initword(jsonFilePath3);
- readAndUpdateWordValues(PlcReadObject);
- readAndUpdateWordValues(PlcMesObject);
- // readAndUpdateWordValues(PlcframeObject);
+// readAndUpdateWordValues(PlcReadObject);
+// readAndUpdateWordValues(PlcMesObject);
+ // readAndUpdateWordValues(PlcframeObject);
// readAndUpdateWordValues(plcStateObject);
- int index = PlcMesObject.getPlcParameter("AddStart").getAddressIndex();
- //System.out.println(index);
- PlcMesObject.getPlcParameter("AddStart").getAddress(index);
- //System.out.println(PlcMesObject.getPlcParameter("AddStart").getAddress(index));
- List<String> addresses = new ArrayList<>();
- addresses.add("FeedID");
- addresses.add("AddStart");
- //System.out.println(addresses);
- //System.out.println(PlcMesObject.getPlcParameterValues(addresses));
- List<String> addresses2 = new ArrayList<>();
- addresses2.add("FeedID");
- addresses2.add("FeedCarStatus");
+// int index = PlcMesObject.getPlcParameter("AddStart").getAddressIndex();
+// //System.out.println(index);
+// PlcMesObject.getPlcParameter("AddStart").getAddress(index);
+// //System.out.println(PlcMesObject.getPlcParameter("AddStart").getAddress(index));
+// List<String> addresses = new ArrayList<>();
+// addresses.add("FeedID");
+// addresses.add("AddStart");
+// //System.out.println(addresses);
+// //System.out.println(PlcMesObject.getPlcParameterValues(addresses));
+// List<String> addresses2 = new ArrayList<>();
+// addresses2.add("FeedID");
+// addresses2.add("FeedCarStatus");
- System.out.println(PlcReadObject.getPlcParameterValues(addresses2));
+ // System.out.println(PlcReadObject.getPlcParameterValues(addresses2));
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutomaticParameterSettingReview2.java b/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutomaticParameterSettingReview2.java
index a6d3f93..bf6f648 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutomaticParameterSettingReview2.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/PLCAutomaticParameterSettingReview2.java
@@ -1,6 +1,7 @@
package com.example.springboot.component;
-import com.example.springboot.entity.device.PlcBitObject;
+
+
import com.example.springboot.entity.device.PlcParameterObject;
import java.io.IOException;
@@ -8,16 +9,21 @@
import java.util.Arrays;
import java.util.List;
+
import static com.example.springboot.component.InitUtil.readAndUpdateBitValues;
import static com.example.springboot.component.InitUtil.readAndUpdateWordValues;
public class PLCAutomaticParameterSettingReview2 extends Thread {
+
+ private static PlcParameterObject plcParameterObject;
// 鐢ㄤ簬瀛樺偍搴旂敤绋嬪簭鐨勯厤缃俊鎭�
private Configuration config;
private static InitUtil initUtil;
// 鍒涘缓涓�涓嚜瀹氫箟鐨� S7 鎺у埗鍣ㄦ秷鎭鐞嗗櫒瀵硅薄
MessageHandler customS7Control = new MessageHandler();
+
+// public static PlcParameterObject plcStateObject;
// 鍗曚緥瀹炰緥
private static PLCAutomaticParameterSettingReview2 instance;
@@ -25,7 +31,7 @@
// 绉佹湁鏋勯�犲嚱鏁�
public PLCAutomaticParameterSettingReview2() throws IOException {
config = new Configuration("config.properties");
- initUtil = new InitUtil();
+ // initUtil = new InitUtil();
}
// 鑾峰彇鍗曚緥瀹炰緥
@@ -36,16 +42,7 @@
return instance;
}
- String jsonFilePath = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcParameter.json").getPath();
- String jsonFilePath2 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcSign.json").getPath();
- String jsonFilePath4 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcState.json").getPath();
- //System.out.println(jsonFilePath4);
- // 璋冪敤initword鏂规硶
- PlcParameterObject plcParameterObject = initUtil.initword(jsonFilePath);
- PlcParameterObject plcStateObject = initUtil.initword(jsonFilePath4);
- // 璋冪敤initbit鏂规硶
- PlcBitObject plcBitObject = initUtil.initbit(jsonFilePath2);
@Override
public void run() {
@@ -58,6 +55,17 @@
}
+ // String jsonFilePath = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcParameter.json").getPath();
+ // String jsonFilePath2 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcSign.json").getPath();
+ //String jsonFilePath4 = PLCAutomaticParameterSettingReview2.class.getResource("/JsonFile/PlcState.json").getPath();
+ //System.out.println(jsonFilePath4);
+ // 璋冪敤initword鏂规硶
+ // plcParameterObject = initUtil.initword(jsonFilePath);
+ // plcStateObject = initUtil.initword(jsonFilePath4);
+
+ // 璋冪敤initbit鏂规硶
+ // PlcBitObject plcBitObject = initUtil.initbit(jsonFilePath2);
+
// int index3 = plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddressIndex();
// System.out.println(index3);
// System.out.println(plcParameterObject.getPlcParameter("A01A02conveyorVelocity(Max)").getAddress(index3));
@@ -67,15 +75,25 @@
// readAndUpdateWordValues(plcParameterObject);
// readAndUpdateWordValues(plcStateObject);
- List<String> addresses = new ArrayList<>();
- addresses.add("conveyorVelocity(AutoFAST)");
- addresses.add("A02ID");
+// List<String> addresses = new ArrayList<>();
+// addresses.add("conveyorVelocity(AutoFAST)");
+// addresses.add("A02ID");
+// addresses.add("conveyorVelocity(Manual)");
+ List<String> addresses = new ArrayList<>();
+ addresses.add("conveyorVelocity(AutoFAST)");
+ addresses.add("A02ID");
addresses.add("conveyorVelocity(Manual)");
- List<String> address = plcParameterObject.getAddressListByCodeId(addresses);
+
+
+
+ List<String> address = PLCAutomaticParameterSettingReview2.plcParameterObject.getAddressListByCodeId(addresses);
System.out.println(address);
+ // List<String> address = plcParameterObject.getAddressListByCodeId(addresses);
+ // System.out.println(address);
+
// int index = plcParameterObject.getPlcParameter("A01turnAngle1").getAddressIndex();
// List<Short> arraylist = S7control.getinstance().ReadWord(plcParameterObject.getPlcParameter("A01turnAngle1").getAddress(index), 8);
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java b/springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java
index c049feb..96fd659 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/PlcParameter.java
@@ -14,143 +14,69 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import com.example.springboot.common.MessageSender;
import org.apache.commons.io.FileUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.stereotype.Component;
+@Component
public class PlcParameter extends Thread {
- String name = "";
- Integer count = 0;
- public static String readFileToString(String filePath) throws IOException {
- File file = new File(filePath);
- return FileUtils.readFileToString(file, "UTF-8");
- }
-
- public void readValue() {
- String str = "";
- BufferedReader bufferedReader = null;
- FileInputStream fileInputStream;
- try {
- // 浠庢枃浠朵腑璇诲彇瀛楄妭鏁版嵁瀛樺叆 fileInputStream
- fileInputStream = new FileInputStream("CanadaMes-ui/src/configuration/Parameter.json");
- // 璇诲彇 fileInputStream 涓瓧鑺傚苟灏嗗叾瑙g爜涓哄瓧绗�
- InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "utf-8");
- // 鎻愰珮璇诲彇鏁堢巼锛屽湪 BufferedReader 鍐呭寘瑁� InputStreamReader
- bufferedReader = new BufferedReader(inputStreamReader);
- String line = null;
- // 灏� bufferedReader 鍐呭涓�琛屼竴琛岃祴鍊肩粰str
- while ((line = bufferedReader.readLine()) != null) {
- str += line;
- }
-
- // 灏唖tr瀛楃涓叉牸寮忚浆涓簀son
- JSONObject jsonObject = new JSONObject(str);
-
- // 鑾峰彇json涓殑鍊�
- JSONArray address = jsonObject.getJSONArray("address");
- for (int i = 0; i < address.size(); i++) {
- JSONObject ress = (JSONObject) address.get(i);
-
- this.name = ress.getStr("name");
- this.count = ress.getInt("count");
-
- }
-
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+// private final MessageSender messageSender;
+//
+// public PlcParameter(MessageSender messageSender) {
+// this.messageSender = messageSender;
+// }
@Override
public void run() {
while (this != null) {
try {
+// try {
+// RabbitMQUtils.sendMessage("Hello, world!", "module_queue");
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// try {
+// RabbitMQUtils.receiveMessage("module_queue");
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// String message = "Hello, RabbitMQ!";
+// messageSender.sendMessage(message);
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
-// this.readValue();
-// String PlcAddress = this.name;
-// Integer Plccount = this.count;
- // System.out.println(stt);
- List<Short> arraylist = S7control.getinstance().ReadWord("DB100.0", 60);
- List<Short> state = S7control.getinstance().ReadWord("DB103.0", 10);
-// Short[] values1 = { 1231, 1, 1, 1, 1, 1, 2, 33, 2, 3, 4, 5 ,1231, 1, 1, 1, 1, 1, 2, 33, 2, 3, 4, 5 };
-// List<Short> arraylist = new ArrayList<>(Arrays.asList(values1));
-
-// Short[] values2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-// List<Short> state = new ArrayList<>(Arrays.asList(values2));
-
- // Boolean[] values = { false, true, true, true, true, true, true, true, true,
- // true, true, true, true, true, true, true, true, true, true, true, true, true,
- // true,
- // true, false, true };
- // List<Boolean> paramlist = new ArrayList<>(Arrays.asList(values));
-
- // short[] sholist = new short[paramlist.size()];
-
- // for (int i = 0; i < paramlist.size(); i++) {
- // boolean value = paramlist.get(i);
- // sholist[i] = value ? (short) 1 : (short) 0;
- // }
JSONObject jsonObject = new JSONObject();
- // new short[]{1,1, 1, 1, 1, 1, 2, 33, 2,3, 4, 5}
- // new short[]{0,0, 0, 0, 0, 0, 0, 0, 0, 0}
+ jsonObject.put("key1", "value1");
+ jsonObject.put("key2", 123);
+ JSONArray jsonArray = new JSONArray();
+ jsonArray.add("item1");
+ jsonArray.add("item2");
+ jsonObject.put("key3", jsonArray);
- jsonObject.append("params", arraylist);
- jsonObject.append("state", state);
- // jsonObject.append("action", sholist);
-// WebSocketServer sendwServer = WebSocketServer.sessionMap.get("Parameter");
-// if (sendwServer != null) {
-// sendwServer.sendMessage(jsonObject.toString());
-// }
+ try {
+ // 灏� JSON 瀵硅薄杞崲涓哄瓧绗︿覆骞跺彂閫佸埌闃熷垪
+ RabbitMQUtils.sendJsonMessage(jsonObject, "json_queue");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("Parameter");
- if (sendwServer != null) {
- for (WebSocketServer webserver : sendwServer) {
- webserver.sendMessage(jsonObject.toString());
-
-// WebSocketServer webSocketServer = WebSocketServer.sessionMap.get("Parameter");
- if (webserver != null) {
- List<String> messages = webserver.getMessages();
-
- String addressList = "DB100.0";
-
- if (!messages.isEmpty()) {
- // 灏嗘渶鍚庝竴涓秷鎭浆鎹负 short 绫诲瀷鐨勫垪琛�
- String lastMessage = messages.get(messages.size() - 1);
- System.out.println("messages锛�" + messages);
- String[] parts = lastMessage.split(",");
- List<Short> messageValues = new ArrayList<>();
- for (String part : parts) {
- try {
- // 浣跨敤姝e垯琛ㄨ揪寮忔竻闄ら潪鏁板瓧瀛楃
- String cleanedPart = part.replaceAll("[^0-9-]", "");
- short value = Short.parseShort(cleanedPart.trim());
- messageValues.add(value);
- } catch (NumberFormatException e) {
- // 濡傛灉鏃犳硶瑙f瀽涓� short 绫诲瀷锛屽垯蹇界暐璇ラ儴鍒�
-
- e.printStackTrace();
- }
- }
-
- // 灏嗘秷鎭�煎啓鍏� PLC
- S7control.getinstance().WriteWord(addressList, messageValues);
- System.out.println("messageValues锛�" + messageValues);
- System.out.println("addressList锛�" + addressList);
- // 娓呯┖娑堟伅鍒楄〃
- webserver.clearMessages();
- }
- }
- }
+ try {
+ // 浠庨槦鍒楁帴鏀跺苟瑙f瀽 JSON 娑堟伅涓� JSONObject 瀵硅薄
+ JSONObject receivedJsonObject = RabbitMQUtils.receiveJsonMessage(JSONObject.class, "json_queue");
+ System.out.println(receivedJsonObject.toString());
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
}
+
+
}
diff --git a/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java b/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java
new file mode 100644
index 0000000..3d8d51c
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/component/RabbitMQUtils.java
@@ -0,0 +1,106 @@
+package com.example.springboot.component;
+
+import com.rabbitmq.client.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class RabbitMQUtils {
+ // ObjectMapper瀵硅薄锛岀敤浜庡簭鍒楀寲鍜屽弽搴忓垪鍖朖SON
+ private static ObjectMapper objectMapper = new ObjectMapper();
+
+ // 鍙戦�佹秷鎭埌 RabbitMQ 闃熷垪涓�
+ public static void sendMessage(String message, String queueName) throws Exception {
+ // 鍒涘缓杩炴帴宸ュ巶骞惰缃富鏈哄悕
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+
+ // 浣跨敤 try-with-resources 璇彞鍒涘缓杩炴帴鍜岄�氶亾锛屽苟鍙戦�佹秷鎭�
+ try (Connection connection = factory.newConnection();
+ Channel channel = connection.createChannel()) {
+ // 澹版槑闃熷垪
+ channel.queueDeclare(queueName, false, false, false, null);
+
+ // 鍙戝竷娑堟伅鍒伴槦鍒�
+ channel.basicPublish("", queueName, null, message.getBytes());
+ System.out.println(" [x] Sent '" + message + "' to queue '" + queueName + "'");
+ }
+ }
+
+ // 浠� RabbitMQ 闃熷垪涓帴鏀舵秷鎭�
+ public static void receiveMessage(String queueName) throws Exception {
+ // 鍒涘缓杩炴帴宸ュ巶骞惰缃富鏈哄悕
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+
+ // 浣跨敤 try-with-resources 璇彞鍒涘缓杩炴帴鍜岄�氶亾锛屽苟鎺ユ敹娑堟伅
+ try (Connection connection = factory.newConnection();
+ Channel channel = connection.createChannel()) {
+ // 澹版槑闃熷垪
+ channel.queueDeclare(queueName, false, false, false, null);
+
+ // 璁剧疆娑堟伅鎺ユ敹鍥炶皟
+ DeliverCallback deliverCallback = (consumerTag, delivery) -> {
+ String receivedMessage = new String(delivery.getBody(), "UTF-8");
+ System.out.println(" [x] Received '" + receivedMessage + "'");
+ };
+
+ // 娑堣垂闃熷垪涓殑娑堟伅
+ channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
+ });
+ }
+ }
+
+ // 鍙戦�� JSON 娑堟伅鍒伴槦鍒�
+ public static void sendJsonMessage(Object message, String queueName) throws Exception {
+ // 鍒涘缓杩炴帴宸ュ巶骞惰缃富鏈哄悕
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+
+ // 浣跨敤 try-with-resources 璇彞鍒涘缓杩炴帴鍜岄�氶亾锛屽苟鍙戦�� JSON 娑堟伅
+ try (Connection connection = factory.newConnection();
+ Channel channel = connection.createChannel()) {
+ // 澹版槑闃熷垪
+ channel.queueDeclare(queueName, false, false, false, null);
+
+ // 灏嗗璞¤浆鎹负 JSON 瀛楃涓�
+ String jsonMessage = objectMapper.writeValueAsString(message);
+
+ // 鍙戝竷 JSON 娑堟伅鍒伴槦鍒�
+ channel.basicPublish("", queueName, null, jsonMessage.getBytes());
+ System.out.println(" [x] Sent JSON message: '" + jsonMessage + "' to queue '" + queueName + "'");
+ }
+ }
+
+ // 鎺ユ敹 JSON 娑堟伅骞惰浆鎹负瀵硅薄
+ public static <T> T receiveJsonMessage(Class<T> valueType, String queueName) throws Exception {
+ // 鍒涘缓杩炴帴宸ュ巶骞惰缃富鏈哄悕
+ ConnectionFactory factory = new ConnectionFactory();
+ factory.setHost("localhost");
+
+ // 浣跨敤 try-with-resources 璇彞鍒涘缓杩炴帴鍜岄�氶亾锛屽苟鎺ユ敹 JSON 娑堟伅
+ try (Connection connection = factory.newConnection();
+ Channel channel = connection.createChannel()) {
+ // 澹版槑闃熷垪
+ channel.queueDeclare(queueName, false, false, false, null);
+
+ // 鑾峰彇闃熷垪涓殑娑堟伅
+ GetResponse response = channel.basicGet(queueName, true);
+ if (response != null) {
+ byte[] body = response.getBody();
+ String jsonMessage = new String(body, "UTF-8");
+ System.out.println(" [x] Received JSON message: '" + jsonMessage + "' from queue '" + queueName + "'");
+
+ // 灏� JSON 娑堟伅杞崲涓哄璞�
+ return objectMapper.readValue(jsonMessage, valueType);
+ } else {
+ return null;
+ }
+ }
+ }
+}
+
+
+// RabbitMQUtils.sendMessage("Hello, world!", "module_queue");
+//RabbitMQUtils.receiveMessage("module_queue");
+//RabbitMQUtils.sendJsonMessage(someObject, "another_queue");
+//RabbitMQUtils.receiveJsonMessage(SomeClass.class, "another_queue");
+// 闇�瑕佸皢 someObject 鏇挎崲涓轰綘瑕佸彂閫佺殑瀵硅薄锛屽苟灏� SomeClass 鏇挎崲涓轰綘瑕佹帴鏀跺苟杞崲鐨勫璞$被鍨嬨��
\ No newline at end of file
diff --git a/springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java b/springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java
index 2cd1c22..17ccdb8 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/config/AppRunnerConfig.java
@@ -1,6 +1,7 @@
package com.example.springboot.config;
import com.example.springboot.component.*;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
@@ -11,36 +12,49 @@
public class AppRunnerConfig implements ApplicationRunner {
+ private final PlcParameter plcParameter;
+
+ public AppRunnerConfig(PlcParameter plcParameter) {
+ this.plcParameter = plcParameter;
+ }
@Override
public void run(ApplicationArguments args) throws Exception {
// TODO Auto-generated method stub
//
System.out.println("鍚姩瀹屾垚");
- new PlcHold().start();
+ // plcParameter.start();
+//
+// new PlcHold().start();
+//
+// new Plchome().start();
+// new PlcLayout().start();
+// new Plcalarm().start();
+//
+// new Plcsign().start();
+//
+// new Plcstate().start();
+// new PlcPositioning1().start();
+//
+// new PlcParameter2().start();
+// new PLCAutomaticParameterSetting().start();
+//
+// new PlcManualonePosition().start();
+// new PlcManualonePosition2().start();
+// new PlcServoManualone().start();
+// new PLCManualJog().start();
+// new Plclog().start();
+//
+// new PlcInteractionState().start();
- new Plchome().start();
- new PlcLayout().start();
- new Plcalarm().start();
- new Plcsign().start();
- new Plcstate().start();
- new PlcPositioning1().start();
- new PlcParameter2().start();
- new PLCAutomaticParameterSetting().start();
-
- new PlcManualonePosition().start();
- new PlcManualonePosition2().start();
- new PlcServoManualone().start();
- new PLCManualJog().start();
- new Plclog().start();
-
- new PlcInteractionState().start();
//new PlcParameter1Review().start();
+ //new PLCAutoMes().start();
//new PLCAutomaticParameterSettingReview2().start();
+
// new PLCManualJogReview().start();
}
}
\ No newline at end of file
diff --git a/springboot-vue3/src/main/java/com/example/springboot/controller/MessageController.java b/springboot-vue3/src/main/java/com/example/springboot/controller/MessageController.java
new file mode 100644
index 0000000..a4219bd
--- /dev/null
+++ b/springboot-vue3/src/main/java/com/example/springboot/controller/MessageController.java
@@ -0,0 +1,55 @@
+package com.example.springboot.controller;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.example.springboot.common.MessageSender;
+import com.example.springboot.component.RabbitMQUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.example.springboot.common.MessageSender.Person;
+
+@RestController
+public class MessageController {
+
+ @Autowired
+ private MessageSender messageSender;
+
+ @GetMapping("/send/{message}")
+ public String sendMessage(@PathVariable("message") String message) {
+ messageSender.sendMessage(message);
+ return "Message sent: " + message;
+ }
+
+ @GetMapping("/sendPerson/{name}/{age}")
+ public String sendPersonMessage(@PathVariable("name") String name, @PathVariable("age") int age) {
+ Person person = new Person(name, age);
+ messageSender.sendMessage2(person);
+ return "Person message sent: " + person;
+ }
+
+ @GetMapping("/sendJson")
+ public String sendJsonMessage() {
+ // 鍒涘缓瑕佸彂閫佺殑瀵硅薄
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("key1", "value1");
+ jsonObject.put("key2", 123);
+ JSONArray jsonArray = new JSONArray();
+ jsonArray.add("item1");
+ jsonArray.add("item2");
+ jsonObject.put("key3", jsonArray);
+
+
+ try {
+ // 璋冪敤 RabbitMQUtils 鍙戦�� JSON 娑堟伅鐨勬柟娉�
+ RabbitMQUtils.sendJsonMessage(jsonObject, "yourQueueName");
+ return "JSON message sent: " + jsonObject;
+ } catch (Exception e) {
+ return "Failed to send JSON message: " + e.getMessage();
+ }
+
+ }
+
+}
diff --git a/springboot-vue3/src/main/resources/application.properties b/springboot-vue3/src/main/resources/application.properties
index 9ac74e3..7ec3226 100644
--- a/springboot-vue3/src/main/resources/application.properties
+++ b/springboot-vue3/src/main/resources/application.properties
@@ -23,3 +23,9 @@
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
+spring.rabbitmq.host=localhost
+spring.rabbitmq.port=5672
+spring.rabbitmq.username=guest
+spring.rabbitmq.password=guest
+
+
--
Gitblit v1.8.0