All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.iot.client.service.ScheduledService Maven / Gradle / Ivy

There is a newer version: 2.3.1.RELEASE
Show newest version
package com.feingto.iot.client.service;

import com.feingto.iot.common.service.MqttConsumer;
import com.feingto.iot.common.util.DateKit;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 定时消息任务
 *
 * @author longfei
 */
@Service
public class ScheduledService {
    @Resource
    private MqttConsumer mqttConsumer;

    @PostConstruct
    public void init() {
        Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> {
            mqttConsumer.publish("/topic/iot", "Welcome to IoT", true);
            mqttConsumer.publish("/topic/iot", "The time is " + DateKit.now());
            mqttConsumer.publish("/feingto/admin", "The time is " + DateKit.now(), 1);
        }, 10, 30, TimeUnit.SECONDS);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy