Package org.openremote.manager.mqtt
Class DefaultMQTTHandler
java.lang.Object
org.openremote.manager.mqtt.MQTTHandler
org.openremote.manager.mqtt.DefaultMQTTHandler
This handler uses the
ClientEventService to publish and subscribe to asset and attribute events; converting
subscription topics into AssetFilters to ensure only the correct events are returned for the subscription.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected final com.google.common.cache.Cache<String, org.apache.activemq.artemis.utils.collections.ConcurrentHashSet<String>> protected final com.google.common.cache.Cache<String, org.openremote.model.event.shared.EventSubscription<?>> static final intFields inherited from class org.openremote.manager.mqtt.MQTTHandler
clientEventService, clientSession, executorService, identityProvider, isKeycloak, messageBrokerService, mqttBrokerService, producer, timerService, TOKEN_MULTI_LEVEL_WILDCARD, TOKEN_SINGLE_LEVEL_WILDCARD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static org.openremote.model.asset.AssetFilter<?> buildAssetFilter(Topic topic) protected static org.openremote.model.attribute.AttributeEventbuildAttributeEvent(List<String> topicTokens, Object value, Long timestamp) booleancanPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Called to authorise a publish ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the publish is allowed otherwise return false.booleancanSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Called to authorise a subscription ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the subscription is allowed otherwise return false.protected LoggerintGets the priority of this handler which is used to determine the call order; handlers with a lower priority are initialised and started first.Get the set of topics this handler wants to subscribe to for incoming publish messages; messages that match these topics will be passed toMQTTHandler.onPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.openremote.manager.mqtt.Topic, io.netty.buffer.ByteBuf).protected static StringgetSessionKey(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) protected <T extends org.openremote.model.event.Event>
Consumer<T> getSubscriptionEventConsumer(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) protected static booleanisAssetTopic(Topic topic) protected static booleanisAttributeTopic(Topic topic) protected static booleanisAttributeValueWriteTopic(Topic topic) protected static booleanisAttributeWriteTopic(Topic topic) voidonConnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Will be called when any client connects; if returns false then subsequent handlers will not be calledvoidonConnectionLost(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Will be called when any client loses connectionvoidonDisconnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Will be called when any client disconnectsvoidonPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic, io.netty.buffer.ByteBuf body) Called to handle publish ifMQTTHandler.canPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.voidonSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Called to handle subscribe ifMQTTHandler.canSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.voidonUnsubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Called to handle unsubscribe ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true.voidonUserAssetLinksChanged(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, List<org.openremote.model.PersistenceEvent<org.openremote.model.asset.UserAssetLink>> changes) Called whenUserAssetLinks for a restricted user are changed and that user has an active connection (subject can be accessed from the connection).booleantopicMatches(Topic topic) Indicates if this handler will handle the specified topic; independent of whether it is a publish or subscribe.Methods inherited from class org.openremote.manager.mqtt.MQTTHandler
addPublishConsumer, addPublishTopicServerConfiguration, checkCanPublish, checkCanSubscribe, getAuthContextFromConnection, getAuthContextFromSecurityContext, getName, getPublishTopicAddressSettings, getSecurityContextFromSubject, getSubjectFromConnection, handlesTopic, init, onConnectionAuthenticated, publishMessage, start, stop, topicClientID, topicClientIdMatches, topicRealm, topicRealmAllowed, topicTokenCountGreaterThan, topicTokenIndexToString
-
Field Details
-
PRIORITY
public static final int PRIORITY- See Also:
-
ASSET_TOPIC
- See Also:
-
ATTRIBUTE_TOPIC
- See Also:
-
ATTRIBUTE_VALUE_TOPIC
- See Also:
-
ATTRIBUTE_VALUE_WRITE_TOPIC
- See Also:
-
ATTRIBUTE_WRITE_TOPIC
- See Also:
-
sessionSubscriptionConsumers
-
authorizationCache
-
eventSubscriptionCache
protected final com.google.common.cache.Cache<String,org.openremote.model.event.shared.EventSubscription<?>> eventSubscriptionCache
-
-
Constructor Details
-
DefaultMQTTHandler
public DefaultMQTTHandler()
-
-
Method Details
-
getPriority
public int getPriority()Description copied from class:MQTTHandlerGets the priority of this handler which is used to determine the call order; handlers with a lower priority are initialised and started first.- Overrides:
getPriorityin classMQTTHandler
-
onConnect
public void onConnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerWill be called when any client connects; if returns false then subsequent handlers will not be called- Overrides:
onConnectin classMQTTHandler
-
onDisconnect
public void onDisconnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerWill be called when any client disconnects- Overrides:
onDisconnectin classMQTTHandler
-
onConnectionLost
public void onConnectionLost(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerWill be called when any client loses connection- Overrides:
onConnectionLostin classMQTTHandler
-
topicMatches
Description copied from class:MQTTHandlerIndicates if this handler will handle the specified topic; independent of whether it is a publish or subscribe. Should generally check the third token onwards unlessMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)has been overridden.- Specified by:
topicMatchesin classMQTTHandler
-
getLogger
- Specified by:
getLoggerin classMQTTHandler
-
canSubscribe
public boolean canSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Description copied from class:MQTTHandlerCalled to authorise a subscription ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the subscription is allowed otherwise return false.- Specified by:
canSubscribein classMQTTHandler
-
canPublish
public boolean canPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Description copied from class:MQTTHandlerCalled to authorise a publish ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the publish is allowed otherwise return false.- Specified by:
canPublishin classMQTTHandler
-
onSubscribe
public void onSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Description copied from class:MQTTHandlerCalled to handle subscribe ifMQTTHandler.canSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.- Specified by:
onSubscribein classMQTTHandler
-
onUnsubscribe
public void onUnsubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Description copied from class:MQTTHandlerCalled to handle unsubscribe ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true.- Specified by:
onUnsubscribein classMQTTHandler
-
getPublishListenerTopics
Description copied from class:MQTTHandlerGet the set of topics this handler wants to subscribe to for incoming publish messages; messages that match these topics will be passed toMQTTHandler.onPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.openremote.manager.mqtt.Topic, io.netty.buffer.ByteBuf).- Specified by:
getPublishListenerTopicsin classMQTTHandler
-
onPublish
public void onPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic, io.netty.buffer.ByteBuf body) Description copied from class:MQTTHandlerCalled to handle publish ifMQTTHandler.canPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.- Specified by:
onPublishin classMQTTHandler
-
onUserAssetLinksChanged
public void onUserAssetLinksChanged(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, List<org.openremote.model.PersistenceEvent<org.openremote.model.asset.UserAssetLink>> changes) Description copied from class:MQTTHandlerCalled whenUserAssetLinks for a restricted user are changed and that user has an active connection (subject can be accessed from the connection).- Overrides:
onUserAssetLinksChangedin classMQTTHandler
-
buildAttributeEvent
-
buildAssetFilter
-
getSubscriptionEventConsumer
-
isAttributeTopic
-
isAttributeValueWriteTopic
-
isAttributeWriteTopic
-
isAssetTopic
-
getSessionKey
protected static String getSessionKey(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection)
-