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
,ComponentSourceAware
,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
Modifier and TypeFieldDescriptionstatic final long
The default completion timeout in milliseconds.static final long
The default disconnect completion timeout in milliseconds.protected final Lock
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionAbstractMqttMessageHandler
(String url, String clientId) AbstractMqttMessageHandler
(ClientManager<T, C> clientManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
doStart()
protected abstract void
doStop()
protected ApplicationEventPublisher
int
Incremented each time the client is connected.protected ClientManager<T,
C> protected long
Subclasses may implement this method to provide component type information.protected MessageConverter
protected int
protected boolean
protected String
protected long
protected MessageProcessor<Integer>
protected MessageProcessor<Boolean>
protected MessageProcessor<String>
protected String
getUrl()
protected void
handleMessageInternal
(Message<?> message) protected void
protected boolean
isAsync()
boolean
protected void
messageSentEvent
(Message<?> message, String topic, int messageId) protected void
onInit()
Subclasses may implement this for initialization logic.protected abstract void
protected void
sendDeliveryCompleteEvent
(int messageId) protected void
sendFailedDeliveryEvent
(int messageId, Throwable exception) void
setApplicationEventPublisher
(ApplicationEventPublisher applicationEventPublisher) void
setAsync
(boolean async) Set to true if you don't want to block when sending messages.void
setAsyncEvents
(boolean asyncEvents) WhensetAsync(boolean)
is true, setting this to true enables publication ofMqttMessageSentEvent
andMqttMessageDeliveredEvent
to be emitted.void
setCompletionTimeout
(long completionTimeout) Set the completion timeout for async operations.void
setConverter
(MessageConverter converter) Set the message converter to use; if this is provided, the adapter qos and retained settings are ignored.void
setDefaultQos
(int defaultQos) Set the qos for messages if theqosExpression
evaluates to null.void
setDefaultRetained
(boolean defaultRetained) Set the retained boolean for messages if theretainedExpression
evaluates to null.void
setDefaultTopic
(String defaultTopic) Set the topic to which the message will be published if thetopicExpression
evaluates to `null`.void
setDisconnectCompletionTimeout
(long completionTimeout) Set the completion timeout when disconnecting.void
setQosExpression
(Expression qosExpression) Set the qos expression; default "headers['mqtt_qos']".void
setQosExpressionString
(String qosExpression) Set the qos expression; default "headers['mqtt_qos']".void
setRetainedExpression
(Expression retainedExpression) Set the retained expression; default "headers['mqtt_retained']".void
setRetainedExpressionString
(String retainedExpression) Set the retained expression; default "headers['mqtt_retained']".void
setTopicExpression
(Expression topicExpression) Set the topic expression; default "headers['mqtt_topic']".void
setTopicExpressionString
(String topicExpression) Set the topic expression; default "headers['mqtt_topic']".final void
start()
final void
stop()
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods 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, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods 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:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
-
getApplicationEventPublisher
-
setDefaultTopic
Set the topic to which the message will be published if thetopicExpression
evaluates 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 theqosExpression
evaluates 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 theretainedExpression
evaluates 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:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in 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
-
setAsync
public void setAsync(boolean async) Set to true if you don't want to block when sending messages. Default false. When true, message sent/delivered events will be published for reception by a suitably configured 'ApplicationListener' or an event inbound-channel-adapter.- Parameters:
async
- true for async.- See Also:
-
isAsync
protected boolean isAsync() -
setAsyncEvents
public void setAsyncEvents(boolean asyncEvents) WhensetAsync(boolean)
is true, setting this to true enables publication ofMqttMessageSentEvent
andMqttMessageDeliveredEvent
to be emitted. Default false.- Parameters:
asyncEvents
- the asyncEvents.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
start
public final void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
-
doStart
protected abstract void doStart() -
stop
public final void stop()- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
-
doStop
protected abstract void doStop() -
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
-
handleMessageInternal
- Specified by:
handleMessageInternal
in classAbstractMessageHandler
-
messageSentEvent
-
sendDeliveryCompleteEvent
protected void sendDeliveryCompleteEvent(int messageId) -
sendFailedDeliveryEvent
-
publish
-