2022-07-04 02:12:08 -07:00
|
|
|
|
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
2022-09-01 05:29:15 -07:00
|
|
|
|
import * as amqplib from 'amqplib';
|
2023-01-27 03:22:44 -08:00
|
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
|
IExecuteFunctions,
|
2022-09-01 05:29:15 -07:00
|
|
|
|
ICredentialsDecrypted,
|
|
|
|
|
ICredentialTestFunctions,
|
2020-12-22 23:05:02 -08:00
|
|
|
|
IDataObject,
|
2022-09-01 05:29:15 -07:00
|
|
|
|
INodeCredentialTestResult,
|
2020-12-22 23:05:02 -08:00
|
|
|
|
INodeExecutionData,
|
|
|
|
|
INodeType,
|
|
|
|
|
INodeTypeDescription,
|
2021-06-12 08:15:23 -07:00
|
|
|
|
JsonObject,
|
2020-12-22 23:05:02 -08:00
|
|
|
|
} from 'n8n-workflow';
|
2023-01-27 03:22:44 -08:00
|
|
|
|
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
|
import { rabbitmqConnectExchange, rabbitmqConnectQueue } from './GenericFunctions';
|
2023-08-09 04:30:53 -07:00
|
|
|
|
import { formatPrivateKey } from '@utils/utilities';
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
|
|
|
|
export class RabbitMQ implements INodeType {
|
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
|
displayName: 'RabbitMQ',
|
|
|
|
|
name: 'rabbitmq',
|
2022-06-20 07:54:01 -07:00
|
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-12-22 23:05:02 -08:00
|
|
|
|
icon: 'file:rabbitmq.png',
|
|
|
|
|
group: ['transform'],
|
2023-05-22 05:37:09 -07:00
|
|
|
|
version: [1, 1.1],
|
2020-12-22 23:05:02 -08:00
|
|
|
|
description: 'Sends messages to a RabbitMQ topic',
|
|
|
|
|
defaults: {
|
|
|
|
|
name: 'RabbitMQ',
|
|
|
|
|
},
|
|
|
|
|
inputs: ['main'],
|
|
|
|
|
outputs: ['main'],
|
|
|
|
|
credentials: [
|
|
|
|
|
{
|
|
|
|
|
name: 'rabbitmq',
|
|
|
|
|
required: true,
|
2022-09-01 05:29:15 -07:00
|
|
|
|
testedBy: 'rabbitmqConnectionTest',
|
2020-12-22 23:05:02 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
properties: [
|
2023-03-02 06:35:13 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Operation',
|
|
|
|
|
name: 'operation',
|
|
|
|
|
type: 'hidden',
|
|
|
|
|
noDataExpression: true,
|
2023-05-22 05:37:09 -07:00
|
|
|
|
default: 'sendMessage',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
|
|
|
|
'@version': [1],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// To remove when action view is fixed
|
2023-03-02 06:35:13 -08:00
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Send a Message to RabbitMQ',
|
2023-05-22 05:37:09 -07:00
|
|
|
|
value: 'sendMessage',
|
|
|
|
|
action: 'Send a Message to RabbitMQ',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Delete From Queue',
|
|
|
|
|
value: 'deleteMessage',
|
|
|
|
|
action: 'Delete From Queue',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Operation',
|
|
|
|
|
name: 'operation',
|
|
|
|
|
type: 'options',
|
|
|
|
|
noDataExpression: true,
|
|
|
|
|
default: 'sendMessage',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
|
|
|
|
'@version': [1.1],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Send a Message to RabbitMQ',
|
|
|
|
|
value: 'sendMessage',
|
|
|
|
|
action: 'Send a Message to RabbitMQ',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Delete From Queue',
|
|
|
|
|
value: 'deleteMessage',
|
|
|
|
|
action: 'Delete From Queue',
|
2023-03-02 06:35:13 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2023-05-22 05:37:09 -07:00
|
|
|
|
{
|
|
|
|
|
displayName:
|
|
|
|
|
'Will delete an item from the queue triggered earlier in the workflow by a RabbitMQ Trigger node',
|
|
|
|
|
name: 'deleteMessage',
|
|
|
|
|
type: 'notice',
|
|
|
|
|
default: '',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
|
|
|
|
operation: ['deleteMessage'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-01-12 23:57:06 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Mode',
|
|
|
|
|
name: 'mode',
|
|
|
|
|
type: 'options',
|
2023-05-22 05:37:09 -07:00
|
|
|
|
displayOptions: {
|
|
|
|
|
hide: {
|
|
|
|
|
operation: ['deleteMessage'],
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-01-12 23:57:06 -08:00
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Queue',
|
|
|
|
|
value: 'queue',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Publish data to queue',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Exchange',
|
|
|
|
|
value: 'exchange',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Publish data to exchange',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
default: 'queue',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'To where data should be moved',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
// Queue
|
|
|
|
|
// ----------------------------------
|
2020-12-22 23:05:02 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Queue / Topic',
|
|
|
|
|
name: 'queue',
|
|
|
|
|
type: 'string',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
mode: ['queue'],
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
2023-05-22 05:37:09 -07:00
|
|
|
|
hide: {
|
|
|
|
|
operation: ['deleteMessage'],
|
|
|
|
|
},
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
2020-12-22 23:05:02 -08:00
|
|
|
|
default: '',
|
|
|
|
|
placeholder: 'queue-name',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Name of the queue to publish to',
|
2020-12-22 23:05:02 -08:00
|
|
|
|
},
|
2021-01-12 23:57:06 -08:00
|
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
// Exchange
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Exchange',
|
|
|
|
|
name: 'exchange',
|
|
|
|
|
type: 'string',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
mode: ['exchange'],
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
|
|
|
|
placeholder: 'exchange-name',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Name of the exchange to publish to',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Type',
|
|
|
|
|
name: 'exchangeType',
|
|
|
|
|
type: 'options',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
mode: ['exchange'],
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Direct',
|
|
|
|
|
value: 'direct',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Direct exchange type',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Topic',
|
|
|
|
|
value: 'topic',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Topic exchange type',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Headers',
|
|
|
|
|
value: 'headers',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Headers exchange type',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Fanout',
|
|
|
|
|
value: 'fanout',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Fanout exchange type',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
default: 'fanout',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Type of exchange',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
|
displayName: 'Routing Key',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
name: 'routingKey',
|
|
|
|
|
type: 'string',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
mode: ['exchange'],
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
|
|
|
|
placeholder: 'routing-key',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The routing key for the message',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
// Default
|
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
2020-12-22 23:05:02 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Send Input Data',
|
|
|
|
|
name: 'sendInputData',
|
|
|
|
|
type: 'boolean',
|
2023-05-22 05:37:09 -07:00
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
|
|
|
|
operation: ['sendMessage'],
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-12-22 23:05:02 -08:00
|
|
|
|
default: true,
|
2024-04-29 01:06:32 -07:00
|
|
|
|
description: 'Whether to send the data the node receives as JSON',
|
2020-12-22 23:05:02 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Message',
|
|
|
|
|
name: 'message',
|
|
|
|
|
type: 'string',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
sendInputData: [false],
|
2020-12-22 23:05:02 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'The message to be sent',
|
2020-12-22 23:05:02 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Options',
|
|
|
|
|
name: 'options',
|
|
|
|
|
type: 'collection',
|
|
|
|
|
default: {},
|
2023-05-22 05:37:09 -07:00
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
|
|
|
|
operation: ['sendMessage'],
|
|
|
|
|
},
|
|
|
|
|
},
|
2020-12-22 23:05:02 -08:00
|
|
|
|
placeholder: 'Add Option',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
options: [
|
2021-04-04 01:33:53 -07:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Alternate Exchange',
|
|
|
|
|
name: 'alternateExchange',
|
|
|
|
|
type: 'string',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
'/mode': ['exchange'],
|
2021-04-04 01:33:53 -07:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: '',
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'An exchange to send messages to if this exchange can’t route them to any queues',
|
2021-04-04 01:33:53 -07:00
|
|
|
|
},
|
2021-01-12 23:57:06 -08:00
|
|
|
|
{
|
|
|
|
|
displayName: 'Arguments',
|
|
|
|
|
name: 'arguments',
|
|
|
|
|
placeholder: 'Add Argument',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Arguments to add',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
type: 'fixedCollection',
|
|
|
|
|
typeOptions: {
|
|
|
|
|
multipleValues: true,
|
|
|
|
|
},
|
|
|
|
|
default: {},
|
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'argument',
|
|
|
|
|
displayName: 'Argument',
|
|
|
|
|
values: [
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Key',
|
|
|
|
|
name: 'key',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Value',
|
|
|
|
|
name: 'value',
|
|
|
|
|
type: 'string',
|
|
|
|
|
default: '',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
2022-05-30 03:16:44 -07:00
|
|
|
|
displayName: 'Auto Delete Queue',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
name: 'autoDelete',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
default: false,
|
2022-08-17 08:50:24 -07:00
|
|
|
|
description:
|
|
|
|
|
'Whether the queue will be deleted when the number of consumers drops to zero',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Durable',
|
|
|
|
|
name: 'durable',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
default: true,
|
2022-06-20 07:54:01 -07:00
|
|
|
|
description: 'Whether the queue will survive broker restarts',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Exclusive',
|
|
|
|
|
name: 'exclusive',
|
|
|
|
|
type: 'boolean',
|
|
|
|
|
displayOptions: {
|
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
|
'/mode': ['queue'],
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
default: false,
|
2022-06-20 07:54:01 -07:00
|
|
|
|
description: 'Whether to scope the queue to the connection',
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
{
|
2021-04-04 01:33:53 -07:00
|
|
|
|
displayName: 'Headers',
|
|
|
|
|
name: 'headers',
|
|
|
|
|
placeholder: 'Add Header',
|
2022-05-06 14:01:25 -07:00
|
|
|
|
description: 'Headers to add',
|
2021-04-04 01:33:53 -07:00
|
|
|
|
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: '',
|
|
|
|
|
},
|
2021-01-12 23:57:06 -08:00
|
|
|
|
],
|
|
|
|
|
},
|
2021-04-04 01:33:53 -07:00
|
|
|
|
],
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
2020-12-22 23:05:02 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-01 05:29:15 -07:00
|
|
|
|
methods = {
|
|
|
|
|
credentialTest: {
|
|
|
|
|
async rabbitmqConnectionTest(
|
|
|
|
|
this: ICredentialTestFunctions,
|
|
|
|
|
credential: ICredentialsDecrypted,
|
|
|
|
|
): Promise<INodeCredentialTestResult> {
|
|
|
|
|
const credentials = credential.data as IDataObject;
|
|
|
|
|
try {
|
|
|
|
|
const credentialKeys = ['hostname', 'port', 'username', 'password', 'vhost'];
|
|
|
|
|
|
|
|
|
|
const credentialData: IDataObject = {};
|
|
|
|
|
credentialKeys.forEach((key) => {
|
|
|
|
|
credentialData[key] = credentials[key] === '' ? undefined : credentials[key];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const optsData: IDataObject = {};
|
|
|
|
|
if (credentials.ssl === true) {
|
|
|
|
|
credentialData.protocol = 'amqps';
|
|
|
|
|
|
|
|
|
|
optsData.ca =
|
2023-08-09 04:30:53 -07:00
|
|
|
|
credentials.ca === ''
|
|
|
|
|
? undefined
|
|
|
|
|
: [Buffer.from(formatPrivateKey(credentials.ca as string))];
|
2022-09-01 05:29:15 -07:00
|
|
|
|
if (credentials.passwordless === true) {
|
|
|
|
|
optsData.cert =
|
2023-08-09 04:30:53 -07:00
|
|
|
|
credentials.cert === ''
|
|
|
|
|
? undefined
|
|
|
|
|
: Buffer.from(formatPrivateKey(credentials.cert as string));
|
2022-09-01 05:29:15 -07:00
|
|
|
|
optsData.key =
|
2023-08-09 04:30:53 -07:00
|
|
|
|
credentials.key === ''
|
|
|
|
|
? undefined
|
|
|
|
|
: Buffer.from(formatPrivateKey(credentials.key as string));
|
2022-09-01 05:29:15 -07:00
|
|
|
|
optsData.passphrase =
|
|
|
|
|
credentials.passphrase === '' ? undefined : credentials.passphrase;
|
|
|
|
|
optsData.credentials = amqplib.credentials.external();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const connection = await amqplib.connect(credentialData, optsData);
|
|
|
|
|
await connection.close();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
status: 'Error',
|
|
|
|
|
message: error.message,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
status: 'OK',
|
|
|
|
|
message: 'Connection successful!',
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-22 23:05:02 -08:00
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
2021-04-04 01:33:53 -07:00
|
|
|
|
let channel, options: IDataObject;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
try {
|
|
|
|
|
const items = this.getInputData();
|
2023-05-22 05:37:09 -07:00
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
|
|
|
|
if (operation === 'deleteMessage') {
|
|
|
|
|
this.sendResponse(items[0].json);
|
2023-09-05 03:59:02 -07:00
|
|
|
|
return [items];
|
2023-05-22 05:37:09 -07:00
|
|
|
|
}
|
|
|
|
|
const mode = (this.getNodeParameter('mode', 0) as string) || 'queue';
|
2021-01-12 23:57:06 -08:00
|
|
|
|
const returnItems: INodeExecutionData[] = [];
|
|
|
|
|
if (mode === 'queue') {
|
|
|
|
|
const queue = this.getNodeParameter('queue', 0) as string;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
|
options = this.getNodeParameter('options', 0, {});
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
channel = await rabbitmqConnectQueue.call(this, queue, options);
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
const sendInputData = this.getNodeParameter('sendInputData', 0) as boolean;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
let message: string;
|
|
|
|
|
const queuePromises = [];
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
if (sendInputData) {
|
2021-01-12 23:57:06 -08:00
|
|
|
|
message = JSON.stringify(items[i].json);
|
|
|
|
|
} else {
|
|
|
|
|
message = this.getNodeParameter('message', i) as string;
|
|
|
|
|
}
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2021-04-04 01:33:53 -07:00
|
|
|
|
let headers: IDataObject = {};
|
2022-08-17 08:50:24 -07:00
|
|
|
|
if (
|
|
|
|
|
options.headers &&
|
|
|
|
|
((options.headers as IDataObject).header! as IDataObject[]).length
|
|
|
|
|
) {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
const itemOptions = this.getNodeParameter('options', i, {});
|
2021-04-04 01:33:53 -07:00
|
|
|
|
const additionalHeaders: IDataObject = {};
|
2022-08-17 08:50:24 -07:00
|
|
|
|
((itemOptions.headers as IDataObject).header as IDataObject[]).forEach(
|
|
|
|
|
(header: IDataObject) => {
|
|
|
|
|
additionalHeaders[header.key as string] = header.value;
|
|
|
|
|
},
|
|
|
|
|
);
|
2021-04-04 01:33:53 -07:00
|
|
|
|
headers = additionalHeaders;
|
|
|
|
|
}
|
|
|
|
|
queuePromises.push(channel.sendToQueue(queue, Buffer.from(message), { headers }));
|
2020-12-22 23:05:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
// @ts-ignore
|
|
|
|
|
const promisesResponses = await Promise.allSettled(queuePromises);
|
|
|
|
|
|
2022-06-20 15:17:18 -07:00
|
|
|
|
// @ts-ignore
|
2021-06-12 08:15:23 -07:00
|
|
|
|
promisesResponses.forEach((response: JsonObject) => {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
if (response.status !== 'fulfilled') {
|
|
|
|
|
if (!this.continueOnFail()) {
|
2021-04-16 09:33:36 -07:00
|
|
|
|
throw new NodeApiError(this.getNode(), response);
|
2021-01-12 23:57:06 -08:00
|
|
|
|
} else {
|
|
|
|
|
// Return the actual reason as error
|
2022-08-17 08:50:24 -07:00
|
|
|
|
returnItems.push({
|
|
|
|
|
json: {
|
|
|
|
|
error: response.reason,
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
|
});
|
2021-01-12 23:57:06 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
returnItems.push({
|
|
|
|
|
json: {
|
|
|
|
|
success: response.value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await channel.close();
|
2021-04-13 09:27:25 -07:00
|
|
|
|
await channel.connection.close();
|
2022-08-17 08:50:24 -07:00
|
|
|
|
} else if (mode === 'exchange') {
|
2021-01-12 23:57:06 -08:00
|
|
|
|
const exchange = this.getNodeParameter('exchange', 0) as string;
|
|
|
|
|
const type = this.getNodeParameter('exchangeType', 0) as string;
|
|
|
|
|
const routingKey = this.getNodeParameter('routingKey', 0) as string;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
|
options = this.getNodeParameter('options', 0, {});
|
2021-04-04 01:33:22 -07:00
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
channel = await rabbitmqConnectExchange.call(this, exchange, type, options);
|
|
|
|
|
|
|
|
|
|
const sendInputData = this.getNodeParameter('sendInputData', 0) as boolean;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
let message: string;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
const exchangePromises = [];
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
if (sendInputData) {
|
2021-01-12 23:57:06 -08:00
|
|
|
|
message = JSON.stringify(items[i].json);
|
2020-12-22 23:05:02 -08:00
|
|
|
|
} else {
|
2021-01-12 23:57:06 -08:00
|
|
|
|
message = this.getNodeParameter('message', i) as string;
|
2020-12-22 23:05:02 -08:00
|
|
|
|
}
|
2021-01-12 23:57:06 -08:00
|
|
|
|
|
2021-04-04 01:33:53 -07:00
|
|
|
|
let headers: IDataObject = {};
|
2022-08-17 08:50:24 -07:00
|
|
|
|
if (
|
|
|
|
|
options.headers &&
|
|
|
|
|
((options.headers as IDataObject).header! as IDataObject[]).length
|
|
|
|
|
) {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
const itemOptions = this.getNodeParameter('options', i, {});
|
2021-04-04 01:33:53 -07:00
|
|
|
|
const additionalHeaders: IDataObject = {};
|
2022-08-17 08:50:24 -07:00
|
|
|
|
((itemOptions.headers as IDataObject).header as IDataObject[]).forEach(
|
|
|
|
|
(header: IDataObject) => {
|
|
|
|
|
additionalHeaders[header.key as string] = header.value;
|
|
|
|
|
},
|
|
|
|
|
);
|
2021-04-04 01:33:53 -07:00
|
|
|
|
headers = additionalHeaders;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
|
exchangePromises.push(
|
|
|
|
|
channel.publish(exchange, routingKey, Buffer.from(message), { headers }),
|
|
|
|
|
);
|
2020-12-22 23:05:02 -08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
// @ts-ignore
|
|
|
|
|
const promisesResponses = await Promise.allSettled(exchangePromises);
|
|
|
|
|
|
2022-06-20 15:17:18 -07:00
|
|
|
|
// @ts-ignore
|
2021-06-12 08:15:23 -07:00
|
|
|
|
promisesResponses.forEach((response: JsonObject) => {
|
2022-12-02 12:54:28 -08:00
|
|
|
|
if (response.status !== 'fulfilled') {
|
|
|
|
|
if (!this.continueOnFail()) {
|
2021-04-16 09:33:36 -07:00
|
|
|
|
throw new NodeApiError(this.getNode(), response);
|
2021-01-12 23:57:06 -08:00
|
|
|
|
} else {
|
|
|
|
|
// Return the actual reason as error
|
2022-08-17 08:50:24 -07:00
|
|
|
|
returnItems.push({
|
|
|
|
|
json: {
|
|
|
|
|
error: response.reason,
|
2021-01-12 23:57:06 -08:00
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
|
});
|
2021-01-12 23:57:06 -08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
returnItems.push({
|
|
|
|
|
json: {
|
|
|
|
|
success: response.value,
|
|
|
|
|
},
|
|
|
|
|
});
|
2020-12-22 23:05:02 -08:00
|
|
|
|
});
|
|
|
|
|
|
2021-01-12 23:57:06 -08:00
|
|
|
|
await channel.close();
|
2021-04-13 09:27:25 -07:00
|
|
|
|
await channel.connection.close();
|
2021-01-12 23:57:06 -08:00
|
|
|
|
} else {
|
2021-04-16 09:33:36 -07:00
|
|
|
|
throw new NodeOperationError(this.getNode(), `The operation "${mode}" is not known!`);
|
2021-01-12 23:57:06 -08:00
|
|
|
|
}
|
2020-12-22 23:05:02 -08:00
|
|
|
|
|
2023-09-05 03:59:02 -07:00
|
|
|
|
return [returnItems];
|
2022-08-17 08:50:24 -07:00
|
|
|
|
} catch (error) {
|
2020-12-22 23:05:02 -08:00
|
|
|
|
if (channel) {
|
|
|
|
|
await channel.close();
|
2021-04-13 09:27:25 -07:00
|
|
|
|
await channel.connection.close();
|
2020-12-22 23:05:02 -08:00
|
|
|
|
}
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|