public class MqttStreamer<K,V> extends StreamAdapter<org.eclipse.paho.client.mqttv3.MqttMessage,K,V> implements org.eclipse.paho.client.mqttv3.MqttCallback
IgniteDataStreamer
instance,
using Eclipse Paho as an MQTT client.
You must also provide a StreamSingleTupleExtractor
or a StreamMultipleTupleExtractor
to extract
cache tuples out of the incoming message.
This Streamer has many features:
MqttConnectOptions
to support features like last will testament, persistent
sessions, etc.setConnectOptions(MqttConnectOptions)
setter.ignite
Constructor and Description |
---|
MqttStreamer() |
Modifier and Type | Method and Description |
---|---|
void |
connectionLost(Throwable throwable)
Implements the
MqttCallback.connectionLost(Throwable) callback method for the MQTT client to inform the
streamer that the connection has been lost. |
void |
deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
Empty implementation of
MqttCallback.deliveryComplete(IMqttDeliveryToken) . |
String |
getBrokerUrl()
Gets the broker URL.
|
String |
getClientId()
Gets the client ID, either the one set by the user or the automatically generated one.
|
org.eclipse.paho.client.mqttv3.MqttConnectOptions |
getConnectOptions()
Gets the currently used MQTT client connect options.
|
Integer |
getDisconnectForciblyTimeout()
Gets the timeout if disconnecting forcibly.
|
Integer |
getDisconnectQuiesceTimeout()
Gets the disconnect quiesce timeout.
|
org.eclipse.paho.client.mqttv3.MqttClientPersistence |
getPersistence()
Gets the currently set persistence mechanism.
|
List<Integer> |
getQualitiesOfService()
Gets the qualities of service for multiple topics.
|
Integer |
getQualityOfService()
Gets the quality of service set by the user for a single topic consumption.
|
com.github.rholder.retry.StopStrategy |
getRetryStopStrategy()
Gets the retry stop strategy.
|
com.github.rholder.retry.WaitStrategy |
getRetryWaitStrategy()
Gets the retry wait strategy.
|
String |
getTopic()
Gets the subscribed topic.
|
List<String> |
getTopics()
Gets the topics subscribed to.
|
boolean |
isBlockUntilConnected()
Gets whether to block the start() method until connected for the first time.
|
boolean |
isConnected()
Returns whether this streamer is connected by delegating to the underlying
MqttClient.isConnected() |
boolean |
isDisconnectForcibly()
Gets whether this MQTT client will disconnect forcibly when shutting down.
|
boolean |
isStopped()
Returns whether this streamer is stopped.
|
void |
messageArrived(String topic,
org.eclipse.paho.client.mqttv3.MqttMessage message)
Implements the
MqttCallback.messageArrived(String, MqttMessage) to receive an MQTT message. |
void |
setBlockUntilConnected(boolean blockUntilConnected)
Sets whether to block the start() method until connected for the first time.
|
void |
setBrokerUrl(String brokerUrl)
Sets the broker URL (compulsory).
|
void |
setClientId(String clientId)
Sets the MQTT client ID (optional).
|
void |
setConnectOptions(org.eclipse.paho.client.mqttv3.MqttConnectOptions connectOptions)
Sets the MQTT client connect options, where users can configured the last will and testament, durability, etc.
|
void |
setDisconnectForcibly(boolean disconnectForcibly)
Sets whether to disconnect forcibly or not when shutting down.
|
void |
setDisconnectForciblyTimeout(Integer disconnectForciblyTimeout)
Sets the timeout if disconnecting forcibly.
|
void |
setDisconnectQuiesceTimeout(Integer disconnectQuiesceTimeout)
Sets the quiesce timeout on disconnection.
|
void |
setPersistence(org.eclipse.paho.client.mqttv3.MqttClientPersistence persistence)
Sets the persistence mechanism.
|
void |
setQualitiesOfService(List<Integer> qualitiesOfService)
Sets the qualities of service to use for multiple topic subscriptions.
|
void |
setQualityOfService(Integer qualityOfService)
Sets the quality of service to use for a single topic subscription (optional).
|
void |
setRetryStopStrategy(com.github.rholder.retry.StopStrategy retryStopStrategy)
Sets the strategy to determine when to stop retrying to (re-)connect.
|
void |
setRetryWaitStrategy(com.github.rholder.retry.WaitStrategy retryWaitStrategy)
Sets the strategy to determine how long to wait between retry attempts.
|
void |
setTopic(String topic)
Sets the topic to subscribe to, if a single topic.
|
void |
setTopics(List<String> topics)
Sets the topics to subscribe to, if many.
|
void |
start()
Starts streamer.
|
void |
stop()
Stops streamer.
|
addMessage, getIgnite, getMultipleTupleExtractor, getSingleTupleExtractor, getStreamer, getTupleExtractor, setIgnite, setMultipleTupleExtractor, setSingleTupleExtractor, setStreamer, setTupleExtractor
public void start() throws IgniteException
IgniteException
- If failed.public void stop() throws IgniteException
IgniteException
- If failed.public void connectionLost(Throwable throwable)
MqttCallback.connectionLost(Throwable)
callback method for the MQTT client to inform the
streamer that the connection has been lost.
connectionLost
in interface org.eclipse.paho.client.mqttv3.MqttCallback
public void messageArrived(String topic, org.eclipse.paho.client.mqttv3.MqttMessage message) throws Exception
MqttCallback.messageArrived(String, MqttMessage)
to receive an MQTT message.
messageArrived
in interface org.eclipse.paho.client.mqttv3.MqttCallback
Exception
public void deliveryComplete(org.eclipse.paho.client.mqttv3.IMqttDeliveryToken token)
MqttCallback.deliveryComplete(IMqttDeliveryToken)
.
Not required by the streamer as it doesn't produce messages.
deliveryComplete
in interface org.eclipse.paho.client.mqttv3.MqttCallback
public void setBrokerUrl(String brokerUrl)
brokerUrl
- The Broker URL (compulsory).public String getBrokerUrl()
public void setTopic(String topic)
topic
- The topic to subscribe to.public String getTopic()
public void setQualityOfService(Integer qualityOfService)
qualityOfService
- The quality of service.public Integer getQualityOfService()
public void setTopics(List<String> topics)
topics
- The topics.public List<String> getTopics()
public void setQualitiesOfService(List<Integer> qualitiesOfService)
topics
.qualitiesOfService
- The qualities of service.public List<Integer> getQualitiesOfService()
public void setClientId(String clientId)
clientId
- The client ID.public String getClientId()
public org.eclipse.paho.client.mqttv3.MqttClientPersistence getPersistence()
public void setPersistence(org.eclipse.paho.client.mqttv3.MqttClientPersistence persistence)
persistence
- A configurable persistence mechanism.public org.eclipse.paho.client.mqttv3.MqttConnectOptions getConnectOptions()
public void setConnectOptions(org.eclipse.paho.client.mqttv3.MqttConnectOptions connectOptions)
connectOptions
- The MQTT client connect options.public void setDisconnectForcibly(boolean disconnectForcibly)
false
.disconnectForcibly
- Whether to disconnect forcibly or not. By default, it's false
.public boolean isDisconnectForcibly()
public void setDisconnectQuiesceTimeout(Integer disconnectQuiesceTimeout)
disconnectQuiesceTimeout
- The disconnect quiesce timeout.public Integer getDisconnectQuiesceTimeout()
public void setDisconnectForciblyTimeout(Integer disconnectForciblyTimeout)
disconnectForciblyTimeout
- The disconnect forcibly timeout.public Integer getDisconnectForciblyTimeout()
public void setRetryWaitStrategy(com.github.rholder.retry.WaitStrategy retryWaitStrategy)
retryWaitStrategy
- The retry wait strategy.public com.github.rholder.retry.WaitStrategy getRetryWaitStrategy()
public void setRetryStopStrategy(com.github.rholder.retry.StopStrategy retryStopStrategy)
retryStopStrategy
- The retry stop strategy.public com.github.rholder.retry.StopStrategy getRetryStopStrategy()
public void setBlockUntilConnected(boolean blockUntilConnected)
false
.blockUntilConnected
- Whether to block or not.public boolean isBlockUntilConnected()
false
.true
if should connect synchronously in start.public boolean isStopped()
true
if stopped; false
if not.public boolean isConnected()
MqttClient.isConnected()
true
if connected; false
if not.MqttClient.isConnected()
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.7.2 Release Date : February 6 2019