mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
⚡ Add Azure Service Bus support (#1107)
This commit is contained in:
parent
889267ebb6
commit
6f92ecb128
|
@ -36,5 +36,11 @@ export class Amqp implements ICredentialType {
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Transport Type',
|
||||||
|
name: 'transportType',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,16 @@ export class Amqp implements INodeType {
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Send the data as an object.',
|
description: 'Send the data as an object.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Send property',
|
||||||
|
name: 'sendOnlyProperty',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Send only this property - If empty the hole Json will be sent',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
||||||
|
@ -87,6 +94,7 @@ export class Amqp implements INodeType {
|
||||||
|
|
||||||
const connectOptions: ContainerOptions = {
|
const connectOptions: ContainerOptions = {
|
||||||
host: credentials.hostname,
|
host: credentials.hostname,
|
||||||
|
hostname: credentials.hostname,
|
||||||
port: credentials.port,
|
port: credentials.port,
|
||||||
reconnect: true, // this id the default anyway
|
reconnect: true, // this id the default anyway
|
||||||
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
||||||
|
@ -94,12 +102,23 @@ export class Amqp implements INodeType {
|
||||||
if (credentials.username || credentials.password) {
|
if (credentials.username || credentials.password) {
|
||||||
container.options.username = credentials.username;
|
container.options.username = credentials.username;
|
||||||
container.options.password = credentials.password;
|
container.options.password = credentials.password;
|
||||||
|
connectOptions.username = credentials.username;
|
||||||
|
connectOptions.password = credentials.password;
|
||||||
|
}
|
||||||
|
if (credentials.transportType) {
|
||||||
|
connectOptions.transport = credentials.transportType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const allSent = new Promise(( resolve ) => {
|
const allSent = new Promise(( resolve ) => {
|
||||||
container.on('sendable', (context: any) => { // tslint:disable-line:no-any
|
container.on('sendable', (context: any) => { // tslint:disable-line:no-any
|
||||||
|
|
||||||
let body: IDataObject | string = item.json;
|
let body: IDataObject | string = item.json;
|
||||||
|
let prop = options.sendOnlyProperty as string;
|
||||||
|
|
||||||
|
if(prop)
|
||||||
|
{
|
||||||
|
body = body[prop] as string;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.dataAsObject !== true) {
|
if (options.dataAsObject !== true) {
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
|
@ -107,7 +126,7 @@ export class Amqp implements INodeType {
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
application_properties: headerProperties,
|
application_properties: headerProperties,
|
||||||
body,
|
body
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendResult = context.sender.send(message);
|
const sendResult = context.sender.send(message);
|
||||||
|
|
|
@ -75,9 +75,16 @@ export class AmqpTrigger implements INodeType {
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Parse the body to an object.',
|
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 container = require('rhea');
|
||||||
const connectOptions: ContainerOptions = {
|
const connectOptions: ContainerOptions = {
|
||||||
host: credentials.hostname,
|
host: credentials.hostname,
|
||||||
|
hostname: credentials.hostname,
|
||||||
port: credentials.port,
|
port: credentials.port,
|
||||||
reconnect: true, // this id the default anyway
|
reconnect: true, // this id the default anyway
|
||||||
reconnect_limit: 50, // try for max 50 times, based on a back-off algorithm
|
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) {
|
if (credentials.username || credentials.password) {
|
||||||
|
// Old rhea implementation. not shure if it is neccessary
|
||||||
container.options.username = credentials.username;
|
container.options.username = credentials.username;
|
||||||
container.options.password = credentials.password;
|
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;
|
let lastMsgId: number | undefined = undefined;
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
container.on('message', (context: any) => { // tslint:disable-line:no-any
|
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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("new Message", context.message.message_id, lastMsgId);
|
||||||
|
lastMsgId = context.message.message_id;
|
||||||
|
|
||||||
let data = context.message;
|
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) {
|
if (options.jsonParseBody === true) {
|
||||||
data.body = JSON.parse(data.body);
|
data.body = JSON.parse(data.body);
|
||||||
|
@ -135,6 +157,7 @@ export class AmqpTrigger implements INodeType {
|
||||||
data = data.body;
|
data = data.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.emit([self.helpers.returnJsonArray([data])]);
|
self.emit([self.helpers.returnJsonArray([data])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -146,16 +169,16 @@ export class AmqpTrigger implements INodeType {
|
||||||
source: {
|
source: {
|
||||||
address: sink,
|
address: sink,
|
||||||
durable: 2,
|
durable: 2,
|
||||||
expiry_policy: 'never',
|
expiry_policy: 'never'
|
||||||
},
|
},
|
||||||
credit_window: 1, // prefetch 1
|
credit_window: 1 // prefetch 1
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
clientOptions = {
|
clientOptions = {
|
||||||
source: {
|
source: {
|
||||||
address: sink,
|
address: sink,
|
||||||
},
|
},
|
||||||
credit_window: 1, // prefetch 1
|
credit_window: 1 // prefetch 1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
connection.open_receiver(clientOptions);
|
connection.open_receiver(clientOptions);
|
||||||
|
@ -176,7 +199,7 @@ export class AmqpTrigger implements INodeType {
|
||||||
await new Promise(( resolve, reject ) => {
|
await new Promise(( resolve, reject ) => {
|
||||||
const timeoutHandler = setTimeout(() => {
|
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.'));
|
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
|
container.on('message', (context: any) => { // tslint:disable-line:no-any
|
||||||
// Check if the only property present in the message is body
|
// Check if the only property present in the message is body
|
||||||
// in which case we only emit the content of the body property
|
// in which case we only emit the content of the body property
|
||||||
|
|
Loading…
Reference in a new issue