Class AbstractMqttMessageHandler<T,C>
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.mqtt.outbound.AbstractMqttMessageHandler<T,C>
- Type Parameters:
T- MQTT Client typeC- MQTT connection options type (v5 or v3)
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>,Aware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,ApplicationContextAware,ApplicationEventPublisherAware,Lifecycle,Ordered,ExpressionCapable,Orderable,IntegrationPattern,NamedComponent,IntegrationManagement,ManageableLifecycle,TrackableComponent,MessageHandler,reactor.core.CoreSubscriber<Message<?>>
- Direct Known Subclasses:
MqttPahoMessageHandler,Mqttv5PahoMessageHandler
public abstract class AbstractMqttMessageHandler<T,C>
extends AbstractMessageHandler
implements ManageableLifecycle, ApplicationEventPublisherAware
Abstract class for MQTT outbound channel adapters.
- Since:
- 4.0
- Author:
- Gary Russell, Artem Bilan, Artem Vozhdayenko
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default completion timeout in milliseconds.static final longThe default disconnect completion timeout in milliseconds.protected final LockFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMqttMessageHandler(String url, String clientId) AbstractMqttMessageHandler(ClientManager<T, C> clientManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voiddoStart()protected abstract voiddoStop()protected ApplicationEventPublisherintIncremented each time the client is connected.protected ClientManager<T,C> protected longSubclasses may implement this method to provide component type information.protected MessageConverterprotected intprotected booleanprotected Stringprotected longprotected MessageProcessor<Integer>protected MessageProcessor<Boolean>protected MessageProcessor<String>protected StringgetUrl()protected voidhandleMessageInternal(Message<?> message) protected voidbooleanprotected voidonInit()Subclasses may implement this for initialization logic.protected abstract voidvoidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) voidsetCompletionTimeout(long completionTimeout) Set the completion timeout for async operations.voidsetConverter(MessageConverter converter) Set the message converter to use; if this is provided, the adapter qos and retained settings are ignored.voidsetDefaultQos(int defaultQos) Set the qos for messages if theqosExpressionevaluates to null.voidsetDefaultRetained(boolean defaultRetained) Set the retained boolean for messages if theretainedExpressionevaluates to null.voidsetDefaultTopic(String defaultTopic) Set the topic to which the message will be published if thetopicExpressionevaluates to `null`.voidsetDisconnectCompletionTimeout(long completionTimeout) Set the completion timeout when disconnecting.voidsetQosExpression(Expression qosExpression) Set the qos expression; default "headers['mqtt_qos']".voidsetQosExpressionString(String qosExpression) Set the qos expression; default "headers['mqtt_qos']".voidsetRetainedExpression(Expression retainedExpression) Set the retained expression; default "headers['mqtt_retained']".voidsetRetainedExpressionString(String retainedExpression) Set the retained expression; default "headers['mqtt_retained']".voidsetTopicExpression(Expression topicExpression) Set the topic expression; default "headers['mqtt_topic']".voidsetTopicExpressionString(String topicExpression) Set the topic expression; default "headers['mqtt_topic']".final voidstart()final voidstop()Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
DISCONNECT_COMPLETION_TIMEOUT
public static final long DISCONNECT_COMPLETION_TIMEOUTThe default disconnect completion timeout in milliseconds.- See Also:
-
DEFAULT_COMPLETION_TIMEOUT
public static final long DEFAULT_COMPLETION_TIMEOUTThe default completion timeout in milliseconds.- See Also:
-
lock
-
-
Constructor Details
-
AbstractMqttMessageHandler
-
AbstractMqttMessageHandler
-
-
Method Details
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
getApplicationEventPublisher
-
setDefaultTopic
Set the topic to which the message will be published if thetopicExpressionevaluates to `null`.- Parameters:
defaultTopic- the default topic.
-
getDefaultTopic
-
setTopicExpression
Set the topic expression; default "headers['mqtt_topic']".- Parameters:
topicExpression- the expression.- Since:
- 5.0
-
setTopicExpressionString
Set the topic expression; default "headers['mqtt_topic']".- Parameters:
topicExpression- the expression.- Since:
- 5.0
-
getTopicProcessor
-
setDefaultQos
public void setDefaultQos(int defaultQos) Set the qos for messages if theqosExpressionevaluates to null. Only applies if a message converter is not provided.- Parameters:
defaultQos- the default qos.- See Also:
-
getDefaultQos
protected int getDefaultQos() -
setQosExpression
Set the qos expression; default "headers['mqtt_qos']". Only applies if a message converter is not provided.- Parameters:
qosExpression- the expression.- Since:
- 5.0
- See Also:
-
setQosExpressionString
Set the qos expression; default "headers['mqtt_qos']". Only applies if a message converter is not provided.- Parameters:
qosExpression- the expression.- Since:
- 5.0
- See Also:
-
getQosProcessor
-
setDefaultRetained
public void setDefaultRetained(boolean defaultRetained) Set the retained boolean for messages if theretainedExpressionevaluates to null. Only applies if a message converter is not provided.- Parameters:
defaultRetained- the default defaultRetained.- See Also:
-
getDefaultRetained
protected boolean getDefaultRetained() -
setRetainedExpression
Set the retained expression; default "headers['mqtt_retained']". Only applies if a message converter is not provided.- Parameters:
retainedExpression- the expression.- Since:
- 5.0
- See Also:
-
setRetainedExpressionString
Set the retained expression; default "headers['mqtt_retained']". Only applies if a message converter is not provided.- Parameters:
retainedExpression- the expression.- Since:
- 5.0
- See Also:
-
getRetainedProcessor
-
setConverter
Set the message converter to use; if this is provided, the adapter qos and retained settings are ignored.- Parameters:
converter- the converter.
-
getConverter
-
getUrl
-
getClientId
-
getClientInstance
public int getClientInstance()Incremented each time the client is connected.- Returns:
- The instance;
- Since:
- 4.1
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
incrementClientInstance
protected void incrementClientInstance() -
setCompletionTimeout
public void setCompletionTimeout(long completionTimeout) Set the completion timeout for async operations. Not settable using the namespace. Default 30000L milliseconds.- Parameters:
completionTimeout- The timeout.- Since:
- 4.1
-
getCompletionTimeout
protected long getCompletionTimeout() -
setDisconnectCompletionTimeout
public void setDisconnectCompletionTimeout(long completionTimeout) Set the completion timeout when disconnecting. Not settable using the namespace. Default 5000L milliseconds.- Parameters:
completionTimeout- The timeout.- Since:
- 5.1.10
-
getDisconnectCompletionTimeout
protected long getDisconnectCompletionTimeout() -
getClientManager
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
start
public final void start()- Specified by:
startin interfaceLifecycle- Specified by:
startin interfaceManageableLifecycle
-
doStart
protected abstract void doStart() -
stop
public final void stop()- Specified by:
stopin interfaceLifecycle- Specified by:
stopin interfaceManageableLifecycle
-
doStop
protected abstract void doStop() -
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle
-
handleMessageInternal
- Specified by:
handleMessageInternalin classAbstractMessageHandler
-
publish
-