Class MQTTUtil
- java.lang.Object
-
- org.apache.activemq.artemis.core.protocol.mqtt.MQTTUtil
-
public class MQTTUtil extends Object
A Utility Class for creating Server Side objects and converting MQTT concepts to/from Artemis.
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description MQTTUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcalculateMessageSize(io.netty.handler.codec.mqtt.MqttPublishMessage message)static intcalculateRemainingLength(String topicName, io.netty.handler.codec.mqtt.MqttProperties properties, io.netty.buffer.ByteBuf payload)static MessagecreatePubRelMessage(MQTTSession session, SimpleString address, int messageId)static MessagecreateServerMessageFromByteBuf(MQTTSession session, SimpleString address, io.netty.handler.codec.mqtt.MqttPublishMessage mqttPublishMessage)static Pair<String,String>decomposeSharedSubscriptionTopicFilter(String topicFilter)MQTT shared subscriptions are specified with this syntax.static StringgetCoreAddressFromMqttTopic(String topicFilter, WildcardConfiguration wildcardConfiguration)This method takes the MQTT-related input and translates it into the proper name for a core address.static StringgetCoreQueueFromMqttTopic(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.static StringgetCoreRetainAddressFromMqttTopic(String topicFilter, WildcardConfiguration wildcardConfiguration)This is exactly the same asgetCoreAddressFromMqttTopic(String, WildcardConfiguration)except that it also prefixes the return withMQTT_RETAIN_ADDRESS_PREFIXstatic StringgetMqttTopicFromCoreAddress(String address, WildcardConfiguration wildcardConfiguration)static <T> TgetProperty(Class<T> type, io.netty.handler.codec.mqtt.MqttProperties properties, io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType propertyName)static <T> TgetProperty(Class<T> type, io.netty.handler.codec.mqtt.MqttProperties properties, io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType propertyName, T defaultReturnValue)static booleanisSharedSubscription(String topicFilter)static voidlogMessage(MQTTSessionState state, io.netty.handler.codec.mqtt.MqttMessage message, boolean inbound, MQTTVersion version)
-
-
-
Field Detail
-
DURABLE_MESSAGES
public static final boolean DURABLE_MESSAGES
- See Also:
- Constant Field Values
-
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_XA
public static final boolean SESSION_XA
- See Also:
- Constant Field Values
-
SESSION_AUTO_CREATE_QUEUE
public static final boolean SESSION_AUTO_CREATE_QUEUE
- See Also:
- Constant Field Values
-
DOLLAR
public static final char DOLLAR
- See Also:
- Constant Field Values
-
HASH
public static final char HASH
- See Also:
- Constant Field Values
-
PLUS
public static final char PLUS
- See Also:
- Constant Field Values
-
SLASH
public static final char SLASH
- See Also:
- Constant Field Values
-
MQTT_SESSION_STORE
public static final String MQTT_SESSION_STORE
- See Also:
- Constant Field Values
-
MQTT_RETAIN_ADDRESS_PREFIX
public static final String MQTT_RETAIN_ADDRESS_PREFIX
- 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_EXISTS_KEY
public static final String MQTT_USER_PROPERTY_EXISTS_KEY
- See Also:
- Constant Field Values
-
MQTT_USER_PROPERTY_KEY_PREFIX
public static final String MQTT_USER_PROPERTY_KEY_PREFIX
- See Also:
- Constant Field Values
-
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
-
MANAGEMENT_QUEUE_PREFIX
public static final String MANAGEMENT_QUEUE_PREFIX
- See Also:
- Constant Field Values
-
SHARED_SUBSCRIPTION_PREFIX
public static final String SHARED_SUBSCRIPTION_PREFIX
- See Also:
- Constant Field Values
-
FOUR_BYTE_INT_MAX
public static final long FOUR_BYTE_INT_MAX
-
TWO_BYTE_INT_MAX
public static final int TWO_BYTE_INT_MAX
-
VARIABLE_BYTE_INT_MAX
public static final int VARIABLE_BYTE_INT_MAX
- See Also:
- Constant Field Values
-
MAX_PACKET_SIZE
public static final int MAX_PACKET_SIZE
- See Also:
- Constant Field Values
-
KEEP_ALIVE_ADJUSTMENT
public static final long KEEP_ALIVE_ADJUSTMENT
- See Also:
- Constant Field Values
-
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
-
MQTT_WILDCARD
public static final WildcardConfiguration MQTT_WILDCARD
-
-
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. ThetopicFiltermay 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 filterclientId- the MQTT client ID, used for normal (i.e. non-shared) subscriptionswildcardConfiguration- theWildcardConfigurationgoverning 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. ThetopicFiltermust be normal (i.e. non-shared). It should not be in the format$share/<shareName>/<topicFilter>.- Parameters:
topicFilter- the MQTT topic filterwildcardConfiguration- theWildcardConfigurationgoverning the core broker- Returns:
- the name of the core addres based on the input
-
getCoreRetainAddressFromMqttTopic
public static String getCoreRetainAddressFromMqttTopic(String topicFilter, WildcardConfiguration wildcardConfiguration)
This is exactly the same asgetCoreAddressFromMqttTopic(String, WildcardConfiguration)except that it also prefixes the return withMQTT_RETAIN_ADDRESS_PREFIX- Parameters:
topicFilter- the MQTT topic filterwildcardConfiguration- theWildcardConfigurationgoverning the core broker- Returns:
- the name of the core address based on the input, stripping
MQTT_RETAIN_ADDRESS_PREFIXif it exists
-
getMqttTopicFromCoreAddress
public static String getMqttTopicFromCoreAddress(String address, WildcardConfiguration wildcardConfiguration)
- Parameters:
address- the core addresswildcardConfiguration- theWildcardConfigurationgoverning 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)
-
createPubRelMessage
public static Message createPubRelMessage(MQTTSession session, SimpleString address, int messageId)
-
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>withshareNameandtopicFilterrespectively ornullandtopicFilterif not in the shared-subscription format.
-
isSharedSubscription
public static boolean isSharedSubscription(String topicFilter)
- Parameters:
topicFilter- the topic filter- Returns:
trueif the input starts with$share/,falseotherwise
-
-