Class MqttTransporter
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.transporter.Transporter
services.moleculer.transporter.MqttTransporter
- All Implemented Interfaces:
org.eclipse.paho.client.mqttv3.MqttCallback, MetricConstants, MoleculerLifecycle
public class MqttTransporter
extends Transporter
implements org.eclipse.paho.client.mqttv3.MqttCallback
MQTT Transporter (eg. for Mosquitto MQTT Server or ActiveMQ Server). MQTT is
a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was
designed as an extremely lightweight publish/subscribe messaging transport
(website: http://mqtt.org). Usage:
// https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client. mqttv3
compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.2.5'
ServiceBroker broker = ServiceBroker.builder().nodeID("node1").transporter(new MqttTransporter("localhost"))
.build();
Required dependency:// https://mvnrepository.com/artifact/org.eclipse.paho/org.eclipse.paho.client. mqttv3
compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.client.mqttv3', version: '1.2.5'
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected org.eclipse.paho.client.mqttv3.MqttAsyncClientprotected intprotected Propertiesprotected intprotected HostnameVerifierprotected booleanprotected intprotected intprotected intprotected Stringprotected org.eclipse.paho.client.mqttv3.persist.MemoryPersistenceprotected intprotected SocketFactoryprotected Propertiesprotected String[]protected StringFields inherited from class Transporter
checkTimeoutTimer, counterTransporterPacketsReceivedBytes, counterTransporterPacketsReceivedTotal, counterTransporterPacketsSentBytes, counterTransporterPacketsSentTotal, debug, debugHeartbeats, disconnectChannel, discoverBroadcastChannel, discoverChannel, eventbus, eventChannel, executor, gaugeTransitConnected, heartbeatChannel, heartbeatInterval, heartbeatTimeout, heartBeatTimer, infoBroadcastChannel, infoChannel, infoScheduled, infoScheduledAt, instanceID, lastReceivedMessageAt, metrics, monitor, namespace, nodeID, nodes, offlineTimeout, PACKET_DISCONNECT, PACKET_DISCOVER, PACKET_EVENT, PACKET_HEARTBEAT, PACKET_INFO, PACKET_PING, PACKET_PONG, PACKET_REQUEST, PACKET_RESPONSE, pingChannel, pongChannel, preferHostname, prefix, protocolVersion, registry, requestChannel, responseChannel, scheduler, serializer, serviceInvoker, subscriptionTimeout, uidGenerator, usingJsonSerializerFields inherited from class MoleculerComponent
broker, logger, nameFields inherited from interface MetricConstants
MOLECULER_CACHER_CLEAN_TIME, MOLECULER_CACHER_CLEAN_TIME_DESC, MOLECULER_CACHER_CLEAN_TOTAL, MOLECULER_CACHER_CLEAN_TOTAL_DESC, MOLECULER_CACHER_DEL_TIME, MOLECULER_CACHER_DEL_TIME_DESC, MOLECULER_CACHER_DEL_TOTAL, MOLECULER_CACHER_DEL_TOTAL_DESC, MOLECULER_CACHER_EXPIRED_TOTAL, MOLECULER_CACHER_EXPIRED_TOTAL_DESC, MOLECULER_CACHER_FOUND_TOTAL, MOLECULER_CACHER_FOUND_TOTAL_DESC, MOLECULER_CACHER_GET_TIME, MOLECULER_CACHER_GET_TIME_DESC, MOLECULER_CACHER_GET_TOTAL, MOLECULER_CACHER_GET_TOTAL_DESC, MOLECULER_CACHER_SET_TIME, MOLECULER_CACHER_SET_TIME_DESC, MOLECULER_CACHER_SET_TOTAL, MOLECULER_CACHER_SET_TOTAL_DESC, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL_DESC, MOLECULER_EVENT_BROADCAST_TOTAL, MOLECULER_EVENT_BROADCAST_TOTAL_DESC, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL_DESC, MOLECULER_EVENT_EMIT_TOTAL, MOLECULER_EVENT_EMIT_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_ACTIVE, MOLECULER_EVENT_RECEIVED_ACTIVE_DESC, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_TIME, MOLECULER_EVENT_RECEIVED_TIME_DESC, MOLECULER_EVENT_RECEIVED_TOTAL, MOLECULER_EVENT_RECEIVED_TOTAL_DESC, MOLECULER_EXECUTOR, MOLECULER_REQUEST_ACTIVE, MOLECULER_REQUEST_ACTIVE_DESC, MOLECULER_REQUEST_ERROR_TOTAL, MOLECULER_REQUEST_ERROR_TOTAL_DESC, MOLECULER_REQUEST_LEVELS, MOLECULER_REQUEST_LEVELS_DESC, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL_DESC, MOLECULER_REQUEST_TIME, MOLECULER_REQUEST_TIME_DESC, MOLECULER_REQUEST_TIMEOUT_TOTAL, MOLECULER_REQUEST_TIMEOUT_TOTAL_DESC, MOLECULER_REQUEST_TOTAL, MOLECULER_REQUEST_TOTAL_DESC, MOLECULER_SCHEDULER, MOLECULER_TRANSIT_CONNECTED, MOLECULER_TRANSIT_CONNECTED_DESC, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL_DESC, MOLECULER_TRANSIT_REQUESTS_ACTIVE, MOLECULER_TRANSIT_REQUESTS_ACTIVE_DESC, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL_DESC -
Constructor Summary
ConstructorsConstructorDescriptionMqttTransporter(String... urls) MqttTransporter(String username, String password, String... urls) -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()voidconnectionLost(Throwable cause) voiddeliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token) protected voidprotected voidAny I/O error occurred.intintintintintorg.eclipse.paho.client.mqttv3.persist.MemoryPersistenceintgetQos()String[]getUrls()booleanbooleanvoidmessageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage message) voidprotected voidvoidsetCleanSession(boolean cleanSession) voidsetConnectionTimeout(int connectionTimeout) voidsetCustomWebSocketHeaders(Properties customWebSocketHeaders) voidsetExecutorServiceTimeout(int executorServiceTimeout) voidsetHostnameVerifier(HostnameVerifier hostnameVerifier) voidsetHttpsHostnameVerificationEnabled(boolean httpsHostnameVerificationEnabled) voidsetKeepAliveInterval(int keepAliveInterval) voidsetMaxInflight(int maxInflight) voidsetMqttVersion(int mqttVersion) voidsetPassword(String password) voidsetPersistence(org.eclipse.paho.client.mqttv3.persist.MemoryPersistence persistence) voidsetQos(int qos) voidsetSocketFactory(SocketFactory socketFactory) voidsetSslClientProps(Properties sslClientProps) voidvoidsetUsername(String username) voidstopped()Closes transporter.io.datatree.PromiseMethods inherited from class Transporter
broadcastInfoPacket, broadcastNodeConnected, broadcastNodeDisconnected, broadcastNodeUpdated, broadcastTransporterConnected, broadcastTransporterDisconnected, channel, checkTimeouts, connected, connected, createPingPacket, getAddress, getAllNodeIDs, getCpuUsage, getDescriptor, getHeartbeatInterval, getHeartbeatTimeout, getInstanceID, getLastHeartbeatTime, getNamespace, getOfflineTimeout, getPrefix, getSerializer, getSubscriptionTimeout, isDebug, isDebugHeartbeats, isOnline, isPreferHostname, processReceivedMessage, processReceivedMessage, publish, received, scheduleInfoPacket, sendClosePacket, sendDataPacket, sendDisconnectPacket, sendDiscoverPacket, sendErrorPacket, sendEventPacket, sendHeartbeatPacket, sendInfoPacket, sendPongPacket, sendRequestPacket, setDebug, setDebugHeartbeats, setHeartbeatInterval, setHeartbeatTimeout, setNamespace, setOfflineTimeout, setPreferHostname, setPrefix, setSerializer, setSubscriptionTimeout, started, subscribe, updateNodeInfoMethods inherited from class MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
username
-
password
-
urls
-
qos
protected int qos -
cleanSession
protected boolean cleanSession -
persistence
protected org.eclipse.paho.client.mqttv3.persist.MemoryPersistence persistence -
connectionTimeout
protected int connectionTimeout -
executorServiceTimeout
protected int executorServiceTimeout -
httpsHostnameVerificationEnabled
protected boolean httpsHostnameVerificationEnabled -
keepAliveInterval
protected int keepAliveInterval -
maxInflight
protected int maxInflight -
mqttVersion
protected int mqttVersion -
socketFactory
-
hostnameVerifier
-
sslClientProps
-
customWebSocketHeaders
-
client
protected org.eclipse.paho.client.mqttv3.MqttAsyncClient client
-
-
Constructor Details
-
MqttTransporter
public MqttTransporter() -
MqttTransporter
-
MqttTransporter
-
-
Method Details
-
connect
public void connect()- Specified by:
connectin classTransporter
-
disconnect
protected void disconnect() -
reconnect
-
connectionLost
- Specified by:
connectionLostin interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
error
Description copied from class:TransporterAny I/O error occurred. Implementation-specific error handling goes here (reconnection, etc.).- Overrides:
errorin classTransporter- Parameters:
cause- I/O error
-
stopped
public void stopped()Closes transporter.- Specified by:
stoppedin interfaceMoleculerLifecycle- Overrides:
stoppedin classTransporter
-
subscribe
- Specified by:
subscribein classTransporter
-
publish
- Specified by:
publishin classTransporter
-
deliveryComplete
public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token) - Specified by:
deliveryCompletein interfaceorg.eclipse.paho.client.mqttv3.MqttCallback
-
messageArrived
-
getUrls
-
setUrls
-
getUsername
-
setUsername
-
getPassword
-
setPassword
-
getQos
public int getQos() -
setQos
public void setQos(int qos) -
isCleanSession
public boolean isCleanSession() -
setCleanSession
public void setCleanSession(boolean cleanSession) -
getPersistence
public org.eclipse.paho.client.mqttv3.persist.MemoryPersistence getPersistence() -
setPersistence
public void setPersistence(org.eclipse.paho.client.mqttv3.persist.MemoryPersistence persistence) -
getConnectionTimeout
public int getConnectionTimeout() -
setConnectionTimeout
public void setConnectionTimeout(int connectionTimeout) -
getExecutorServiceTimeout
public int getExecutorServiceTimeout() -
setExecutorServiceTimeout
public void setExecutorServiceTimeout(int executorServiceTimeout) -
isHttpsHostnameVerificationEnabled
public boolean isHttpsHostnameVerificationEnabled() -
setHttpsHostnameVerificationEnabled
public void setHttpsHostnameVerificationEnabled(boolean httpsHostnameVerificationEnabled) -
getKeepAliveInterval
public int getKeepAliveInterval() -
setKeepAliveInterval
public void setKeepAliveInterval(int keepAliveInterval) -
getMaxInflight
public int getMaxInflight() -
setMaxInflight
public void setMaxInflight(int maxInflight) -
getMqttVersion
public int getMqttVersion() -
setMqttVersion
public void setMqttVersion(int mqttVersion) -
getSocketFactory
-
setSocketFactory
-
getHostnameVerifier
-
setHostnameVerifier
-
getSslClientProps
-
setSslClientProps
-
getCustomWebSocketHeaders
-
setCustomWebSocketHeaders
-