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

com.feingto.iot.server.handler.MqttHandlerChain Maven / Gradle / Ivy

There is a newer version: 1.2.5.RELEASE
Show newest version
package com.feingto.iot.server.handler;

import com.feingto.iot.common.model.mqtt.SendMessage;
import com.feingto.iot.common.model.mqtt.SubscribeMessage;
import com.feingto.iot.common.service.IAuth;
import com.feingto.iot.server.handler.mqtt.*;
import com.feingto.iot.server.service.PushService;
import org.apache.ignite.IgniteCache;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

/**
 * MQTT 消息处理链工厂
 *
 * @author longfei
 */
@Component
public class MqttHandlerChain {
    private static MqttHandlerChain instance;
    private static BaseMessageHandler handler;

    @Resource
    public PushService pushService;

    @Resource
    private IAuth authService;

    @Resource(name = "igniteSubscribe")
    private IgniteCache> igniteSubscribe;

    @Resource(name = "igniteRetained")
    private IgniteCache igniteRetained;

    @Resource(name = "igniteMessage")
    private IgniteCache> igniteMessage;

    @PostConstruct
    public void init() {
        instance = this;
    }

    public static MqttHandlerChain getInstance() {
        return instance;
    }

    public static BaseMessageHandler getHandler() {
        if (handler == null) {
            handler = initHandler();
        }
        return handler;
    }

    private static BaseMessageHandler initHandler() {
        return new ConnectHandler(instance.authService)
                .igniteSubscribe(instance.igniteSubscribe)
                .igniteRetained(instance.igniteRetained)
                .igniteMessage(instance.igniteMessage)
                .filter(new PublishHandler(instance.pushService))
                .filter(new PubackHandler())
                .filter(new PubrecHandler())
                .filter(new PubrelHandler(instance.pushService))
                .filter(new PubcompHandler())
                .filter(new SubscribeHandler())
                .filter(new UnSubscribeHandler())
                .filter(new PingreqHandler())
                .filter(new DisconnectHandler());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy