Add Azure Service Bus support (#1107)

This commit is contained in:
Günther
2020-10-28 23:29:45 +01:00
committed by GitHub
parent 889267ebb6
commit 6f92ecb128
3 changed files with 58 additions and 10 deletions

View File

@@ -75,9 +75,16 @@ export class AmqpTrigger implements INodeType {
default: false,
description: 'Parse the body to an object.',
},
{
displayName: 'Convert JSON Body content from Byte Array to string',
name: 'jsonConvertByteArrayToString',
type: 'boolean',
default: false,
description: 'Convert JSON Body content (["body"]["content"]) from Byte Array to string - Azure Service Bus',
}
],
},
],
]
};
@@ -106,27 +113,42 @@ export class AmqpTrigger implements INodeType {
const container = require('rhea');
const connectOptions: ContainerOptions = {
host: credentials.hostname,
hostname: credentials.hostname,
port: credentials.port,
reconnect: true, // this id the default anyway
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
container_id: (durable ? clientname : null),
container_id: (durable ? clientname : null)
};
if (credentials.username || credentials.password) {
// Old rhea implementation. not shure if it is neccessary
container.options.username = credentials.username;
container.options.password = credentials.password;
connectOptions.username = credentials.username;
connectOptions.password = credentials.password;
}
if (credentials.transportType) {
connectOptions.transport = credentials.transportType;
}
let lastMsgId: number | undefined = undefined;
const self = this;
container.on('message', (context: any) => { // tslint:disable-line:no-any
// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
if (context.message.message_id && context.message.message_id === lastMsgId) {
// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
lastMsgId = context.message.message_id;
return;
}
console.log("new Message", context.message.message_id, lastMsgId);
lastMsgId = context.message.message_id;
let data = context.message;
if(options.jsonConvertByteArrayToString === true && data.body.content !== undefined) {
// The buffer is not ready... Stringify and parse back to load it.
let cont = JSON.stringify(data.body.content);
data.body = String.fromCharCode.apply(null,JSON.parse(cont).data);
}
if (options.jsonParseBody === true) {
data.body = JSON.parse(data.body);
@@ -135,6 +157,7 @@ export class AmqpTrigger implements INodeType {
data = data.body;
}
self.emit([self.helpers.returnJsonArray([data])]);
});
@@ -146,16 +169,16 @@ export class AmqpTrigger implements INodeType {
source: {
address: sink,
durable: 2,
expiry_policy: 'never',
expiry_policy: 'never'
},
credit_window: 1, // prefetch 1
credit_window: 1 // prefetch 1
};
} else {
clientOptions = {
source: {
address: sink,
},
credit_window: 1, // prefetch 1
credit_window: 1 // prefetch 1
};
}
connection.open_receiver(clientOptions);
@@ -176,7 +199,7 @@ export class AmqpTrigger implements INodeType {
await new Promise(( resolve, reject ) => {
const timeoutHandler = setTimeout(() => {
reject(new Error('Aborted, no message received within 30secs. This 30sec timeout is only set for "manually triggered execution". Active Workflows will listen indefinitely.'));
}, 30000);
}, 3000);
container.on('message', (context: any) => { // tslint:disable-line:no-any
// Check if the only property present in the message is body
// in which case we only emit the content of the body property