Class Mqttv5PahoMessageDrivenChannelAdapter
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.Mqttv5PahoMessageDrivenChannelAdapter
- All Implemented Interfaces:
org.eclipse.paho.mqttv5.client.MqttCallback,Aware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,SmartInitializingSingleton,ApplicationContextAware,ApplicationEventPublisherAware,Lifecycle,Phased,SmartLifecycle,ExpressionCapable,MessageProducer,IntegrationPattern,MqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>,NamedComponent,ManageableLifecycle,ManageableSmartLifecycle,TrackableComponent
public class Mqttv5PahoMessageDrivenChannelAdapter
extends AbstractMqttMessageDrivenChannelAdapter
implements org.eclipse.paho.mqttv5.client.MqttCallback, MqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
The
AbstractMqttMessageDrivenChannelAdapter implementation for MQTT v5.
The MqttProperties are mapped via the provided HeaderMapper;
meanwhile the regular MqttMessage properties are always mapped into headers.
It is recommended to have the MqttConnectionOptions.setAutomaticReconnect(boolean)
set to true to let an internal IMqttAsyncClient instance to handle reconnects.
Otherwise, only the manual restart of this component can handle reconnects, e.g. via
MqttConnectionFailedEvent handling on disconnection.
See setPayloadType(java.lang.Class<?>) for more information about type conversion.- Since:
- 5.5.5
- Author:
- Artem Bilan, Mikhail Polivakha, Lucas Bowler, Matthias Thoma
-
Field Summary
Fields inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
DEFAULT_COMPLETION_TIMEOUT, topicLockFields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLockFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionMqttv5PahoMessageDrivenChannelAdapter(String url, String clientId, String... topic) Mqttv5PahoMessageDrivenChannelAdapter(org.eclipse.paho.mqttv5.client.MqttConnectionOptions connectionOptions, String clientId, String... topic) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a topic to the subscribed list.voidauthPacketArrived(int reasonCode, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties) voidconnectComplete(boolean reconnect, String serverURI) voiddeliveryComplete(org.eclipse.paho.mqttv5.client.IMqttToken token) voiddestroy()voiddisconnected(org.eclipse.paho.mqttv5.client.MqttDisconnectResponse disconnectResponse) protected voiddoStart()Take no action by default.protected voiddoStop()Take no action by default.org.eclipse.paho.mqttv5.client.MqttConnectionOptionsReturn information about the connection.voidmessageArrived(String topic, org.eclipse.paho.mqttv5.common.MqttMessage mqttMessage) voidmqttErrorOccurred(org.eclipse.paho.mqttv5.common.MqttException exception) protected voidonInit()Subclasses may implement this for initialization logic.voidremoveTopic(String... topic) Remove a topic (or topics) from the subscribed list.voidsetConverter(MqttMessageConverter converter) voidsetHeaderMapper(HeaderMapper<org.eclipse.paho.mqttv5.common.packet.MqttProperties> headerMapper) voidsetMessageConverter(SmartMessageConverter messageConverter) voidsetPayloadType(Class<?> payloadType) Set the type of the target message payload to produce after conversion from MQTT message.voidsetPersistence(org.eclipse.paho.mqttv5.client.MqttClientPersistence persistence) Methods inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
addTopic, addTopics, getApplicationEventPublisher, getClientId, getCompletionTimeout, getComponentType, getConverter, getQos, getTopic, getUrl, isManualAcks, setApplicationEventPublisher, setCompletionTimeout, setManualAcks, setQosMethods inherited from class org.springframework.integration.endpoint.MessageProducerSupport
afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisherMethods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stopMethods 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, waitMethods inherited from interface org.springframework.beans.factory.BeanNameAware
setBeanNameMethods inherited from interface org.springframework.integration.mqtt.core.MqttComponent
getBeanNameMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
Mqttv5PahoMessageDrivenChannelAdapter
-
Mqttv5PahoMessageDrivenChannelAdapter
-
-
Method Details
-
getConnectionInfo
public org.eclipse.paho.mqttv5.client.MqttConnectionOptions getConnectionInfo()Description copied from interface:MqttComponentReturn information about the connection.- Specified by:
getConnectionInfoin interfaceMqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>- Returns:
- the information.
-
setPersistence
public void setPersistence(@Nullable org.eclipse.paho.mqttv5.client.MqttClientPersistence persistence) -
setConverter
- Overrides:
setConverterin classAbstractMqttMessageDrivenChannelAdapter
-
setMessageConverter
-
setPayloadType
Set the type of the target message payload to produce after conversion from MQTT message. Defaults tobyte[].class- just extract MQTT message payload without conversion. Can be set toMqttMessageclass to produce the whole MQTT message as a payload.- Parameters:
payloadType- the expected payload type to convert MQTT message to.
-
setHeaderMapper
public void setHeaderMapper(HeaderMapper<org.eclipse.paho.mqttv5.common.packet.MqttProperties> headerMapper) -
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classMessageProducerSupport
-
doStart
protected void doStart()Description copied from class:MessageProducerSupportTake no action by default. Subclasses may override this if they need lifecycle-managed behavior. Protected by 'lifecycleLock'.- Overrides:
doStartin classMessageProducerSupport
-
doStop
protected void doStop()Description copied from class:MessageProducerSupportTake no action by default. Subclasses may override this if they need lifecycle-managed behavior.- Overrides:
doStopin classMessageProducerSupport
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean- Overrides:
destroyin classAbstractEndpoint
-
addTopic
Description copied from class:AbstractMqttMessageDrivenChannelAdapterAdd a topic to the subscribed list.- Overrides:
addTopicin classAbstractMqttMessageDrivenChannelAdapter- Parameters:
topic- The topic.qos- The qos.
-
removeTopic
Description copied from class:AbstractMqttMessageDrivenChannelAdapterRemove a topic (or topics) from the subscribed list.- Overrides:
removeTopicin classAbstractMqttMessageDrivenChannelAdapter- Parameters:
topic- The topic.
-
messageArrived
- Specified by:
messageArrivedin interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
disconnected
public void disconnected(org.eclipse.paho.mqttv5.client.MqttDisconnectResponse disconnectResponse) - Specified by:
disconnectedin interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
mqttErrorOccurred
public void mqttErrorOccurred(org.eclipse.paho.mqttv5.common.MqttException exception) - Specified by:
mqttErrorOccurredin interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
deliveryComplete
public void deliveryComplete(org.eclipse.paho.mqttv5.client.IMqttToken token) - Specified by:
deliveryCompletein interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
connectComplete
- Specified by:
connectCompletein interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
authPacketArrived
public void authPacketArrived(int reasonCode, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties) - Specified by:
authPacketArrivedin interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-