From b1e1a1b7cc8c6f273373a284320e59150e3da6f8 Mon Sep 17 00:00:00 2001 From: bgy Date: Wed, 31 Dec 2025 09:15:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../influxdb/OperateInfluxdbApplication.java | 5 ++- .../topsail/influxdb/rabbitmq/AmqpListener.java | 4 +-- .../influxdb/schdule/ScheduledMessageProducer.java | 38 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/topsail/influxdb/schdule/ScheduledMessageProducer.java diff --git a/src/main/java/com/topsail/influxdb/OperateInfluxdbApplication.java b/src/main/java/com/topsail/influxdb/OperateInfluxdbApplication.java index 030353b..a58faf4 100644 --- a/src/main/java/com/topsail/influxdb/OperateInfluxdbApplication.java +++ b/src/main/java/com/topsail/influxdb/OperateInfluxdbApplication.java @@ -3,9 +3,12 @@ package com.topsail.influxdb; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; import java.util.TimeZone; - +@Configuration +@EnableScheduling @SpringBootApplication @MapperScan("com.topsail.influxdb.mapper") public class OperateInfluxdbApplication { diff --git a/src/main/java/com/topsail/influxdb/rabbitmq/AmqpListener.java b/src/main/java/com/topsail/influxdb/rabbitmq/AmqpListener.java index 2c1b656..90136ba 100644 --- a/src/main/java/com/topsail/influxdb/rabbitmq/AmqpListener.java +++ b/src/main/java/com/topsail/influxdb/rabbitmq/AmqpListener.java @@ -37,7 +37,7 @@ public class AmqpListener { * @throws Exception */ - @RabbitListener(queues = "shengdilandevicedataall") +// @RabbitListener(queues = "shengdilandevicedataall") public void deviceDataMqListener(@Payload String message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) throws Exception { if (StringUtils.isEmpty(message)) { channel.basicAck(deliveryTag, false); @@ -63,7 +63,7 @@ public class AmqpListener { * @throws Exception */ - @RabbitListener(queues = "shengdilandevicelogall") +// @RabbitListener(queues = "shengdilandevicelogall") public void deviceLogMqListener(@Payload String message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel) throws Exception { if (StringUtils.isEmpty(message)) { channel.basicAck(deliveryTag, false); diff --git a/src/main/java/com/topsail/influxdb/schdule/ScheduledMessageProducer.java b/src/main/java/com/topsail/influxdb/schdule/ScheduledMessageProducer.java new file mode 100644 index 0000000..bbf2c67 --- /dev/null +++ b/src/main/java/com/topsail/influxdb/schdule/ScheduledMessageProducer.java @@ -0,0 +1,38 @@ +package com.topsail.influxdb.schdule; + +import com.topsail.influxdb.rabbitmq.service.AmqpService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +public class ScheduledMessageProducer { + + @Autowired + private AmqpService amqpService; + + // 使用cron表达式,每分钟的第10秒执行 + @Scheduled(cron = "40 * * * * ?") + public void pushCronMessage3() { + try { + String message="{\"deviceType\":1,\"hardwareVersions\":\"1.24.1.1\",\"iMSI\":\"460087939303126\",\"iccid\":\"898604F9262380193126\",\"imei\":\"865074051888625\",\"softwareVersions\":\"1.1.6.8\"}"; + amqpService.SendMessage("testOneQ3", message); + System.out.println("设备基础信息:Cron定时消息: " + LocalDateTime.now()); + }catch (Exception e){ + System.out.println("设备基础信息:Cron定时消息: 失败" +e.getMessage()); + } + } + @Scheduled(cron = "40 * * * * ?") + public void pushCronMessage2() { + try { + String message="{\"alarmType\":\"0\",\"batteryLevel\":100,\"dataBody\":\"{\\\"CSQ\\\":31,\\\"IMEI\\\":\\\"865074051888625\\\",\\\"alarm\\\":0,\\\"alarms_dat\\\":\\\"\\\",\\\"bat_level\\\":100,\\\"dev_model\\\":12,\\\"dev_type\\\":1,\\\"samp_time\\\":\\\"2000/1/1 1:1:7\\\",\\\"sensor_dat\\\":\\\"℃,MPa|null,0.0000\\\"}\",\"dataGroupNum\":2,\"devModel\":12,\"deviceType\":1,\"deviceid\":\"15208214865074051888625\",\"imei\":\"865074051888625\",\"passNum\":1,\"platformType\":\"AEP\",\"protocol\":\"mqtt\",\"sampTime\":\"2000/1/1 1:1:7\",\"sampleData\":\"0,0.0000\",\"sendTime\":\"20251229163715\",\"singalStrength\":31,\"sourcetype\":\"new_top\",\"time\":\"2025-12-29 16:37:15\",\"unit\":\"℃,MPa\",\"userName\":\"topsail\"}"; + amqpService.SendMessage("testOneQ2", message); + System.out.println("设备数据:Cron定时消息: " + LocalDateTime.now()); + }catch (Exception e){ + System.out.println("设备数据:Cron定时消息: 失败" +e.getMessage()); + } + } +} +