Browse Source

新增定时任务

master
bgy 6 hours ago
parent
commit
b1e1a1b7cc
3 changed files with 44 additions and 3 deletions
  1. +4
    -1
      src/main/java/com/topsail/influxdb/OperateInfluxdbApplication.java
  2. +2
    -2
      src/main/java/com/topsail/influxdb/rabbitmq/AmqpListener.java
  3. +38
    -0
      src/main/java/com/topsail/influxdb/schdule/ScheduledMessageProducer.java

+ 4
- 1
src/main/java/com/topsail/influxdb/OperateInfluxdbApplication.java View File

@ -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 {


+ 2
- 2
src/main/java/com/topsail/influxdb/rabbitmq/AmqpListener.java View File

@ -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);


+ 38
- 0
src/main/java/com/topsail/influxdb/schdule/ScheduledMessageProducer.java View File

@ -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());
}
}
}

Loading…
Cancel
Save