Add RabbitMQ Header parameter (#1622)

* Add RabbitMQ Exchange's Header parameter

* code refactoring

* remove log
This commit is contained in:
s 2021-04-04 04:33:22 -04:00 committed by GitHub
parent 0c8afbb3cb
commit 51f066cbcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 1 deletions

View file

@ -36,6 +36,37 @@ export const rabbitDefaultOptions: Array<INodePropertyOptions | INodeProperties
},
],
},
{
displayName: 'Headers',
name: 'headers',
placeholder: 'Add Header',
description: 'Headers to add.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'header',
displayName: 'Header',
values: [
{
displayName: 'Key',
name: 'key',
type: 'string',
default: '',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
},
],
},
],
},
{
displayName: 'Auto Delete',
name: 'autoDelete',

View file

@ -208,6 +208,37 @@ export class RabbitMQ implements INodeType {
},
],
},
{
displayName: 'Headers',
name: 'headers',
placeholder: 'Add Header',
description: 'Headers to add.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'header',
displayName: 'Header',
values: [
{
displayName: 'Key',
name: 'key',
type: 'string',
default: '',
},
{
displayName: 'Value',
name: 'value',
type: 'string',
default: '',
},
],
},
],
},
{
displayName: 'Auto Delete',
name: 'autoDelete',
@ -322,6 +353,15 @@ export class RabbitMQ implements INodeType {
const options = this.getNodeParameter('options', 0, {}) as IDataObject;
let headers : IDataObject = {};
if (options.headers && ((options.headers as IDataObject).header! as IDataObject[]).length) {
const additionalHeaders: IDataObject = {};
((options.headers as IDataObject).header as IDataObject[]).forEach((header: IDataObject) => {
additionalHeaders[header.key as string] = header.value;
});
headers = additionalHeaders;
}
channel = await rabbitmqConnectExchange.call(this, exchange, type, options);
const sendInputData = this.getNodeParameter('sendInputData', 0) as boolean;
@ -336,7 +376,7 @@ export class RabbitMQ implements INodeType {
message = this.getNodeParameter('message', i) as string;
}
exchangePromises.push(channel.publish(exchange, routingKey, Buffer.from(message)));
exchangePromises.push(channel.publish(exchange, routingKey, Buffer.from(message), {headers}));
}
// @ts-ignore