public class MqttClientTemplate extends Object implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, org.springframework.core.Ordered
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_CLIENT_TEMPLATE_BEAN |
| 构造器和说明 |
|---|
MqttClientTemplate(MqttClientCreator clientCreator) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet() |
void |
afterSingletonsInstantiated() |
void |
destroy() |
boolean |
disconnect()
断开 mqtt 连接
|
org.tio.client.TioClientConfig |
getClientTioConfig()
获取 ClientTioConfig
|
org.tio.client.ClientChannelContext |
getContext()
获取 ClientChannelContext
|
MqttClient |
getMqttClient()
获取 MqttClient
|
int |
getOrder() |
org.tio.client.TioClient |
getTioClient()
获取 TioClient
|
boolean |
isConnected()
判断客户端跟服务端是否连接
|
boolean |
isDisconnected()
判断客户端跟服务端是否断开连接
|
boolean |
publish(String topic,
byte[] payload)
发布消息
|
boolean |
publish(String topic,
byte[] payload,
boolean retain)
发布消息
|
boolean |
publish(String topic,
byte[] payload,
net.dreamlu.iot.mqtt.codec.MqttQoS qos)
发布消息
|
boolean |
publish(String topic,
byte[] payload,
net.dreamlu.iot.mqtt.codec.MqttQoS qos,
boolean retain)
发布消息
|
boolean |
publish(String topic,
byte[] payload,
net.dreamlu.iot.mqtt.codec.MqttQoS qos,
boolean retain,
net.dreamlu.iot.mqtt.codec.MqttProperties properties)
发布消息
|
boolean |
publish(String topic,
byte[] payload,
net.dreamlu.iot.mqtt.codec.MqttQoS qos,
Consumer<net.dreamlu.iot.mqtt.codec.MqttMessageBuilders.PublishBuilder> builder)
发布消息
|
void |
reconnect()
重连
|
boolean |
reconnect(String ip,
int port)
重连到新的服务端节点
|
org.tio.utils.timer.TimerTask |
schedule(Runnable command,
long delay)
添加定时任务,注意:如果抛出异常,会终止后续任务,请自行处理异常
|
org.tio.utils.timer.TimerTask |
schedule(Runnable command,
long delay,
Executor executor)
添加定时任务,注意:如果抛出异常,会终止后续任务,请自行处理异常
|
org.tio.utils.timer.TimerTask |
scheduleOnce(Runnable command,
long delay)
添加定时任务
|
org.tio.utils.timer.TimerTask |
scheduleOnce(Runnable command,
long delay,
Executor executor)
添加定时任务
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
MqttClient |
subQos0(String topicFilter,
IMqttClientMessageListener listener)
订阅
|
MqttClient |
subQos1(String topicFilter,
IMqttClientMessageListener listener)
订阅
|
MqttClient |
subQos2(String topicFilter,
IMqttClientMessageListener listener)
订阅
|
MqttClient |
subscribe(List<MqttClientSubscription> subscriptionList)
批量订阅
|
MqttClient |
subscribe(List<MqttClientSubscription> subscriptionList,
net.dreamlu.iot.mqtt.codec.MqttProperties properties)
批量订阅
|
MqttClient |
subscribe(net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS,
String topicFilter,
IMqttClientMessageListener listener)
订阅
|
MqttClient |
subscribe(String[] topicFilters,
net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS,
IMqttClientMessageListener listener)
订阅
|
MqttClient |
subscribe(String[] topicFilters,
net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS,
IMqttClientMessageListener listener,
net.dreamlu.iot.mqtt.codec.MqttProperties properties)
订阅
|
MqttClient |
subscribe(String topicFilter,
net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS,
IMqttClientMessageListener listener)
订阅
|
MqttClient |
subscribe(String topicFilter,
net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS,
IMqttClientMessageListener listener,
net.dreamlu.iot.mqtt.codec.MqttProperties properties)
订阅
|
MqttClient |
unSubscribe(List<String> topicFilters)
取消订阅
|
MqttClient |
unSubscribe(String... topicFilters)
取消订阅
|
public MqttClientTemplate(MqttClientCreator clientCreator)
public MqttClient subQos0(String topicFilter, IMqttClientMessageListener listener)
topicFilter - topicFilterlistener - MqttMessageListenerpublic MqttClient subQos1(String topicFilter, IMqttClientMessageListener listener)
topicFilter - topicFilterlistener - MqttMessageListenerpublic MqttClient subQos2(String topicFilter, IMqttClientMessageListener listener)
topicFilter - topicFilterlistener - MqttMessageListenerpublic MqttClient subscribe(net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS, String topicFilter, IMqttClientMessageListener listener)
mqttQoS - MqttQoStopicFilter - topicFilterlistener - MqttMessageListenerpublic MqttClient subscribe(String topicFilter, net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS, IMqttClientMessageListener listener)
mqttQoS - MqttQoStopicFilter - topicFilterlistener - MqttMessageListenerpublic MqttClient subscribe(String topicFilter, net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS, IMqttClientMessageListener listener, net.dreamlu.iot.mqtt.codec.MqttProperties properties)
mqttQoS - MqttQoStopicFilter - topicFilterlistener - MqttMessageListenerproperties - MqttPropertiespublic MqttClient subscribe(String[] topicFilters, net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS, IMqttClientMessageListener listener)
topicFilters - topicFilter 数组mqttQoS - MqttQoSlistener - MqttMessageListenerpublic MqttClient subscribe(String[] topicFilters, net.dreamlu.iot.mqtt.codec.MqttQoS mqttQoS, IMqttClientMessageListener listener, net.dreamlu.iot.mqtt.codec.MqttProperties properties)
topicFilters - topicFilter 数组mqttQoS - MqttQoSlistener - MqttMessageListenerproperties - MqttPropertiespublic MqttClient subscribe(List<MqttClientSubscription> subscriptionList)
subscriptionList - 订阅集合public MqttClient subscribe(List<MqttClientSubscription> subscriptionList, net.dreamlu.iot.mqtt.codec.MqttProperties properties)
subscriptionList - 订阅集合properties - MqttPropertiespublic MqttClient unSubscribe(String... topicFilters)
topicFilters - topicFilter 集合public MqttClient unSubscribe(List<String> topicFilters)
topicFilters - topicFilter 集合public boolean publish(String topic, byte[] payload)
topic - topicpayload - 消息内容public boolean publish(String topic, byte[] payload, net.dreamlu.iot.mqtt.codec.MqttQoS qos)
topic - topicpayload - 消息内容qos - MqttQoSpublic boolean publish(String topic, byte[] payload, boolean retain)
topic - topicpayload - 消息内容retain - 是否在服务器上保留消息public boolean publish(String topic, byte[] payload, net.dreamlu.iot.mqtt.codec.MqttQoS qos, boolean retain)
topic - topicpayload - 消息体qos - MqttQoSretain - 是否在服务器上保留消息public boolean publish(String topic, byte[] payload, net.dreamlu.iot.mqtt.codec.MqttQoS qos, boolean retain, net.dreamlu.iot.mqtt.codec.MqttProperties properties)
topic - topicpayload - 消息体qos - MqttQoSretain - 是否在服务器上保留消息properties - MqttPropertiespublic boolean publish(String topic, byte[] payload, net.dreamlu.iot.mqtt.codec.MqttQoS qos, Consumer<net.dreamlu.iot.mqtt.codec.MqttMessageBuilders.PublishBuilder> builder)
topic - topicpayload - 消息体qos - MqttQoSbuilder - PublishBuilderpublic org.tio.utils.timer.TimerTask schedule(Runnable command, long delay)
command - runnabledelay - delaypublic org.tio.utils.timer.TimerTask schedule(Runnable command, long delay, Executor executor)
command - runnabledelay - delayexecutor - 用于自定义线程池,处理耗时业务public org.tio.utils.timer.TimerTask scheduleOnce(Runnable command, long delay)
command - runnabledelay - delaypublic org.tio.utils.timer.TimerTask scheduleOnce(Runnable command, long delay, Executor executor)
command - runnabledelay - delayexecutor - 用于自定义线程池,处理耗时业务public void reconnect()
public boolean reconnect(String ip, int port)
ip - ipport - portpublic boolean disconnect()
public org.tio.client.TioClient getTioClient()
public org.tio.client.TioClientConfig getClientTioConfig()
public org.tio.client.ClientChannelContext getContext()
public boolean isConnected()
public boolean isDisconnected()
public MqttClient getMqttClient()
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
throws org.springframework.beans.BeansException
setApplicationContext 在接口中 org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic void afterPropertiesSet()
throws Exception
afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBeanExceptionpublic void afterSingletonsInstantiated()
afterSingletonsInstantiated 在接口中 org.springframework.beans.factory.SmartInitializingSingletonpublic void destroy()
destroy 在接口中 org.springframework.beans.factory.DisposableBeanpublic int getOrder()
getOrder 在接口中 org.springframework.core.OrderedCopyright © 2024. All rights reserved.