Class MQTTVirtualTopicSubscriptionStrategy
- java.lang.Object
-
- org.apache.activemq.transport.mqtt.strategy.AbstractMQTTSubscriptionStrategy
-
- org.apache.activemq.transport.mqtt.strategy.MQTTVirtualTopicSubscriptionStrategy
-
- All Implemented Interfaces:
BrokerServiceAware
,MQTTSubscriptionStrategy
public class MQTTVirtualTopicSubscriptionStrategy extends AbstractMQTTSubscriptionStrategy
Subscription strategy that converts all MQTT subscribes that would be durable to Virtual Topic Queue subscriptions. Also maps all publish requests to be prefixed with the VirtualTopic. prefix unless already present.
-
-
Field Summary
-
Fields inherited from class org.apache.activemq.transport.mqtt.strategy.AbstractMQTTSubscriptionStrategy
brokerService, consumerIdGenerator, mqttSubscriptionByTopic, protocol, restoredDurableSubs, subscriptionsByConsumerId
-
-
Constructor Summary
Constructors Constructor Description MQTTVirtualTopicSubscriptionStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 $).void
onConnect(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.void
onReSubscribe(MQTTSubscription mqttSubscription)
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.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.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.byte
onSubscribe(String topicName, org.fusesource.mqtt.client.QoS requestedQoS)
Called when a new Subscription is being requested.void
onUnSubscribe(String topicName)
Called when a client requests an un-subscribe a previous subscription.-
Methods inherited from class org.apache.activemq.transport.mqtt.strategy.AbstractMQTTSubscriptionStrategy
deleteDurableSubs, doSubscribe, doUnSubscribe, getNextConsumerId, getProtocolConverter, getSubscription, initialize, lookupSubscription, onSubscribe, restoreDurableSubs, setBrokerService, setProtocolConverter
-
-
-
-
Method Detail
-
onConnect
public void onConnect(org.fusesource.mqtt.codec.CONNECT connect) throws MQTTProtocolException
Description copied from interface:MQTTSubscriptionStrategy
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.- Throws:
MQTTProtocolException
- if an error occurs while processing the connect actions.
-
onSubscribe
public byte onSubscribe(String topicName, org.fusesource.mqtt.client.QoS requestedQoS) throws MQTTProtocolException
Description copied from interface:MQTTSubscriptionStrategy
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
public void onReSubscribe(MQTTSubscription mqttSubscription) throws MQTTProtocolException
Description copied from interface:MQTTSubscriptionStrategy
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.- Specified by:
onReSubscribe
in interfaceMQTTSubscriptionStrategy
- Overrides:
onReSubscribe
in classAbstractMQTTSubscriptionStrategy
- Parameters:
mqttSubscription
- the MQTTSubscription that contains the subscription state.- Throws:
MQTTProtocolException
-
onUnSubscribe
public void onUnSubscribe(String topicName) throws MQTTProtocolException
Description copied from interface:MQTTSubscriptionStrategy
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
public ActiveMQDestination onSend(String topicName)
Description copied from interface:MQTTSubscriptionStrategy
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.- Specified by:
onSend
in interfaceMQTTSubscriptionStrategy
- Overrides:
onSend
in classAbstractMQTTSubscriptionStrategy
- 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
public String onSend(ActiveMQDestination destination)
Description copied from interface:MQTTSubscriptionStrategy
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.- Specified by:
onSend
in interfaceMQTTSubscriptionStrategy
- Overrides:
onSend
in classAbstractMQTTSubscriptionStrategy
- Parameters:
destination
- the destination that the message was dispatched from- Returns:
- an Topic name that is valid for the receiving client.
-
isControlTopic
public boolean isControlTopic(ActiveMQDestination destination)
Description copied from interface:MQTTSubscriptionStrategy
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.- Specified by:
isControlTopic
in interfaceMQTTSubscriptionStrategy
- Overrides:
isControlTopic
in classAbstractMQTTSubscriptionStrategy
- Parameters:
destination
- the destination to query.- Returns:
- true if the destination is an MQTT control topic.
-
-