From 23182f2c951df5fa55e70e30ff70ddaf91199a2e Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期四, 05 二月 2026 15:57:58 +0800
Subject: [PATCH] 1
---
zy-acs-hex/src/main/java/com/zy/acs/hex/controller/TestController.java | 17 +
zy-acs-hex/src/main/java/com/zy/acs/hex/utils/StrUtils.java | 62 ++++++++
zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/listener/AbstractListener.java | 3
zy-acs-hex/pom.xml | 18 +-
zy-acs-hex/src/main/java/com/zy/acs/hex/domain/Device.java | 10 +
zy-acs-hex/src/main/java/com/zy/acs/hex/HexApplication.java | 2
component/component-Influxdb/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst | 2
component/component-Influxdb/src/main/java/com/zy/component/influxdb/service/InfluxDBService.java | 1
zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/UpMessageListener.java | 28 +---
zy-acs-hex/src/main/resources/application.yml | 8
component/component-Influxdb/target/classes/com/zy/component/influxdb/service/InfluxDBService.class | 0
zy-acs-hex/src/main/java/com/zy/acs/hex/utils/ReflectionUtils.java | 171 ++++++++++++++++++++++++
zy-acs-hex/src/main/java/com/zy/acs/hex/constant/InfluxDBConstant.java | 28 ++++
component/component-Influxdb/target/component-Influxdb-1.0.0.jar | 0
zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/DownMessageListener.java | 20 +-
15 files changed, 317 insertions(+), 53 deletions(-)
diff --git a/component/component-Influxdb/src/main/java/com/zy/component/influxdb/service/InfluxDBService.java b/component/component-Influxdb/src/main/java/com/zy/component/influxdb/service/InfluxDBService.java
index 9010073..c3f5ad4 100644
--- a/component/component-Influxdb/src/main/java/com/zy/component/influxdb/service/InfluxDBService.java
+++ b/component/component-Influxdb/src/main/java/com/zy/component/influxdb/service/InfluxDBService.java
@@ -40,7 +40,6 @@
.setTimestamp(Instant.now().toEpochMilli(), WritePrecision.MS);
try {
influxDBClient.writePoint(point);
- System.out.println("Data written to the database.");
} catch (Exception e) {
logger.error("Failed to write data to the database.");
e.printStackTrace();
diff --git a/component/component-Influxdb/target/classes/com/zy/component/influxdb/service/InfluxDBService.class b/component/component-Influxdb/target/classes/com/zy/component/influxdb/service/InfluxDBService.class
index e45e65f..5182549 100644
--- a/component/component-Influxdb/target/classes/com/zy/component/influxdb/service/InfluxDBService.class
+++ b/component/component-Influxdb/target/classes/com/zy/component/influxdb/service/InfluxDBService.class
Binary files differ
diff --git a/component/component-Influxdb/target/component-Influxdb-1.0.0.jar b/component/component-Influxdb/target/component-Influxdb-1.0.0.jar
index 7490632..b611964 100644
--- a/component/component-Influxdb/target/component-Influxdb-1.0.0.jar
+++ b/component/component-Influxdb/target/component-Influxdb-1.0.0.jar
Binary files differ
diff --git a/component/component-Influxdb/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/component/component-Influxdb/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
index 3f0a789..b1930b9 100644
--- a/component/component-Influxdb/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
+++ b/component/component-Influxdb/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
@@ -1,3 +1,3 @@
com\zy\component\influxdb\service\InfluxDBService.class
-com\zy\component\influxdb\properties\InfluxDBProperties.class
com\zy\component\influxdb\config\InfluxDBAutoConfiguration.class
+com\zy\component\influxdb\properties\InfluxDBProperties.class
diff --git a/zy-acs-hex/pom.xml b/zy-acs-hex/pom.xml
index 95deb61..f23f868 100644
--- a/zy-acs-hex/pom.xml
+++ b/zy-acs-hex/pom.xml
@@ -22,11 +22,11 @@
<dependencies>
- <dependency>
- <groupId>com.zy</groupId>
- <artifactId>acs-common</artifactId>
- <version>1.0.0</version>
- </dependency>
+ <dependency>
+ <groupId>com.zy</groupId>
+ <artifactId>acs-common</artifactId>
+ <version>1.0.0</version>
+ </dependency>
<dependency>
<groupId>com.zy</groupId>
<artifactId>component-Influxdb</artifactId>
@@ -46,10 +46,10 @@
</dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
<!-- Lombok -->
<dependency>
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
index 483bede..41c2135 100644
--- 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
@@ -5,7 +5,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
-@ComponentScan(basePackages = {"com.zy.component","com.zy.acs"})
+@ComponentScan(basePackages = {"com.zy.component", "com.zy.acs"})
@SpringBootApplication
public class HexApplication {
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/constant/InfluxDBConstant.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/constant/InfluxDBConstant.java
new file mode 100644
index 0000000..d0baeac
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/constant/InfluxDBConstant.java
@@ -0,0 +1,28 @@
+package com.zy.acs.hex.constant;
+
+
+/**
+ * 鏃跺簭鏁版嵁搴撳父閲忕被
+ *
+ * @author ken
+ */
+
+public class InfluxDBConstant {
+
+ public static final String DEVICE_MEASUREMENT = "device";
+
+ public static final String DEVICE_MEASUREMENT_TAG_DEVICEID = "deviceId";
+
+ public static final String DEVICE_MEASUREMENT_TAG_EVENT = "event";
+
+ public static final String DEVICE_MEASUREMENT_TAG_TYPE = "type";
+
+ public static class DEVICE_MEASUREMENT_TAG_TYPE_FLAG {
+
+ public static final String DEVICE_MEASUREMENT_TAG_TYPE_UP = "up";
+
+ public static final String DEVICE_MEASUREMENT_TAG_TYPE_DOWN = "down";
+ }
+
+
+}
\ No newline at end of file
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/DownMessageListener.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/DownMessageListener.java
index d03084d..47a167c 100644
--- a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/DownMessageListener.java
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/DownMessageListener.java
@@ -1,12 +1,15 @@
package com.zy.acs.hex.consumer;
import com.rabbitmq.client.Channel;
+import com.zy.acs.hex.constant.InfluxDBConstant;
import com.zy.acs.hex.constant.RabbitConstant;
import com.zy.acs.hex.consumer.listener.AbstractListener;
+import com.zy.acs.hex.domain.Device;
+import com.zy.acs.hex.utils.ReflectionUtils;
+import com.zy.acs.hex.utils.StrUtils;
import com.zy.component.influxdb.service.InfluxDBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
-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;
@@ -19,15 +22,10 @@
@Component
@RabbitListener(bindings = @QueueBinding(
value = @Queue(name = RabbitConstant.TOPIC_QUEUE_DOWN, durable = RabbitConstant.DURABLE),
- exchange = @Exchange(name = RabbitConstant.TOPIC_EXCHANGE,type = RabbitConstant.TOPIC_EXCHANGE_TYPE),
+ exchange = @Exchange(name = RabbitConstant.TOPIC_EXCHANGE, type = RabbitConstant.TOPIC_EXCHANGE_TYPE),
key = RabbitConstant.ROUTING_KEY_DOWN
))
-public class DownMessageListener implements AbstractListener {
-
-
-
- @Autowired
- private RabbitTemplate rabbitTemplate;
+public class DownMessageListener implements AbstractListener {
@Autowired
@@ -35,9 +33,9 @@
@RabbitHandler
- public void handle(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
- log.info("receive down message: {}" , msg);
-
+ public void handle(Device msg, @Header(AmqpHeaders.RECEIVED_ROUTING_KEY) String routingKey, Channel channel) {
+ log.info("routingKey:{},receive down message:{}", routingKey, msg);
+ influxDBService.writeData(InfluxDBConstant.DEVICE_MEASUREMENT, StrUtils.getTagsByRoutingKey(routingKey), ReflectionUtils.convertBean2Map(msg));
}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/UpMessageListener.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/UpMessageListener.java
index 5dc351c..1c894d8 100644
--- a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/UpMessageListener.java
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/UpMessageListener.java
@@ -1,18 +1,19 @@
package com.zy.acs.hex.consumer;
import com.rabbitmq.client.Channel;
+import com.zy.acs.hex.constant.InfluxDBConstant;
import com.zy.acs.hex.constant.RabbitConstant;
import com.zy.acs.hex.consumer.listener.AbstractListener;
+import com.zy.acs.hex.domain.Device;
+import com.zy.acs.hex.utils.ReflectionUtils;
+import com.zy.acs.hex.utils.StrUtils;
import com.zy.component.influxdb.service.InfluxDBService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
-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 java.io.IOException;
/**
* 娑堣垂鑰�
@@ -27,30 +28,15 @@
public class UpMessageListener implements AbstractListener {
-
- @Autowired
- private RabbitTemplate rabbitTemplate;
-
-
@Autowired
private InfluxDBService influxDBService;
@RabbitHandler
- public void handle(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
- log.info("receive up message: {}" , msg);
- try {
- channel.basicAck(tag,true);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- // 杩涘叆娑堟伅娑堣垂涓氬姟閫昏緫銆�
- //String data = new String(message.getBody());
- //log.info("鏀跺埌娑堟伅锛歿}" ,data );
- //influxDBService.writeData();
+ public void handle(Device msg, @Header(AmqpHeaders.RECEIVED_ROUTING_KEY) String routingKey, Channel channel) {
+ log.info("routingKey:{},receive up message:{}", routingKey, msg);
+ influxDBService.writeData(InfluxDBConstant.DEVICE_MEASUREMENT, StrUtils.getTagsByRoutingKey(routingKey), ReflectionUtils.convertBean2Map(msg));
}
-
-
}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/listener/AbstractListener.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/listener/AbstractListener.java
index 2e1c4c4..57abd1b 100644
--- a/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/listener/AbstractListener.java
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/consumer/listener/AbstractListener.java
@@ -1,9 +1,10 @@
package com.zy.acs.hex.consumer.listener;
import com.rabbitmq.client.Channel;
+import com.zy.acs.hex.domain.Device;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
public interface AbstractListener {
- void handle(String event, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag);
+ void handle(Device event, @Header(AmqpHeaders.RECEIVED_ROUTING_KEY) String routingKey, Channel channel);
}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/TestController.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/TestController.java
index d69d370..1744e66 100644
--- a/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/TestController.java
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/controller/TestController.java
@@ -1,10 +1,13 @@
package com.zy.acs.hex.controller;
import com.zy.acs.hex.constant.RabbitConstant;
+import com.zy.acs.hex.domain.Device;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
@@ -16,21 +19,27 @@
/**
* 鍙戦�佹秷鎭痶est1
+ *
* @return
*/
@GetMapping(value = "/test1")
public void sendTest1() {
- String router = RabbitConstant.ROUTING_KEY_UP.replaceFirst("\\*", "1").replaceFirst("\\*", "2");
- rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE,router,"1212321323");
+ Device device = new Device();
+ //device.setEvent("online");
+ //device.setDeviceId("123");
+ device.setProtocol("212121212121212");
+ String router = RabbitConstant.ROUTING_KEY_UP.replaceFirst("\\*", "123").replaceFirst("\\*", "online");
+ rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, router, device);
}
/**
* 鍙戦�佹秷鎭痶est2
+ *
* @return
*/
@GetMapping(value = "/test2")
public void sendTest2() {
- rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, RabbitConstant.ROUTING_KEY_DOWN, "qswaqsaasas");
+ rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, RabbitConstant.ROUTING_KEY_DOWN, "qswaqsaasas");
}
}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/domain/Device.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/domain/Device.java
new file mode 100644
index 0000000..45de61d
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/domain/Device.java
@@ -0,0 +1,10 @@
+package com.zy.acs.hex.domain;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class Device implements Serializable {
+ private String protocol;
+}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/utils/ReflectionUtils.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/utils/ReflectionUtils.java
new file mode 100644
index 0000000..bc699ee
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/utils/ReflectionUtils.java
@@ -0,0 +1,171 @@
+package com.zy.acs.hex.utils;
+
+import com.zy.acs.framework.common.Cools;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ReflectionUtils {
+ /**
+ * 鑾峰彇涓�涓被鍜屽叾鐖剁被鐨勬墍鏈夊睘鎬�
+ *
+ * @param clazz
+ * @return
+ */
+ public static List<Field> findAllFieldsOfSelfAndSuperClass(Class clazz) {
+ Field[] fields = null;
+ List fieldList = new ArrayList();
+ while (true) {
+ if (clazz == null) {
+ break;
+ } else {
+ fields = clazz.getDeclaredFields();
+ for (int i = 0; i < fields.length; i++) {
+ fieldList.add(fields[i]);
+ }
+ clazz = clazz.getSuperclass();
+ }
+ }
+ return fieldList;
+ }
+
+ /**
+ * 鎶婁竴涓狟ean瀵硅薄杞崲鎴怣ap瀵硅薄</br>
+ *
+ * @param obj
+ * @param ignores
+ * @return
+ * @throws IllegalAccessException
+ */
+ public static Map convertBean2Map(Object obj, String[] ignores) {
+ Map map = new HashMap();
+ Class clazz = obj.getClass();
+ List<Field> fieldList = findAllFieldsOfSelfAndSuperClass(clazz);
+ Field field = null;
+ try {
+ for (int i = 0; i < fieldList.size(); i++) {
+ field = fieldList.get(i);
+ // 瀹氫箟fieldName鏄惁鍦ㄦ嫹璐濆拷鐣ョ殑鑼冪暣鍐�
+ boolean flag = false;
+ if (ignores != null && ignores.length != 0) {
+ flag = isExistOfIgnores(field.getName(), ignores);
+ }
+ if (!flag) {
+ Object value = getProperty(obj, field.getName());
+ if (null != value
+ && !Cools.isEmpty(value.toString())) {
+ map.put(field.getName(),
+ getProperty(obj, field.getName()));
+ }
+ }
+ }
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ }
+ return map;
+ }
+
+ /**
+ * 鎶婁竴涓狟ean瀵硅薄杞崲鎴怣ap瀵硅薄</br>
+ *
+ * @param obj
+ * @return
+ */
+ public static Map convertBean2Map(Object obj) {
+ return convertBean2Map(obj, null);
+ }
+
+ public static Map convertBean2MapForIngoreserialVersionUID(Object obj) {
+ return convertBean2Map(obj, new String[]{"serialVersionUID"});
+ }
+
+ /**
+ * 鍒ゆ柇fieldName鏄惁鏄痠gnores涓帓闄ょ殑
+ *
+ * @param fieldName
+ * @param ignores
+ * @return
+ */
+ private static boolean isExistOfIgnores(String fieldName,
+ String[] ignores) {
+ boolean flag = false;
+ for (String str : ignores) {
+ if (str.equals(fieldName)) {
+ flag = true;
+ break;
+ }
+ }
+ return flag;
+ }
+
+ public static PropertyDescriptor getPropertyDescriptor(Class clazz,
+ String propertyName) {
+ StringBuffer sb = new StringBuffer();// 鏋勫缓涓�涓彲鍙樺瓧绗︿覆鐢ㄦ潵鏋勫缓鏂规硶鍚嶇О
+ Method setMethod = null;
+ Method getMethod = null;
+ PropertyDescriptor pd = null;
+ try {
+ Field f = clazz.getDeclaredField(propertyName);// 鏍规嵁瀛楁鍚嶆潵鑾峰彇瀛楁
+ if (f != null) {
+ // 鏋勫缓鏂规硶鐨勫悗缂�
+ String methodEnd = propertyName.substring(0, 1).toUpperCase()
+ + propertyName.substring(1);
+ sb.append("set" + methodEnd);// 鏋勫缓set鏂规硶
+ setMethod = clazz.getDeclaredMethod(sb.toString(),
+ new Class[]{f.getType()});
+ sb.delete(0, sb.length());// 娓呯┖鏁翠釜鍙彉瀛楃涓�
+ sb.append("get" + methodEnd);// 鏋勫缓get鏂规硶
+ // 鏋勫缓get 鏂规硶
+ getMethod =
+ clazz.getDeclaredMethod(sb.toString(), new Class[]{});
+ // 鏋勫缓涓�涓睘鎬ф弿杩板櫒 鎶婂搴斿睘鎬� propertyName 鐨� get 鍜� set 鏂规硶淇濆瓨鍒板睘鎬ф弿杩板櫒涓�
+ pd = new PropertyDescriptor(propertyName, getMethod, setMethod);
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ return pd;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void setProperty(Object obj, String propertyName,
+ Object value) {
+ Class clazz = obj.getClass();// 鑾峰彇瀵硅薄鐨勭被鍨�
+ PropertyDescriptor pd = getPropertyDescriptor(clazz, propertyName);// 鑾峰彇 clazz
+ // 绫诲瀷涓殑
+ // propertyName
+ // 鐨勫睘鎬ф弿杩板櫒
+ Method setMethod = pd.getWriteMethod();// 浠庡睘鎬ф弿杩板櫒涓幏鍙� set 鏂规硶
+ try {
+ setMethod.invoke(obj, new Object[]{value});// 璋冪敤 set 鏂规硶灏嗕紶鍏ョ殑value鍊间繚瀛樺睘鎬т腑鍘�
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public static Object getProperty(Object obj, String propertyName) {
+ Class clazz = obj.getClass();// 鑾峰彇瀵硅薄鐨勭被鍨�
+ PropertyDescriptor pd = getPropertyDescriptor(clazz, propertyName);// 鑾峰彇 clazz
+ // 绫诲瀷涓殑
+ // propertyName
+ // 鐨勫睘鎬ф弿杩板櫒
+ Method getMethod = pd.getReadMethod();// 浠庡睘鎬ф弿杩板櫒涓幏鍙� get 鏂规硶
+ Object value = null;
+ try {
+ value = getMethod.invoke(obj, new Object[]{});// 璋冪敤鏂规硶鑾峰彇鏂规硶鐨勮繑鍥炲��
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return value;// 杩斿洖鍊�
+ }
+
+}
diff --git a/zy-acs-hex/src/main/java/com/zy/acs/hex/utils/StrUtils.java b/zy-acs-hex/src/main/java/com/zy/acs/hex/utils/StrUtils.java
new file mode 100644
index 0000000..37410c4
--- /dev/null
+++ b/zy-acs-hex/src/main/java/com/zy/acs/hex/utils/StrUtils.java
@@ -0,0 +1,62 @@
+package com.zy.acs.hex.utils;
+
+import com.zy.acs.hex.constant.InfluxDBConstant;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class StrUtils {
+
+ public static Map<String, String> getTagsByRoutingKey(String routingKey) {
+
+ // 姝e垯琛ㄨ揪寮忓尮閰� rcs.up. 寮�澶达紝鍚庨潰璺熺潃涓や釜鐗堟湰鍙烽儴鍒�
+ String regex = "^rcs\\.up\\.(\\*|[a-zA-Z0-9]+)\\.(\\*|[a-zA-Z0-9]+)$";
+ if (routingKey.matches(regex)) {
+ // 鍒嗗壊瀛楃涓插苟杩斿洖鐗堟湰鍙烽儴鍒�
+ String[] parts = routingKey.split("\\.");
+ if (parts.length == 4) {
+ Map<String, String> data = new HashMap<>();
+ data.put(InfluxDBConstant.DEVICE_MEASUREMENT_TAG_TYPE, parts[1]);
+ data.put(InfluxDBConstant.DEVICE_MEASUREMENT_TAG_DEVICEID, parts[2]);
+ data.put(InfluxDBConstant.DEVICE_MEASUREMENT_TAG_EVENT, parts[3]);
+ return data;
+ }
+ }
+ // 濡傛灉鏍煎紡涓嶇鍚堬紝杩斿洖绌烘暟缁�
+ return null;
+ }
+
+ public static String getDeviceIdByRoutingKey(String routingKey) {
+
+ // 姝e垯琛ㄨ揪寮忓尮閰� rcs.up. 寮�澶达紝鍚庨潰璺熺潃涓や釜鐗堟湰鍙烽儴鍒�
+ String regex = "^rcs\\.up\\.(\\*|[a-zA-Z0-9]+)\\.(\\*|[a-zA-Z0-9]+)$";
+ if (routingKey.matches(regex)) {
+ // 鍒嗗壊瀛楃涓插苟杩斿洖鐗堟湰鍙烽儴鍒�
+ String[] parts = routingKey.split("\\.");
+ if (parts.length == 4) {
+ return parts[2];
+ }
+ }
+ // 濡傛灉鏍煎紡涓嶇鍚堬紝杩斿洖绌烘暟缁�
+ return null;
+ }
+
+ public static String getEventByRoutingKey(String routingKey) {
+
+ // 姝e垯琛ㄨ揪寮忓尮閰� rcs.up. 寮�澶达紝鍚庨潰璺熺潃涓や釜鐗堟湰鍙烽儴鍒�
+ String regex = "^rcs\\.up\\.(\\*|[a-zA-Z0-9]+)\\.(\\*|[a-zA-Z0-9]+)$";
+ if (routingKey.matches(regex)) {
+ // 鍒嗗壊瀛楃涓插苟杩斿洖鐗堟湰鍙烽儴鍒�
+ String[] parts = routingKey.split("\\.");
+ if (parts.length == 4) {
+ return parts[2];
+ }
+ }
+ // 濡傛灉鏍煎紡涓嶇鍚堬紝杩斿洖绌烘暟缁�
+ return null;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(StrUtils.getDeviceIdByRoutingKey("rcs.up.ds1233.2aads"));
+ }
+}
diff --git a/zy-acs-hex/src/main/resources/application.yml b/zy-acs-hex/src/main/resources/application.yml
index ec78f6f..d2bd267 100644
--- a/zy-acs-hex/src/main/resources/application.yml
+++ b/zy-acs-hex/src/main/resources/application.yml
@@ -1,4 +1,3 @@
-
spring:
application:
name: rcs-hex
@@ -14,9 +13,10 @@
publisher-confirm-type: correlated
publisher-returns: true
# 娑堣垂鑰呴厤缃�
- listener:
- direct:
- acknowledge-mode: manual
+# listener:
+# direct:
+# 纭鏈哄埗
+# acknowledge-mode: manual
influxdb3:
enabled: true
--
Gitblit v1.9.1