Class MQTTProtocolManager

  • All Implemented Interfaces:
    org.apache.activemq.artemis.core.server.management.NotificationListener, org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>

    public class MQTTProtocolManager
    extends org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManager<io.netty.handler.codec.mqtt.MqttMessage,​MQTTInterceptor,​MQTTConnection,​MQTTRedirectHandler>
    implements org.apache.activemq.artemis.core.server.management.NotificationListener
    MQTTProtocolManager
    • Method Detail

      • getDefaultMqttSessionExpiryInterval

        public int getDefaultMqttSessionExpiryInterval()
      • setDefaultMqttSessionExpiryInterval

        public MQTTProtocolManager setDefaultMqttSessionExpiryInterval​(int sessionExpiryInterval)
      • onNotification

        public void onNotification​(org.apache.activemq.artemis.core.server.management.Notification notification)
        Specified by:
        onNotification in interface org.apache.activemq.artemis.core.server.management.NotificationListener
      • getFactory

        public org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory getFactory()
        Specified by:
        getFactory in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • updateInterceptors

        public void updateInterceptors​(java.util.List incoming,
                                       java.util.List outgoing)
        Specified by:
        updateInterceptors in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • scanSessions

        public void scanSessions()
      • createConnectionEntry

        public org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry createConnectionEntry​(org.apache.activemq.artemis.spi.core.remoting.Acceptor acceptorUsed,
                                                                                                   org.apache.activemq.artemis.spi.core.remoting.Connection connection)
        Specified by:
        createConnectionEntry in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • acceptsNoHandshake

        public boolean acceptsNoHandshake()
        Specified by:
        acceptsNoHandshake in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • removeHandler

        public void removeHandler​(java.lang.String name)
        Specified by:
        removeHandler in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • handleBuffer

        public void handleBuffer​(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection,
                                 org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)
        Specified by:
        handleBuffer in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • addChannelHandlers

        public void addChannelHandlers​(io.netty.channel.ChannelPipeline pipeline)
        Specified by:
        addChannelHandlers in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • isProtocol

        public boolean isProtocol​(byte[] array)
        The protocol handler passes us an 8 byte long array from the transport. We sniff these first 8 bytes to see if they match the first 8 bytes from MQTT Connect packet. In many other protocols the protocol name is the first thing sent on the wire. However, in MQTT the protocol name doesn't come until later on in the CONNECT packet. In order to fully identify MQTT protocol via protocol name, we need up to 12 bytes. However, we can use other information from the connect packet to infer that the MQTT protocol is being used. This is enough to identify MQTT and add the Netty codec in the pipeline. The Netty codec takes care of things from here. MQTT CONNECT PACKET: See MQTT 3.1.1 Spec for more info. Byte 1: Fixed Header Packet Type. 0b0001000 (16) = MQTT Connect Byte 2-[N]: Remaining length of the Connect Packet (encoded with 1-4 bytes). The next set of bytes represents the UTF8 encoded string MQTT (MQTT 3.1.1) or MQIsdp (MQTT 3.1) Byte N: UTF8 MSB must be 0 Byte N+1: UTF8 LSB must be (4(MQTT) or 6(MQIsdp)) Byte N+1: M (first char from the protocol name). Max no bytes used in the sequence = 8.
        Specified by:
        isProtocol in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • handshake

        public void handshake​(org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnection connection,
                              org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)
        Specified by:
        handshake in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • websocketSubprotocolIdentifiers

        public java.util.List<java.lang.String> websocketSubprotocolIdentifiers()
        Specified by:
        websocketSubprotocolIdentifiers in interface org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,​MQTTRedirectHandler>
      • invokeIncoming

        public java.lang.String invokeIncoming​(io.netty.handler.codec.mqtt.MqttMessage mqttMessage,
                                               MQTTConnection connection)
      • invokeOutgoing

        public java.lang.String invokeOutgoing​(io.netty.handler.codec.mqtt.MqttMessage mqttMessage,
                                               MQTTConnection connection)
      • isClientConnected

        public boolean isClientConnected​(java.lang.String clientId,
                                         MQTTConnection connection)
      • removeConnectedClient

        public void removeConnectedClient​(java.lang.String clientId)
      • addConnectedClient

        public MQTTConnection addConnectedClient​(java.lang.String clientId,
                                                 MQTTConnection connection)
        Parameters:
        clientId -
        connection -
        Returns:
        the MQTTConnection that the added connection replaced or null if there was no previous entry for the clientId
      • getSessionState

        public MQTTSessionState getSessionState​(java.lang.String clientId)
      • removeSessionState

        public MQTTSessionState removeSessionState​(java.lang.String clientId)
      • getSessionStates

        public java.util.Map<java.lang.String,​MQTTSessionState> getSessionStates()
      • getConnectedClients

        public java.util.Map<java.lang.String,​MQTTConnection> getConnectedClients()
        For DEBUG only