mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Improvements to Amqp Node
This commit is contained in:
parent
6f92ecb128
commit
708b0c8b26
|
@ -41,6 +41,7 @@ export class Amqp implements ICredentialType {
|
||||||
name: 'transportType',
|
name: 'transportType',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'Optional Transport Type to use.',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,11 +62,11 @@ export class Amqp implements INodeType {
|
||||||
name: 'sendOnlyProperty',
|
name: 'sendOnlyProperty',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Send only this property - If empty the hole Json will be sent',
|
description: 'The only property to send. If empty the whole item will be sent.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
||||||
|
@ -105,7 +105,7 @@ export class Amqp implements INodeType {
|
||||||
connectOptions.username = credentials.username;
|
connectOptions.username = credentials.username;
|
||||||
connectOptions.password = credentials.password;
|
connectOptions.password = credentials.password;
|
||||||
}
|
}
|
||||||
if (credentials.transportType) {
|
if (credentials.transportType !== '') {
|
||||||
connectOptions.transport = credentials.transportType;
|
connectOptions.transport = credentials.transportType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,11 +113,10 @@ export class Amqp implements INodeType {
|
||||||
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;
|
const sendOnlyProperty = options.sendOnlyProperty as string;
|
||||||
|
|
||||||
if(prop)
|
if (sendOnlyProperty) {
|
||||||
{
|
body = body[sendOnlyProperty] as string;
|
||||||
body = body[prop] as string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.dataAsObject !== true) {
|
if (options.dataAsObject !== true) {
|
||||||
|
@ -126,7 +125,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);
|
||||||
|
|
|
@ -62,11 +62,11 @@ export class AmqpTrigger implements INodeType {
|
||||||
default: {},
|
default: {},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Only Body',
|
displayName: 'Convert Body To String',
|
||||||
name: 'onlyBody',
|
name: 'jsonConvertByteArrayToString',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Returns only the body property.',
|
description: 'Convert JSON Body content (["body"]["content"]) from Byte Array to string. Needed for Azure Service Bus.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'JSON Parse Body',
|
displayName: 'JSON Parse Body',
|
||||||
|
@ -76,15 +76,15 @@ export class AmqpTrigger implements INodeType {
|
||||||
description: 'Parse the body to an object.',
|
description: 'Parse the body to an object.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Convert JSON Body content from Byte Array to string',
|
displayName: 'Only Body',
|
||||||
name: 'jsonConvertByteArrayToString',
|
name: 'onlyBody',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
default: false,
|
default: false,
|
||||||
description: 'Convert JSON Body content (["body"]["content"]) from Byte Array to string - Azure Service Bus',
|
description: 'Returns only the body property.',
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ export class AmqpTrigger implements INodeType {
|
||||||
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
|
// Old rhea implementation. not shure if it is neccessary
|
||||||
|
@ -139,15 +139,14 @@ export class AmqpTrigger implements INodeType {
|
||||||
if (context.message.message_id && context.message.message_id === lastMsgId) {
|
if (context.message.message_id && context.message.message_id === lastMsgId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("new Message", context.message.message_id, lastMsgId);
|
|
||||||
lastMsgId = context.message.message_id;
|
lastMsgId = context.message.message_id;
|
||||||
|
|
||||||
let data = context.message;
|
let data = context.message;
|
||||||
|
|
||||||
if(options.jsonConvertByteArrayToString === true && data.body.content !== undefined) {
|
if (options.jsonConvertByteArrayToString === true && data.body.content !== undefined) {
|
||||||
// The buffer is not ready... Stringify and parse back to load it.
|
// The buffer is not ready... Stringify and parse back to load it.
|
||||||
let cont = JSON.stringify(data.body.content);
|
const content = JSON.stringify(data.body.content);
|
||||||
data.body = String.fromCharCode.apply(null,JSON.parse(cont).data);
|
data.body = String.fromCharCode.apply(null, JSON.parse(content).data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.jsonParseBody === true) {
|
if (options.jsonParseBody === true) {
|
||||||
|
@ -169,16 +168,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);
|
||||||
|
@ -196,10 +195,10 @@ export class AmqpTrigger implements INodeType {
|
||||||
// for AMQP it doesn't make much sense to wait here but
|
// for AMQP it doesn't make much sense to wait here but
|
||||||
// for a new user who doesn't know how this works, it's better to wait and show a respective info message
|
// for a new user who doesn't know how this works, it's better to wait and show a respective info message
|
||||||
async function manualTriggerFunction() {
|
async function manualTriggerFunction() {
|
||||||
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.'));
|
||||||
}, 3000);
|
}, 30000);
|
||||||
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