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.eclipse.paho.mqttv5.client.IMqttAsyncClient,org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
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
,ClientManager.ConnectCallback
,MqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
public class Mqttv5PahoMessageDrivenChannelAdapter
extends AbstractMqttMessageDrivenChannelAdapter<org.eclipse.paho.mqttv5.client.IMqttAsyncClient,org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
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, Artem Vozhdayenko, Matthias Thoma
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
topicLock
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock
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.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
ConstructorDescriptionMqttv5PahoMessageDrivenChannelAdapter
(String url, String clientId, String... topic) Mqttv5PahoMessageDrivenChannelAdapter
(org.eclipse.paho.mqttv5.client.MqttConnectionOptions connectionOptions, String clientId, String... topic) Mqttv5PahoMessageDrivenChannelAdapter
(ClientManager<org.eclipse.paho.mqttv5.client.IMqttAsyncClient, org.eclipse.paho.mqttv5.client.MqttConnectionOptions> clientManager, String... topic) Use this constructor when you need to use a singleClientManager
(for instance, to reuse an MQTT connection). -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a topic to the subscribed list.void
authPacketArrived
(int reasonCode, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties) void
connectComplete
(boolean isReconnect) Called when the connection to the server is completed successfully.void
connectComplete
(boolean reconnect, String serverURI) void
deliveryComplete
(org.eclipse.paho.mqttv5.client.IMqttToken token) void
destroy()
void
disconnected
(org.eclipse.paho.mqttv5.client.MqttDisconnectResponse disconnectResponse) protected void
doStart()
Take no action by default.protected void
doStop()
Take no action by default.org.eclipse.paho.mqttv5.client.MqttConnectionOptions
Return information about the connection.void
messageArrived
(String topic, org.eclipse.paho.mqttv5.common.MqttMessage mqttMessage) void
mqttErrorOccurred
(org.eclipse.paho.mqttv5.common.MqttException exception) protected void
onInit()
Subclasses may implement this for initialization logic.void
removeTopic
(String... topic) Remove a topic (or topics) from the subscribed list.void
setConverter
(MqttMessageConverter converter) void
setHeaderMapper
(HeaderMapper<org.eclipse.paho.mqttv5.common.packet.MqttProperties> headerMapper) void
setMessageConverter
(SmartMessageConverter messageConverter) void
setPayloadType
(Class<?> payloadType) Set the type of the target message payload to produce after conversion from MQTT message.void
setPersistence
(org.eclipse.paho.mqttv5.client.MqttClientPersistence persistence) Methods inherited from class org.springframework.integration.mqtt.inbound.AbstractMqttMessageDrivenChannelAdapter
addTopic, addTopics, getApplicationEventPublisher, getClientId, getClientManager, getCompletionTimeout, getComponentType, getConverter, getDisconnectCompletionTimeout, getQos, getTopic, getUrl, isManualAcks, setApplicationEventPublisher, setCompletionTimeout, setDisconnectCompletionTimeout, setManualAcks, setQos
Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport
afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageAttributes, getErrorMessageStrategy, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, isObserved, registerObservationRegistry, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setObservationConvention, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisher
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
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, 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.beans.factory.BeanNameAware
setBeanName
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getOverrides, getThisAs, isLoggingEnabled, registerMetricsCaptor, setLoggingEnabled, setManagedName, setManagedType
Methods inherited from interface org.springframework.integration.mqtt.core.MqttComponent
getBeanName
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
Mqttv5PahoMessageDrivenChannelAdapter
-
Mqttv5PahoMessageDrivenChannelAdapter
-
Mqttv5PahoMessageDrivenChannelAdapter
public Mqttv5PahoMessageDrivenChannelAdapter(ClientManager<org.eclipse.paho.mqttv5.client.IMqttAsyncClient, org.eclipse.paho.mqttv5.client.MqttConnectionOptions> clientManager, String... topic) Use this constructor when you need to use a singleClientManager
(for instance, to reuse an MQTT connection).- Parameters:
clientManager
- The client manager.topic
- The topic(s).- Since:
- 6.0
-
-
Method Details
-
getConnectionInfo
public org.eclipse.paho.mqttv5.client.MqttConnectionOptions getConnectionInfo()Description copied from interface:MqttComponent
Return information about the connection.- Specified by:
getConnectionInfo
in interfaceMqttComponent<org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
- Returns:
- the information.
-
setPersistence
public void setPersistence(@Nullable org.eclipse.paho.mqttv5.client.MqttClientPersistence persistence) -
setConverter
- Overrides:
setConverter
in classAbstractMqttMessageDrivenChannelAdapter<org.eclipse.paho.mqttv5.client.IMqttAsyncClient,
org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
-
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 toMqttMessage
class 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:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractMqttMessageDrivenChannelAdapter<org.eclipse.paho.mqttv5.client.IMqttAsyncClient,
org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
-
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
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Specified by:
destroy
in interfaceIntegrationManagement
- Overrides:
destroy
in classAbstractMqttMessageDrivenChannelAdapter<org.eclipse.paho.mqttv5.client.IMqttAsyncClient,
org.eclipse.paho.mqttv5.client.MqttConnectionOptions>
-
addTopic
Description copied from class:AbstractMqttMessageDrivenChannelAdapter
Add a topic to the subscribed list.- Overrides:
addTopic
in classAbstractMqttMessageDrivenChannelAdapter<org.eclipse.paho.mqttv5.client.IMqttAsyncClient,
org.eclipse.paho.mqttv5.client.MqttConnectionOptions> - 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<org.eclipse.paho.mqttv5.client.IMqttAsyncClient,
org.eclipse.paho.mqttv5.client.MqttConnectionOptions> - Parameters:
topic
- The topic.
-
messageArrived
- Specified by:
messageArrived
in interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
disconnected
public void disconnected(org.eclipse.paho.mqttv5.client.MqttDisconnectResponse disconnectResponse) - Specified by:
disconnected
in interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
mqttErrorOccurred
public void mqttErrorOccurred(org.eclipse.paho.mqttv5.common.MqttException exception) - Specified by:
mqttErrorOccurred
in interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
deliveryComplete
public void deliveryComplete(org.eclipse.paho.mqttv5.client.IMqttToken token) - Specified by:
deliveryComplete
in interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
connectComplete
public void connectComplete(boolean isReconnect) Description copied from interface:ClientManager.ConnectCallback
Called when the connection to the server is completed successfully.- Specified by:
connectComplete
in interfaceClientManager.ConnectCallback
- Parameters:
isReconnect
- if true, the connection was the result of automatic reconnect.
-
connectComplete
- Specified by:
connectComplete
in interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-
authPacketArrived
public void authPacketArrived(int reasonCode, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties) - Specified by:
authPacketArrived
in interfaceorg.eclipse.paho.mqttv5.client.MqttCallback
-