ldcsaa
1
MQTT Java客户端的MqttSubscription
找不到这两个属性:
public class MqttSubscription {
private boolean mutable = true;
private String topic;
private int qos = 1;
private boolean noLocal = false;
private boolean retainAsPublished = false;
private int retainHandling = 0;
private int messageId;
}
ldcsaa
3
谢谢~~
MqttClient的subscribe()方法的确没办法设置 MqttProperties,但MqttAsyncClient可以设置。我目前是通过继承MqttClient,扩展subscribe方法,直接调用MqttAsyncClient来实现。
public class ExtMqttClient extends MqttClient
{
public IMqttToken subscribe(MqttSubscription subscription, Integer subscriptionIdentifier) throws MqttException
{
return subscribe(new MqttSubscription[] {subscription}, subscriptionIdentifier);
}
public IMqttToken subscribe(MqttSubscription[] subscriptions, Integer subscriptionIdentifier) throws MqttException
{
MqttProperties mqttProperties = new MqttProperties();
mqttProperties.setSubscriptionIdentifier(subscriptionIdentifier);
return subscribe(subscriptions, mqttProperties);
}
public IMqttToken subscribe(MqttSubscription subscription, MqttProperties mqttProperties) throws MqttException
{
IMqttToken tok = aClient.subscribe(subscription, null, null, (IMqttMessageListener)null, mqttProperties);
tok.waitForCompletion(getTimeToWait());
return tok;
}
public IMqttToken subscribe(MqttSubscription[] subscriptions, MqttProperties mqttProperties) throws MqttException
{
IMqttToken tok = aClient.subscribe(subscriptions, null, null, (IMqttMessageListener[])null, mqttProperties);
tok.waitForCompletion(getTimeToWait());
return tok;
}
}
ldcsaa
4
还有一个疑问:MqttProperties 的 setTopicAlias(Integer) 是Integer类型的,而上述客户端可以设置成字符串的。这是为何?