Class MqttPahoMessageDrivenChannelAdapter
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter
- All Implemented Interfaces:
org.eclipse.paho.client.mqttv3.MqttCallback
,Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,SmartInitializingSingleton
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,Phased
,SmartLifecycle
,ExpressionCapable
,MessageProducer
,IntegrationPattern
,MqttComponent<org.eclipse.paho.client.mqttv3.MqttConnectOptions>
,MqttPahoComponent
,NamedComponent
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
public class MqttPahoMessageDrivenChannelAdapter extends AbstractMqttMessageDrivenChannelAdapter implements org.eclipse.paho.client.mqttv3.MqttCallback, MqttPahoComponent
Eclipse Paho Implementation. When consuming
MqttIntegrationEvent
s
published by this component use MqttPahoComponent adapter = event.getSourceAsType()
to get a
reference, allowing you to obtain the bean name and MqttConnectOptions
. This
technique allows consumption of events from both inbound and outbound endpoints in the
same event listener.- Since:
- 4.0
- Author:
- Gary Russell, Artem Bilan
-
Field Summary
Fields Modifier and Type Field Description static long
DISCONNECT_COMPLETION_TIMEOUT
The default disconnect completion timeout in milliseconds.Fields inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
DEFAULT_COMPLETION_TIMEOUT, topicLock
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
Constructors Constructor Description MqttPahoMessageDrivenChannelAdapter(String url, String clientId, String... topic)
Use this constructor when you don't need additionalMqttConnectOptions
.MqttPahoMessageDrivenChannelAdapter(String url, String clientId, MqttPahoClientFactory clientFactory, String... topic)
Use this constructor for a single url (although it may be overridden if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
).MqttPahoMessageDrivenChannelAdapter(String clientId, MqttPahoClientFactory clientFactory, String... topic)
Use this constructor if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
. -
Method Summary
Modifier and Type Method Description void
addTopic(String topic, int qos)
Add a topic to the subscribed list.void
connectionLost(Throwable cause)
void
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
protected void
doStart()
Take no action by default.protected void
doStop()
Take no action by default.org.eclipse.paho.client.mqttv3.MqttConnectOptions
getConnectionInfo()
Return information about the connection.void
messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage mqttMessage)
protected void
onInit()
Subclasses may implement this for initialization logic.void
removeTopic(String... topic)
Remove a topic (or topics) from the subscribed list.void
setDisconnectCompletionTimeout(long completionTimeout)
Set the completion timeout when disconnecting.void
setRecoveryInterval(int recoveryInterval)
The time (ms) to wait between reconnection attempts.Methods inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
addTopic, addTopics, getApplicationEventPublisher, getClientId, getCompletionTimeout, getComponentType, getConverter, getQos, getTopic, getUrl, isManualAcks, setApplicationEventPublisher, setCompletionTimeout, setConverter, setManualAcks, setQos
Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport
afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisher
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
destroy, doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop
Methods 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, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.mqtt.core.MqttComponent
getBeanName
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:
- Constant Field Values
-
-
Constructor Details
-
MqttPahoMessageDrivenChannelAdapter
public MqttPahoMessageDrivenChannelAdapter(String url, String clientId, MqttPahoClientFactory clientFactory, String... topic)Use this constructor for a single url (although it may be overridden if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
).- Parameters:
url
- the URL.clientId
- The client id.clientFactory
- The client factory.topic
- The topic(s).
-
MqttPahoMessageDrivenChannelAdapter
public MqttPahoMessageDrivenChannelAdapter(String clientId, MqttPahoClientFactory clientFactory, String... topic)Use this constructor if the server URI(s) are provided by theMqttConnectOptions.getServerURIs()
provided by theMqttPahoClientFactory
.- Parameters:
clientId
- The client id.clientFactory
- The client factory.topic
- The topic(s).- Since:
- 4.1
-
MqttPahoMessageDrivenChannelAdapter
Use this constructor when you don't need additionalMqttConnectOptions
.- Parameters:
url
- The URL.clientId
- The client id.topic
- The topic(s).
-
-
Method Details
-
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
-
setRecoveryInterval
public void setRecoveryInterval(int recoveryInterval)The time (ms) to wait between reconnection attempts. Default 10000.- Parameters:
recoveryInterval
- the interval.- Since:
- 4.2.2
-
getConnectionInfo
public org.eclipse.paho.client.mqttv3.MqttConnectOptions getConnectionInfo()Description copied from interface:MqttComponent
Return information about the connection.- Specified by:
getConnectionInfo
in interfaceMqttComponent<org.eclipse.paho.client.mqttv3.MqttConnectOptions>
- Specified by:
getConnectionInfo
in interfaceMqttPahoComponent
- Returns:
- the information.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classMessageProducerSupport
-
doStart
protected void doStart()Description copied from class:MessageProducerSupport
Take no action by default. Subclasses may override this if they need lifecycle-managed behavior. Protected by 'lifecycleLock'.- Overrides:
doStart
in classMessageProducerSupport
-
doStop
protected void doStop()Description copied from class:MessageProducerSupport
Take no action by default. Subclasses may override this if they need lifecycle-managed behavior.- Overrides:
doStop
in classMessageProducerSupport
-
addTopic
Description copied from class:AbstractMqttMessageDrivenChannelAdapter
Add a topic to the subscribed list.- Overrides:
addTopic
in classAbstractMqttMessageDrivenChannelAdapter
- Parameters:
topic
- The topic.qos
- The qos.
-
removeTopic
Description copied from class:AbstractMqttMessageDrivenChannelAdapter
Remove a topic (or topics) from the subscribed list.- Overrides:
removeTopic
in classAbstractMqttMessageDrivenChannelAdapter
- Parameters:
topic
- The topic.
-
connectionLost
- Specified by:
connectionLost
in interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
messageArrived
- Specified by:
messageArrived
in interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
deliveryComplete
public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)- Specified by:
deliveryComplete
in interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-