Class AbstractMqttMessageHandler
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.mqtt.outbound.AbstractMqttMessageHandler
- All Implemented Interfaces:
org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.Lifecycle,org.springframework.core.Ordered,org.springframework.integration.context.ExpressionCapable,org.springframework.integration.context.Orderable,org.springframework.integration.IntegrationPattern,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.IntegrationManagement,org.springframework.integration.support.management.ManageableLifecycle,org.springframework.integration.support.management.TrackableComponent,org.springframework.messaging.MessageHandler,reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>
- Direct Known Subclasses:
MqttPahoMessageHandler
public abstract class AbstractMqttMessageHandler
extends org.springframework.integration.handler.AbstractMessageHandler
implements org.springframework.integration.support.management.ManageableLifecycle
Abstract class for MQTT outbound channel adapters.
- Since:
- 4.0
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
Constructors Constructor Description AbstractMqttMessageHandler(java.lang.String url, java.lang.String clientId) -
Method Summary
Modifier and Type Method Description protected abstract voiddoStart()protected abstract voiddoStop()java.lang.StringgetClientId()intgetClientInstance()Incremented each time the client is connected.java.lang.StringgetComponentType()protected org.springframework.messaging.converter.MessageConvertergetConverter()protected java.lang.StringgetUrl()protected voidhandleMessageInternal(org.springframework.messaging.Message<?> message)protected voidincrementClientInstance()booleanisRunning()protected voidonInit()protected abstract voidpublish(java.lang.String topic, java.lang.Object mqttMessage, org.springframework.messaging.Message<?> message)voidsetConverter(org.springframework.messaging.converter.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(java.lang.String defaultTopic)Set the topic to which the message will be published if thetopicExpressionevaluates to `null`.voidsetQosExpression(org.springframework.expression.Expression qosExpression)Set the qos expression; default "headers['mqtt_qos']".voidsetQosExpressionString(java.lang.String qosExpression)Set the qos expression; default "headers['mqtt_qos']".voidsetRetainedExpression(org.springframework.expression.Expression retainedExpression)Set the retained expression; default "headers['mqtt_retained']".voidsetRetainedExpressionString(java.lang.String retainedExpression)Set the retained expression; default "headers['mqtt_retained']".voidsetTopicExpression(org.springframework.expression.Expression topicExpression)Set the topic expression; default "headers['mqtt_topic']".voidsetTopicExpressionString(java.lang.String topicExpression)Set the topic expression; default "headers['mqtt_topic']".voidstart()voidstop()Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribeMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, 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, getIntegrationProperty, 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, wait
-
Constructor Details
-
AbstractMqttMessageHandler
public AbstractMqttMessageHandler(@Nullable java.lang.String url, java.lang.String clientId)
-
-
Method Details
-
setDefaultTopic
public void setDefaultTopic(java.lang.String defaultTopic)Set the topic to which the message will be published if thetopicExpressionevaluates to `null`.- Parameters:
defaultTopic- the default topic.
-
setTopicExpression
public void setTopicExpression(org.springframework.expression.Expression topicExpression)Set the topic expression; default "headers['mqtt_topic']".- Parameters:
topicExpression- the expression.- Since:
- 5.0
-
setTopicExpressionString
public void setTopicExpressionString(java.lang.String topicExpression)Set the topic expression; default "headers['mqtt_topic']".- Parameters:
topicExpression- the expression.- Since:
- 5.0
-
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:
setConverter(MessageConverter)
-
setQosExpression
public void setQosExpression(org.springframework.expression.Expression qosExpression)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:
setConverter(MessageConverter)
-
setQosExpressionString
public void setQosExpressionString(java.lang.String qosExpression)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:
setConverter(MessageConverter)
-
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:
setConverter(MessageConverter)
-
setRetainedExpression
public void setRetainedExpression(org.springframework.expression.Expression retainedExpression)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:
setConverter(MessageConverter)
-
setRetainedExpressionString
public void setRetainedExpressionString(java.lang.String retainedExpression)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:
setConverter(MessageConverter)
-
setConverter
public void setConverter(org.springframework.messaging.converter.MessageConverter converter)Set the message converter to use; if this is provided, the adapter qos and retained settings are ignored.- Parameters:
converter- the converter.
-
getConverter
protected org.springframework.messaging.converter.MessageConverter getConverter() -
getUrl
@Nullable protected java.lang.String getUrl() -
getClientId
public java.lang.String getClientId() -
getClientInstance
public int getClientInstance()Incremented each time the client is connected.- Returns:
- The instance;
- Since:
- 4.1
-
getComponentType
public java.lang.String getComponentType()- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.handler.MessageHandlerSupport
-
incrementClientInstance
protected void incrementClientInstance() -
onInit
protected void onInit()- Overrides:
onInitin classorg.springframework.integration.context.IntegrationObjectSupport
-
start
public final void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle- Specified by:
startin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
doStart
protected abstract void doStart() -
stop
public final void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle- Specified by:
stopin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
doStop
protected abstract void doStop() -
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle- Specified by:
isRunningin interfaceorg.springframework.integration.support.management.ManageableLifecycle
-
handleMessageInternal
protected void handleMessageInternal(org.springframework.messaging.Message<?> message)- Specified by:
handleMessageInternalin classorg.springframework.integration.handler.AbstractMessageHandler
-
publish
protected abstract void publish(java.lang.String topic, java.lang.Object mqttMessage, org.springframework.messaging.Message<?> message)
-