|
|
@ -77,6 +77,8 @@ public class TbMqttNode extends TbAbstractExternalNode { |
|
|
this.mqttNodeConfiguration = TbNodeUtils.convert(configuration, TbMqttNodeConfiguration.class); |
|
|
this.mqttNodeConfiguration = TbNodeUtils.convert(configuration, TbMqttNodeConfiguration.class); |
|
|
try { |
|
|
try { |
|
|
this.mqttClient = initClient(ctx); |
|
|
this.mqttClient = initClient(ctx); |
|
|
|
|
|
} catch (TbNodeException e) { |
|
|
|
|
|
throw e; |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
throw new TbNodeException(e); |
|
|
throw new TbNodeException(e); |
|
|
} |
|
|
} |
|
|
@ -119,8 +121,7 @@ public class TbMqttNode extends TbAbstractExternalNode { |
|
|
MqttClientConfig config = new MqttClientConfig(getSslContext()); |
|
|
MqttClientConfig config = new MqttClientConfig(getSslContext()); |
|
|
config.setOwnerId(getOwnerId(ctx)); |
|
|
config.setOwnerId(getOwnerId(ctx)); |
|
|
if (!StringUtils.isEmpty(this.mqttNodeConfiguration.getClientId())) { |
|
|
if (!StringUtils.isEmpty(this.mqttNodeConfiguration.getClientId())) { |
|
|
config.setClientId(this.mqttNodeConfiguration.isAppendClientIdSuffix() ? |
|
|
config.setClientId(getClientId(ctx)); |
|
|
this.mqttNodeConfiguration.getClientId() + "_" + ctx.getServiceId() : this.mqttNodeConfiguration.getClientId()); |
|
|
|
|
|
} |
|
|
} |
|
|
config.setCleanSession(this.mqttNodeConfiguration.isCleanSession()); |
|
|
config.setCleanSession(this.mqttNodeConfiguration.isCleanSession()); |
|
|
|
|
|
|
|
|
@ -146,6 +147,17 @@ public class TbMqttNode extends TbAbstractExternalNode { |
|
|
return client; |
|
|
return client; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getClientId(TbContext ctx) throws TbNodeException { |
|
|
|
|
|
String clientId = this.mqttNodeConfiguration.isAppendClientIdSuffix() ? |
|
|
|
|
|
this.mqttNodeConfiguration.getClientId() + "_" + ctx.getServiceId() : |
|
|
|
|
|
this.mqttNodeConfiguration.getClientId(); |
|
|
|
|
|
if (clientId.length() > 23) { |
|
|
|
|
|
throw new TbNodeException("Client ID is too long '" + clientId + "'. " + |
|
|
|
|
|
"The length of Client ID cannot be longer than 23, but current length is " + clientId.length() + ".", true); |
|
|
|
|
|
} |
|
|
|
|
|
return clientId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
MqttClient getMqttClient(TbContext ctx, MqttClientConfig config) { |
|
|
MqttClient getMqttClient(TbContext ctx, MqttClientConfig config) { |
|
|
return MqttClient.create(config, null, ctx.getExternalCallExecutor()); |
|
|
return MqttClient.create(config, null, ctx.getExternalCallExecutor()); |
|
|
} |
|
|
} |
|
|
|