Interface ClientManager<T,C>
- Type Parameters:
T- MQTT client typeC- MQTT connection options type (v5 or v3)
- All Superinterfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.Lifecycle, MqttComponent<C>, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
- All Known Implementing Classes:
AbstractMqttClientManager, Mqttv3ClientManager, Mqttv5ClientManager
public interface ClientManager<T,C>
extends org.springframework.context.SmartLifecycle, MqttComponent<C>
A utility abstraction over MQTT client which can be used in any MQTT-related component
without need to handle generic client callbacks, reconnects etc.
Using this manager in multiple MQTT integrations will preserve a single connection.
- Since:
- 6.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA contract for a custom callback onconnectCompleteevent from the client.static interfaceA contract for a default message handler on themessageArrivedevent from the client. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default completion timeout in milliseconds.static final longThe default disconnect completion timeout in milliseconds.static final LongFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCallback(ClientManager.ConnectCallback connectCallback) Register a callback for theconnectCompleteevent from the client.<M> voidaddDefaultMessageHandler(ClientManager.DefaultMessageHandler<M> defaultMessageHandler) Register a callback for themessageArrivedevent from the client.@Nullable TReturn the managed client.Return the managed client id.getUrl()Return the managed client url.booleanReturn the managed clients isConnected.booleanIf manual acknowledge has to be used; false by default.booleanremoveCallback(ClientManager.ConnectCallback connectCallback) Remove the callback from registration.<M> booleanremoveDefaultMessageHandler(ClientManager.DefaultMessageHandler<M> defaultMessageHandler) Remove the callback from registration.Methods inherited from interface org.springframework.beans.factory.BeanNameAware
setBeanNameMethods inherited from interface org.springframework.context.Lifecycle
isRunning, start, stopMethods inherited from interface MqttComponent
getBeanName, getConnectionInfoMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup, isPauseable, stop
-
Field Details
-
DEFAULT_COMPLETION_TIMEOUT
static final long DEFAULT_COMPLETION_TIMEOUTThe default completion timeout in milliseconds.- See Also:
-
QUIESCENT_TIMEOUT
-
DISCONNECT_COMPLETION_TIMEOUT
static final long DISCONNECT_COMPLETION_TIMEOUTThe default disconnect completion timeout in milliseconds.- See Also:
-
-
Method Details
-
getClient
-
getUrl
String getUrl()Return the managed client url.- Returns:
- the managed client url, never null.
- Since:
- 7.0
-
getClientId
String getClientId()Return the managed client id.- Returns:
- the managed client id, never null.
- Since:
- 7.0
-
isManualAcks
boolean isManualAcks()If manual acknowledge has to be used; false by default.- Returns:
- true if manual acknowledge has to be used.
-
addCallback
Register a callback for theconnectCompleteevent from the client.- Parameters:
connectCallback- aClientManager.ConnectCallbackto register.
-
removeCallback
Remove the callback from registration.- Parameters:
connectCallback- aClientManager.ConnectCallbackto unregister.- Returns:
- true if callback was removed.
-
addDefaultMessageHandler
Register a callback for themessageArrivedevent from the client.- Parameters:
defaultMessageHandler- aClientManager.DefaultMessageHandlerto register.- Since:
- 6.5.6
-
removeDefaultMessageHandler
<M> boolean removeDefaultMessageHandler(ClientManager.DefaultMessageHandler<M> defaultMessageHandler) Remove the callback from registration.- Parameters:
defaultMessageHandler- aClientManager.DefaultMessageHandlerto unregister.- Returns:
- true if callback was removed.
- Since:
- 6.5.6
-
isConnected
boolean isConnected()Return the managed clients isConnected.- Returns:
- the managed clients isConnected.
- Since:
- 6.4
-