Interface MQTTSubscriptionStrategy
-
- All Known Implementing Classes:
AbstractMQTTSubscriptionStrategy,MQTTDefaultSubscriptionStrategy,MQTTVirtualTopicSubscriptionStrategy
public interface MQTTSubscriptionStrategySubscription management strategy used to control how MQTT clients subscribe to destination and how messages are addressed in order to arrive on the appropriate destinations.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MQTTProtocolConvertergetProtocolConverter()MQTTSubscriptiongetSubscription(ConsumerId consumer)Lookup anMQTTSubscriptioninstance based on knownConsumerIdvalue.voidinitialize(MQTTProtocolConverter protocol)Initialize the strategy before first use.booleanisControlTopic(ActiveMQDestination destination)Allows the protocol handler to interrogate an destination name to determine if it is equivalent to the MQTT control topic (starts with $).voidonConnect(org.fusesource.mqtt.codec.CONNECT connect)Allows the strategy to perform any needed actions on client connect prior to the CONNACK frame being sent back such as recovering old subscriptions and performing any clean session actions.voidonReSubscribe(MQTTSubscription subscription)Called when a client sends a duplicate subscribe request which should force any retained messages on that topic to be replayed again as though the client had just subscribed for the first time.ActiveMQDestinationonSend(String topicName)Intercepts PUBLISH operations from the client and allows the strategy to map the target destination so that the send operation will land in the destinations that this strategy has mapped the incoming subscribe requests to.StringonSend(ActiveMQDestination destination)Intercepts send operations from the broker and allows the strategy to map the target topic name so that the client sees a valid Topic name.byteonSubscribe(String topicName, org.fusesource.mqtt.client.QoS requestedQoS)Called when a new Subscription is being requested.byteonSubscribe(org.fusesource.mqtt.client.Topic topic)Called for each Topic that a client requests to subscribe to.voidonUnSubscribe(String topicName)Called when a client requests an un-subscribe a previous subscription.voidsetProtocolConverter(MQTTProtocolConverter parent)Sets theMQTTProtocolConverterthat is the parent of this strategy object.
-
-
-
Method Detail
-
initialize
void initialize(MQTTProtocolConverter protocol) throws MQTTProtocolException
Initialize the strategy before first use.- Parameters:
protocol- the MQTTProtocolConverter that is initializing the strategy- Throws:
MQTTProtocolException- if an error occurs during initialization.
-
onConnect
void onConnect(org.fusesource.mqtt.codec.CONNECT connect) throws MQTTProtocolExceptionAllows the strategy to perform any needed actions on client connect prior to the CONNACK frame being sent back such as recovering old subscriptions and performing any clean session actions.- Throws:
MQTTProtocolException- if an error occurs while processing the connect actions.
-
onSubscribe
byte onSubscribe(org.fusesource.mqtt.client.Topic topic) throws MQTTProtocolExceptionCalled for each Topic that a client requests to subscribe to. The strategy needs check each Topic for duplicate subscription requests and change of QoS state.- Parameters:
topic- the MQTT Topic instance being subscribed to.- Returns:
- the assigned QoS value given to the new subscription.
- Throws:
MQTTProtocolException- if an error occurs while processing the subscribe actions.
-
onSubscribe
byte onSubscribe(String topicName, org.fusesource.mqtt.client.QoS requestedQoS) throws MQTTProtocolException
Called when a new Subscription is being requested. This method allows the strategy to create a specific type of subscription for the client such as mapping topic subscriptions to Queues etc.- Parameters:
topicName- the requested Topic name to subscribe to.requestedQoS- the QoS level that the client has requested for this subscription.- Returns:
- the assigned QoS value given to the new subscription
- Throws:
MQTTProtocolException- if an error occurs while processing the subscribe actions.
-
onReSubscribe
void onReSubscribe(MQTTSubscription subscription) throws MQTTProtocolException
Called when a client sends a duplicate subscribe request which should force any retained messages on that topic to be replayed again as though the client had just subscribed for the first time. The method should not unsubscribe the client as it might miss messages sent while the subscription is being recreated.- Parameters:
subscription- the MQTTSubscription that contains the subscription state.- Throws:
MQTTProtocolException
-
onUnSubscribe
void onUnSubscribe(String topicName) throws MQTTProtocolException
Called when a client requests an un-subscribe a previous subscription.- Parameters:
topicName- the name of the Topic the client wishes to unsubscribe from.- Throws:
MQTTProtocolException- if an error occurs during the un-subscribe processing.
-
onSend
ActiveMQDestination onSend(String topicName)
Intercepts PUBLISH operations from the client and allows the strategy to map the target destination so that the send operation will land in the destinations that this strategy has mapped the incoming subscribe requests to.- Parameters:
topicName- the targeted Topic that the client sent the message to.- Returns:
- an ActiveMQ Topic instance that lands the send in the correct destinations.
-
onSend
String onSend(ActiveMQDestination destination)
Intercepts send operations from the broker and allows the strategy to map the target topic name so that the client sees a valid Topic name.- Parameters:
destination- the destination that the message was dispatched from- Returns:
- an Topic name that is valid for the receiving client.
-
isControlTopic
boolean isControlTopic(ActiveMQDestination destination)
Allows the protocol handler to interrogate an destination name to determine if it is equivalent to the MQTT control topic (starts with $). Since the mapped destinations that the strategy might alter the naming scheme the strategy must provide a way to reverse map and determine if the destination was originally an MQTT control topic.- Parameters:
destination- the destination to query.- Returns:
- true if the destination is an MQTT control topic.
-
setProtocolConverter
void setProtocolConverter(MQTTProtocolConverter parent)
Sets theMQTTProtocolConverterthat is the parent of this strategy object.- Parameters:
parent- theMQTTProtocolConverterthat owns this strategy.
-
getProtocolConverter
MQTTProtocolConverter getProtocolConverter()
- Returns:
- the
MQTTProtocolConverterthat owns this strategy.
-
getSubscription
MQTTSubscription getSubscription(ConsumerId consumer)
Lookup anMQTTSubscriptioninstance based on knownConsumerIdvalue.- Parameters:
consumer- the consumer ID to lookup.- Returns:
- the
MQTTSubscriptionfor the consumer or null if no subscription exists.
-
-