Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/amqps protocol #689

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
14 changes: 7 additions & 7 deletions docs/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
6 changes: 4 additions & 2 deletions docs/installationguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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).
Expand Down Expand Up @@ -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 |
Expand Down
10 changes: 4 additions & 6 deletions lib/bindings/AMQPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 + '@';
}
Expand All @@ -125,7 +123,7 @@ function start(callback) {
uri += ':' + amqpConfig.port;
}
}

let isConnecting = false;
let numRetried = 0;

Expand Down
10 changes: 8 additions & 2 deletions lib/configService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -108,6 +109,7 @@ function processEnvironmentVariables() {
'IOTA_MQTT_DISABLED'
];
const amqpVariables = [
'IOTA_AMQP_PROTOCOL',
'IOTA_AMQP_HOST',
'IOTA_AMQP_PORT',
'IOTA_AMQP_USERNAME',
Expand Down Expand Up @@ -229,14 +231,18 @@ 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;
}

if (anyIsSet(amqpVariables)) {
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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"keywords": [],
"dependencies": {
"amqplib": "~0.5.1",
"amqplib": "~0.10.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be also mentioned in the CHANGES_NEXT_RELEASE file. Something like this:

- Upgrade amqplib dependency from ~0.5.1 to ~0.10.3

"async": "2.6.4",
"body-parser": "1.20.0",
"dateformat": "3.0.3",
Expand Down
2 changes: 2 additions & 0 deletions test/unit/startup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
Loading