Class MQTTUtil


  • public class MQTTUtil
    extends Object
    A Utility Class for creating Server Side objects and converting MQTT concepts to/from Artemis.
    • Field Detail

      • SESSION_AUTO_COMMIT_SENDS

        public static final boolean SESSION_AUTO_COMMIT_SENDS
        See Also:
        Constant Field Values
      • SESSION_AUTO_COMMIT_ACKS

        public static final boolean SESSION_AUTO_COMMIT_ACKS
        See Also:
        Constant Field Values
      • SESSION_PREACKNOWLEDGE

        public static final boolean SESSION_PREACKNOWLEDGE
        See Also:
        Constant Field Values
      • SESSION_AUTO_CREATE_QUEUE

        public static final boolean SESSION_AUTO_CREATE_QUEUE
        See Also:
        Constant Field Values
      • MQTT_QOS_LEVEL_KEY

        public static final SimpleString MQTT_QOS_LEVEL_KEY
      • MQTT_MESSAGE_ID_KEY

        public static final SimpleString MQTT_MESSAGE_ID_KEY
      • MQTT_MESSAGE_TYPE_KEY

        public static final SimpleString MQTT_MESSAGE_TYPE_KEY
      • MQTT_MESSAGE_RETAIN_KEY

        public static final SimpleString MQTT_MESSAGE_RETAIN_KEY
      • MQTT_MESSAGE_RETAIN_INITIAL_DISTRIBUTION_KEY

        public static final SimpleString MQTT_MESSAGE_RETAIN_INITIAL_DISTRIBUTION_KEY
      • MQTT_PAYLOAD_FORMAT_INDICATOR_KEY

        public static final SimpleString MQTT_PAYLOAD_FORMAT_INDICATOR_KEY
      • MQTT_RESPONSE_TOPIC_KEY

        public static final SimpleString MQTT_RESPONSE_TOPIC_KEY
      • MQTT_CORRELATION_DATA_KEY

        public static final SimpleString MQTT_CORRELATION_DATA_KEY
      • MQTT_USER_PROPERTY_KEY_PREFIX_SIMPLE

        public static final SimpleString MQTT_USER_PROPERTY_KEY_PREFIX_SIMPLE
      • MQTT_CONTENT_TYPE_KEY

        public static final SimpleString MQTT_CONTENT_TYPE_KEY
      • FOUR_BYTE_INT_MAX

        public static final long FOUR_BYTE_INT_MAX
      • TWO_BYTE_INT_MAX

        public static final int TWO_BYTE_INT_MAX
      • DEFAULT_SERVER_KEEP_ALIVE

        public static final int DEFAULT_SERVER_KEEP_ALIVE
        See Also:
        Constant Field Values
      • DEFAULT_TOPIC_ALIAS_MAX

        public static final int DEFAULT_TOPIC_ALIAS_MAX
      • DEFAULT_RECEIVE_MAXIMUM

        public static final int DEFAULT_RECEIVE_MAXIMUM
      • DEFAULT_MAXIMUM_PACKET_SIZE

        public static final int DEFAULT_MAXIMUM_PACKET_SIZE
        See Also:
        Constant Field Values
    • Constructor Detail

      • MQTTUtil

        public MQTTUtil()
    • Method Detail

      • getCoreQueueFromMqttTopic

        public static String getCoreQueueFromMqttTopic​(String topicFilter,
                                                       String clientId,
                                                       WildcardConfiguration wildcardConfiguration)
        This method takes the MQTT-related input and translates it into the proper name for a core subscription queue. The topicFilter may be either for a shared subscription in the format $share/<shareName>/<topicFilter> or a normal MQTT topic filter (e.g. a/b/#, a/+/c, a/b/c, etc.).
        Parameters:
        topicFilter - the MQTT topic filter
        clientId - the MQTT client ID, used for normal (i.e. non-shared) subscriptions
        wildcardConfiguration - the WildcardConfiguration governing the core broker
        Returns:
        the name of the core subscription queue based on the input
      • getCoreAddressFromMqttTopic

        public static String getCoreAddressFromMqttTopic​(String topicFilter,
                                                         WildcardConfiguration wildcardConfiguration)
        This method takes the MQTT-related input and translates it into the proper name for a core address. The topicFilter must be normal (i.e. non-shared). It should not be in the format $share/<shareName>/<topicFilter>.
        Parameters:
        topicFilter - the MQTT topic filter
        wildcardConfiguration - the WildcardConfiguration governing the core broker
        Returns:
        the name of the core addres based on the input
      • getMqttTopicFromCoreAddress

        public static String getMqttTopicFromCoreAddress​(String address,
                                                         WildcardConfiguration wildcardConfiguration)
        Parameters:
        address - the core address
        wildcardConfiguration - the WildcardConfiguration governing the core broker
        Returns:
        the name of the MQTT topic based on the input
      • createServerMessageFromByteBuf

        public static Message createServerMessageFromByteBuf​(MQTTSession session,
                                                             SimpleString address,
                                                             io.netty.handler.codec.mqtt.MqttPublishMessage mqttPublishMessage)
      • logMessage

        public static void logMessage​(MQTTSessionState state,
                                      io.netty.handler.codec.mqtt.MqttMessage message,
                                      boolean inbound,
                                      MQTTVersion version)
      • calculateRemainingLength

        public static int calculateRemainingLength​(String topicName,
                                                   io.netty.handler.codec.mqtt.MqttProperties properties,
                                                   io.netty.buffer.ByteBuf payload)
      • calculateMessageSize

        public static int calculateMessageSize​(io.netty.handler.codec.mqtt.MqttPublishMessage message)
      • getProperty

        public static <T> T getProperty​(Class<T> type,
                                        io.netty.handler.codec.mqtt.MqttProperties properties,
                                        io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType propertyName)
      • getProperty

        public static <T> T getProperty​(Class<T> type,
                                        io.netty.handler.codec.mqtt.MqttProperties properties,
                                        io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType propertyName,
                                        T defaultReturnValue)
      • decomposeSharedSubscriptionTopicFilter

        public static Pair<String,​String> decomposeSharedSubscriptionTopicFilter​(String topicFilter)
        MQTT shared subscriptions are specified with this syntax.
        Parameters:
        topicFilter - String in the format $share/<shareName>/<topicFilter>
        Returns:
        Pair<String, String> with shareName and topicFilter respectively or null and topicFilter if not in the shared-subscription format.
      • isSharedSubscription

        public static boolean isSharedSubscription​(String topicFilter)
        Parameters:
        topicFilter - the topic filter
        Returns:
        true if the input starts with $share/, false otherwise