diff --git a/config.js b/config.js index 3a4f8cdc..6a72f0a2 100644 --- a/config.js +++ b/config.js @@ -319,7 +319,7 @@ config.iota = { /** * map {name: function} of extra transformations avaliable at JEXL plugin -* see https://github.com/telefonicaid/iotagent-node-lib/tree/master/doc/expressionLanguage.md#available-functions + * see https://github.com/telefonicaid/iotagent-node-lib/tree/master/doc/expressionLanguage.md#available-functions */ config.jexlTransformations = {}; diff --git a/docs/deprecated.md b/docs/deprecated.md index ee88841d..a048c528 100644 --- a/docs/deprecated.md +++ b/docs/deprecated.md @@ -39,10 +39,10 @@ in the case you want to use old versions: The following table provides information about the last iotagent-json version supporting currently removed features: -| **Removed feature** | **Last iotagent-json version supporting feature** | **That version release date** | -| ---------------------- | --------------------------------------------------- | ----------------------------- | -| NGSIv1 API | 1.17.0 | February 18th, 2021 | -| Support to Node.js v4 | 1.9.0 | December 19th, 2018 | -| Support to Node.js v6 | 1.10.0 | May 22nd, 2019 | -| Support to Node.js v8 | 1.14.0 | April 7th, 2020 | -| Support to Node.js v10 | 1.17.0 | February 18th, 2021 | +| **Removed feature** | **Last iotagent-json version supporting feature** | **That version release date** | +| ---------------------- | ------------------------------------------------- | ----------------------------- | +| NGSIv1 API | 1.17.0 | February 18th, 2021 | +| Support to Node.js v4 | 1.9.0 | December 19th, 2018 | +| Support to Node.js v6 | 1.10.0 | May 22nd, 2019 | +| Support to Node.js v8 | 1.14.0 | April 7th, 2020 | +| Support to Node.js v10 | 1.17.0 | February 18th, 2021 | diff --git a/docs/installationguide.md b/docs/installationguide.md index 83f2b35f..7b5f6797 100644 --- a/docs/installationguide.md +++ b/docs/installationguide.md @@ -136,8 +136,8 @@ These are the currently available MQTT configuration options: order versions) or without the slash. See [discussion](https://github.com/telefonicaid/iotagent-node-lib/issues/866). - **clean**: this flag is by default true, set to false to receive QoS 1 and 2 messages while offline. -- **clientId**: string ID which identifies client in mqtt broker. By default is using a string composed by a fixed prefix - `iotajson_` and a random suffix, i.e. `iotajson_43bf8a3a`. +- **clientId**: string ID which identifies client in mqtt broker. By default is using a string composed by a fixed + prefix `iotajson_` and a random suffix, i.e. `iotajson_43bf8a3a`. TLS options (i.e. **ca**, **cert**, **key**, **rejectUnauthorized**) are directly linked with the ones supported by the [tls module of Node.js](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options). @@ -147,6 +147,7 @@ TLS options (i.e. **ca**, **cert**, **key**, **rejectUnauthorized**) are directl The `config.amqp` section of the config file contains all the information needed to connect to the AMQP Broker from the IoT Agent. The following attributes are accepted: +- **protocol**: protocol to use for connecting with the AMQP broker (`amqp`, `amqps`). The default is `amqp` - **host**: Host where the AMQP Broker is located. - **port**: Port where the AMQP Broker is listening - **username**: username that identifies the IOTA against the AMQP broker (optional). @@ -203,6 +204,7 @@ The ones relating specific JSON bindings are described in the following table. | IOTA_MQTT_CLEAN | mqtt.clean | | IOTA_MQTT_CLIENT_ID | mqtt.clientId | | IOTA_MQTT_DISABLED | mqtt.disabled | +| IOTA_AMQP_PROTOCOL | amqp.protocol | | IOTA_AMQP_HOST | amqp.host | | IOTA_AMQP_PORT | amqp.port | | IOTA_AMQP_USERNAME | amqp.username | diff --git a/lib/bindings/AMQPBinding.js b/lib/bindings/AMQPBinding.js index fd868a65..9fde33d5 100644 --- a/lib/bindings/AMQPBinding.js +++ b/lib/bindings/AMQPBinding.js @@ -92,9 +92,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; @@ -114,8 +112,8 @@ function start(callback) { retryTime = constants.AMQP_DEFAULT_RETRY_TIME; } - let uri = 'amqp://'; - + let uri = config.getConfig().amqp.protocol ? config.getConfig().amqp.protocol + `://` : 'amqp://'; + if (amqpConfig.username && amqpConfig.password) { uri += amqpConfig.username + ':' + amqpConfig.password + '@'; } @@ -125,7 +123,7 @@ function start(callback) { uri += ':' + amqpConfig.port; } } - + let isConnecting = false; let numRetried = 0; diff --git a/lib/configService.js b/lib/configService.js index db4ddce8..a6d729bd 100644 --- a/lib/configService.js +++ b/lib/configService.js @@ -71,6 +71,7 @@ function processEnvironmentVariables() { 'IOTA_MQTT_CLEAN', 'IOTA_MQTT_CLIENT_ID', 'IOTA_MQTT_DISABLED', + 'IOTA_AMQP_PROTOCOL', 'IOTA_AMQP_HOST', 'IOTA_AMQP_PORT', 'IOTA_AMQP_USERNAME', @@ -108,6 +109,7 @@ function processEnvironmentVariables() { 'IOTA_MQTT_DISABLED' ]; const amqpVariables = [ + 'IOTA_AMQP_PROTOCOL', 'IOTA_AMQP_HOST', 'IOTA_AMQP_PORT', 'IOTA_AMQP_USERNAME', @@ -229,7 +231,7 @@ function processEnvironmentVariables() { config.mqtt.clientId = process.env.IOTA_MQTT_CLIENT_ID; } - if (process.env.IOTA_MQTT_DISABLED && process.env.IOTA_MQTT_DISABLED.trim().toLowerCase() === 'true'){ + if (process.env.IOTA_MQTT_DISABLED && process.env.IOTA_MQTT_DISABLED.trim().toLowerCase() === 'true') { config.mqtt.disabled = true; } @@ -237,6 +239,10 @@ function processEnvironmentVariables() { config.amqp = config.amqp || {}; } + if (process.env.IOTA_AMQP_PROTOCOL) { + config.amqp.protocol = process.env.IOTA_AMQP_PROTOCOL; + } + if (process.env.IOTA_AMQP_HOST) { config.amqp.host = process.env.IOTA_AMQP_HOST; } @@ -274,7 +280,7 @@ function processEnvironmentVariables() { config.amqp.retryTime = process.env.IOTA_AMQP_RETRY_TIME; } - if (process.env.IOTA_AMQP_DISABLED && process.env.IOTA_AMQP_DISABLED.trim().toLowerCase() === 'true'){ + if (process.env.IOTA_AMQP_DISABLED && process.env.IOTA_AMQP_DISABLED.trim().toLowerCase() === 'true') { config.amqp.disabled = true; } diff --git a/package.json b/package.json index 38425119..eab8aa88 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ }, "keywords": [], "dependencies": { - "amqplib": "~0.5.1", + "amqplib": "~0.10.3", "async": "2.6.4", "body-parser": "1.20.0", "dateformat": "3.0.3", diff --git a/test/unit/startup-test.js b/test/unit/startup-test.js index 44773961..e97c2f10 100644 --- a/test/unit/startup-test.js +++ b/test/unit/startup-test.js @@ -89,6 +89,7 @@ describe('Startup tests', function () { describe('When the AMQP transport is started with environment variables', function () { beforeEach(function () { + process.env.IOTA_AMQP_PROTOCOL = 'xxx'; process.env.IOTA_AMQP_HOST = 'localhost'; process.env.IOTA_AMQP_PORT = '9090'; process.env.IOTA_AMQP_USERNAME = 'useramqp'; @@ -102,6 +103,7 @@ describe('Startup tests', function () { }); afterEach(function () { + delete process.env.IOTA_AMQP_PROTOCOL; delete process.env.IOTA_AMQP_HOST; delete process.env.IOTA_AMQP_PORT; delete process.env.IOTA_AMQP_USERNAME;