Skip to content

Commit

Permalink
improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Spector committed Aug 12, 2014
1 parent 33a7446 commit 4a1e810
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi)
if (data.client == null) {
String broker = environmentSubstitute(meta.getBroker());
try {
data.client = new MqttClient(broker,
environmentSubstitute(meta.getClientId()));
String clientId = environmentSubstitute(meta.getClientId());
data.client = new MqttClient(broker, clientId);

MqttConnectOptions connectOptions = new MqttConnectOptions();
connectOptions.setCleanSession(true);
Expand All @@ -84,7 +84,8 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi)
}

logBasic(Messages.getString(
"MQTTClientStep.CreateMQTTClient.Message", broker));
"MQTTClientStep.CreateMQTTClient.Message", broker,
clientId));
data.client.connect(connectOptions);

} catch (MqttException e) {
Expand Down Expand Up @@ -145,10 +146,10 @@ public boolean processRow(StepMetaInterface smi, StepDataInterface sdi)
MqttMessage mqttMessage = new MqttMessage(message);
mqttMessage.setQos(qos);

logBasic(Messages.getString("MQTTClientStep.Log.SendingData",
topic, Integer.toString(qos)));
if (isRowLevel()) {
logRowlevel(Messages.getString(
"MQTTClientStep.Log.SendingData", topic,
data.inputFieldMeta.getString(r[data.inputFieldNr])));
logRowlevel(data.inputFieldMeta.getString(r[data.inputFieldNr]));
}
try {
data.client.publish(topic, mqttMessage);
Expand Down Expand Up @@ -179,16 +180,18 @@ public void stopRunning(StepMetaInterface smi, StepDataInterface sdi)
throws KettleException {

MQTTProducerData data = (MQTTProducerData) sdi;
try {
if (data.client.isConnected()) {
data.client.disconnect();
if (data.client != null) {
try {
if (data.client.isConnected()) {
data.client.disconnect();
}
data.client.close();
data.client = null;
} catch (MqttException e) {
logError(
Messages.getString("MQTTClientStep.ErrorClosingMQTTClient.Message"),
e);
}
data.client.close();
data.client = null;
} catch (MqttException e) {
logError(
Messages.getString("MQTTClientStep.ErrorClosingMQTTClient.Message"),
e);
}
super.stopRunning(smi, sdi);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
MQTTClientStep.CreateMQTTClient.Message=Connecting to MQTT broker\: {0}
MQTTClientStep.CreateMQTTClient.Message=Connecting to MQTT broker\: {0} as client ''{1}''
MQTTClientStep.WrongTimeoutValue.Message=Wrong connection timeout value\: {0}!
MQTTClientStep.WrongQOSValue.Message=Wrong QoS value\: {0}!
MQTTClientStep.ErrorCreateMQTTClient.Message=Error connecting to MQTT broker!
MQTTClientStep.ErrorClosingMQTTClient.Message=Error closing MQTT connection!
MQTTClientStep.ErrorPublishing.Message=Error publishing MQTT message!
MQTTClientStep.Log.SendingData=Sending data through MQTT topic ''{0}'' : {1}
MQTTClientStep.Log.SendingData=Sending data through MQTT topic ''{0}'' with QoS={1}
MQTTClientStep.ErrorInStepRunning=Error running step \: {0}
MQTTClientStep.Log.FieldNameIsNull=Input field name not specified\!
MQTTClientStep.Log.CouldntFindField=Couldn''t find field ''{0}'' in input stream\!
Expand Down

0 comments on commit 4a1e810

Please sign in to comment.