Skip to content

Commit

Permalink
Merge pull request #763 from telefonicaid/task/ensure_srv_subsrvc_log…
Browse files Browse the repository at this point in the history
…_error_process_message2

the same fix for http, mqtt and amqp bindings
  • Loading branch information
fgalan authored Oct 10, 2023
2 parents a6f2572 + e2695df commit 1346a3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
13 changes: 7 additions & 6 deletions lib/bindings/AMQPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

/* eslint-disable consistent-return */

const iotAgentLib = require('iotagent-node-lib');
const config = require('../configService');
const constants = require('../constants');
const amqp = require('amqplib/callback_api');
const commons = require('./../commonBindings');
const fillService = iotAgentLib.fillService;
const async = require('async');
const context = {
let context = {
op: 'IOTAJSON.AMQP.Binding'
};
let amqpConn;
Expand Down Expand Up @@ -70,6 +72,7 @@ function queueListener(msg) {
function start(callback) {
let exchange;
let queue;
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
const amqpConfig = config.getConfig().amqp;
if (!amqpConfig) {
return config.getLogger().error(context, 'Error AMPQ is not configured');
Expand All @@ -92,9 +95,7 @@ function start(callback) {

let durable;

if (
amqpConfig.options && amqpConfig.options.durable
) {
if (amqpConfig.options && amqpConfig.options.durable) {
durable = amqpConfig.options.durable;
} else {
durable = constants.AMQP_DEFAULT_DURABLE;
Expand All @@ -115,7 +116,7 @@ function start(callback) {
}

let uri = 'amqp://';

if (amqpConfig.username && amqpConfig.password) {
uri += amqpConfig.username + ':' + amqpConfig.password + '@';
}
Expand All @@ -125,7 +126,7 @@ function start(callback) {
uri += ':' + amqpConfig.port;
}
}

let isConnecting = false;
let numRetried = 0;

Expand Down
6 changes: 4 additions & 2 deletions lib/bindings/HTTPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const fs = require('fs');
const iotAgentLib = require('iotagent-node-lib');
const regenerateTransid = iotAgentLib.regenerateTransid;
const finishSouthBoundTransaction = iotAgentLib.finishSouthBoundTransaction;
const fillService = iotAgentLib.fillService;
const intoTrans = iotAgentLib.intoTrans;
const _ = require('underscore');
const commandHandler = require('../commandHandler');
Expand All @@ -41,7 +42,7 @@ const https = require('https');
const commonBindings = require('../commonBindings');
const bodyParser = require('body-parser');
const constants = require('../constants');
const context = {
let context = {
op: 'IOTAJSON.HTTP.Binding'
};
const config = require('../configService');
Expand Down Expand Up @@ -255,7 +256,7 @@ function addTimestamp(req, res, next) {

function handleIncomingMeasure(req, res, next) {
let values;

context = fillService(context, { service: 'n/a', subservice: 'n/a' });
config
.getLogger()
.debug(context, 'Processing multiple HTTP measures for device [%s] with apiKey [%s]', req.deviceId, req.apiKey);
Expand Down Expand Up @@ -502,6 +503,7 @@ function deviceUpdatingHandler(device, callback) {
*/
function returnCommands(req, res, next) {
function updateCommandStatus(device, commandList) {
context = fillService(context, device);
function createCommandUpdate(command) {
return apply(
iotAgentLib.setCommandResult,
Expand Down
8 changes: 6 additions & 2 deletions lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ const fs = require('fs');
const iotAgentLib = require('iotagent-node-lib');
const mqtt = require('mqtt');
const commonBindings = require('../commonBindings');
const fillService = iotAgentLib.fillService;
const async = require('async');
const iotaUtils = require('../iotaUtils');
const constants = require('../constants');
const context = {
let context = {
op: 'IOTAJSON.MQTT.Binding'
};
let mqttClient;
Expand Down Expand Up @@ -132,6 +133,7 @@ function generateTopics(callback) {
* Recreate the MQTT subscriptions for all the registered devices.
*/
function recreateSubscriptions(callback) {
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
config.getLogger().debug(context, 'Recreating subscriptions for all devices');

function subscribeToTopics(topics, callback) {
Expand Down Expand Up @@ -166,6 +168,7 @@ function recreateSubscriptions(callback) {
function sendConfigurationToDevice(apiKey, deviceId, results, callback) {
const configurations = iotaUtils.createConfigurationNotification(results);
const options = {};
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
if (config.getConfig().mqtt.qos) {
options.qos = parseInt(config.getConfig().mqtt.qos) || 0;
}
Expand Down Expand Up @@ -228,6 +231,7 @@ function unsubscribeAll(callback) {
* Start the binding.
*/
function start(callback) {
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
const mqttConfig = config.getConfig().mqtt;
if (!mqttConfig) {
return config.getLogger().error(context, 'Error MQTT is not configured');
Expand Down Expand Up @@ -371,7 +375,7 @@ function stop(callback) {
function executeCommand(apiKey, device, cmdName, serializedPayload, contentType, callback) {
const options = {};
// retrieve command mqtt options from device
var commands = Object.assign({}, ...device.commands.map((c) => ({ [c.name]: c })));
const commands = Object.assign({}, ...device.commands.map((c) => ({ [c.name]: c })));

options.qos =
commands[cmdName].mqtt && commands[cmdName].mqtt.qos
Expand Down

0 comments on commit 1346a3c

Please sign in to comment.