@autofleet/rabbit 3.2.22 → 3.2.23-beta.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { EventEmitter } from 'events';
3
3
  import { AmqpConnectionManager, ChannelWrapper, CreateChannelOpts } from 'amqp-connection-manager';
4
4
  import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
5
5
  import { RedisConfig } from './lib/redis';
6
+ import { sendCeleryTaskViaHttp } from './lib/celery';
6
7
  import { CallbackFunction, ConsumeMessageOrNull, ConsumeOptions, CustomMessageHeaders, QueuesCache, RedisLockType, ExchangesCache, QueueSetupPromisesDictionary, AssertExchangePromisesDictionary } from './lib/types';
7
8
  export interface IAfRabbitMq {
8
9
  ack: any;
@@ -99,3 +100,4 @@ declare class RabbitMq implements IAfRabbitMq {
99
100
  gracefulShutdown(signal: string): Promise<void>;
100
101
  }
101
102
  export default RabbitMq;
103
+ export { sendCeleryTaskViaHttp, };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.sendCeleryTaskViaHttp = void 0;
7
8
  const events_1 = require("events");
8
9
  const util_1 = require("util");
9
10
  const moment_1 = __importDefault(require("moment"));
@@ -15,6 +16,8 @@ const logger_1 = __importDefault(require("./logger"));
15
16
  const rabbitError_1 = __importDefault(require("./lib/rabbitError"));
16
17
  const redis_1 = __importDefault(require("./lib/redis"));
17
18
  const utils_1 = require("./lib/utils");
19
+ const celery_1 = require("./lib/celery");
20
+ Object.defineProperty(exports, "sendCeleryTaskViaHttp", { enumerable: true, get: function () { return celery_1.sendCeleryTaskViaHttp; } });
18
21
  const consts_1 = require("./lib/consts");
19
22
  const types_1 = require("./lib/types");
20
23
  // const debug = nodeDebug('af-rabbitmq')
@@ -0,0 +1,9 @@
1
+ interface TaskData {
2
+ [key: string]: any;
3
+ }
4
+ interface SendTaskOptions {
5
+ taskName: string;
6
+ queueName: string;
7
+ }
8
+ declare function sendCeleryTaskViaHttp(data: TaskData, { taskName, queueName }: SendTaskOptions): Promise<void>;
9
+ export { sendCeleryTaskViaHttp, TaskData, SendTaskOptions };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sendCeleryTaskViaHttp = void 0;
7
+ const node_crypto_1 = require("node:crypto");
8
+ const logger_1 = __importDefault(require("../logger"));
9
+ // Environment configuration
10
+ const config = {
11
+ host: process.env.RABBITMQ_SERVICE_HOST || 'localhost',
12
+ username: process.env.RABBITMQ_USERNAME || 'guest',
13
+ password: process.env.RABBITMQ_PASSWORD || 'guest',
14
+ };
15
+ async function sendCeleryTaskViaHttp(data, { taskName, queueName }) {
16
+ const apiUrl = `http://${config.host}:15672/api/exchanges/%2f/amq.default/publish`;
17
+ const message = {
18
+ task: taskName,
19
+ id: (0, node_crypto_1.randomUUID)(),
20
+ args: [data],
21
+ };
22
+ const payload = {
23
+ properties: {
24
+ delivery_mode: 2,
25
+ content_type: 'application/json',
26
+ },
27
+ routing_key: queueName,
28
+ payload: JSON.stringify(message),
29
+ payload_encoding: 'string',
30
+ };
31
+ try {
32
+ const response = await fetch(apiUrl, {
33
+ method: 'POST',
34
+ headers: {
35
+ 'Content-Type': 'application/json',
36
+ Authorization: `Basic ${Buffer.from(`${config.username}:${config.password}`).toString('base64')}`,
37
+ },
38
+ body: JSON.stringify(payload),
39
+ });
40
+ if (response.ok) {
41
+ const result = await response.json();
42
+ logger_1.default.info('Successfully published message:', result);
43
+ }
44
+ else {
45
+ logger_1.default.error(`Failed to publish message. Status code: ${response.status}`);
46
+ logger_1.default.error(`Response: ${await response.text()}`);
47
+ }
48
+ }
49
+ catch (error) {
50
+ logger_1.default.error('Error sending request:', error instanceof Error ? error.message : String(error));
51
+ throw error;
52
+ }
53
+ }
54
+ exports.sendCeleryTaskViaHttp = sendCeleryTaskViaHttp;
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.2.22",
3
+ "version": "3.2.23-beta.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
+ "engines": {
7
+ "node": ">=15.0.0"
8
+ },
6
9
  "scripts": {
7
10
  "postinstall": "echo '\\033[0;31m\nWARNING: in case of migrating to new version of @autofleet/rabbit \nyou might have to delete existing queues or the deployment will fail.\\033[0m\n'",
8
11
  "start": "ts-node src/index.ts",
@@ -43,4 +46,4 @@
43
46
  },
44
47
  "author": "",
45
48
  "license": "ISC"
46
- }
49
+ }
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ import logger from './logger';
18
18
  import RabbitError from './lib/rabbitError';
19
19
  import getRedisInstance, { RedisConfig } from './lib/redis';
20
20
  import { assertExchangeFanout, rand, wrapSetImmediate } from './lib/utils';
21
+ import { sendCeleryTaskViaHttp } from './lib/celery';
21
22
  import {
22
23
  AUTOMATION_ID_HEADER,
23
24
  CONNECTION_CREATED_CONST,
@@ -765,3 +766,7 @@ class RabbitMq implements IAfRabbitMq {
765
766
  }
766
767
 
767
768
  export default RabbitMq;
769
+
770
+ export {
771
+ sendCeleryTaskViaHttp,
772
+ };
@@ -0,0 +1,89 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import logger from '../logger';
3
+ // Environment configuration
4
+ const config = {
5
+ host: process.env.RABBITMQ_SERVICE_HOST || 'localhost',
6
+ username: process.env.RABBITMQ_USERNAME || 'guest',
7
+ password: process.env.RABBITMQ_PASSWORD || 'guest',
8
+ } as const;
9
+
10
+ // Type definitions
11
+ interface TaskData {
12
+ [key: string]: any;
13
+ }
14
+
15
+ interface TaskMessage {
16
+ task: string;
17
+ id: string;
18
+ args: TaskData[];
19
+ }
20
+
21
+ interface PublishPayload {
22
+ properties: {
23
+ // eslint-disable-next-line camelcase
24
+ delivery_mode: number;
25
+ // eslint-disable-next-line camelcase
26
+ content_type: string;
27
+ };
28
+ // eslint-disable-next-line camelcase
29
+ routing_key: string;
30
+ payload: string;
31
+ // eslint-disable-next-line camelcase
32
+ payload_encoding: string;
33
+ }
34
+
35
+ interface PublishResponse {
36
+ routed: boolean;
37
+ }
38
+
39
+ interface SendTaskOptions {
40
+ taskName: string;
41
+ queueName: string;
42
+ }
43
+
44
+ async function sendCeleryTaskViaHttp(
45
+ data: TaskData,
46
+ { taskName, queueName }: SendTaskOptions,
47
+ ): Promise<void> {
48
+ const apiUrl = `http://${config.host}:15672/api/exchanges/%2f/amq.default/publish`;
49
+
50
+ const message: TaskMessage = {
51
+ task: taskName,
52
+ id: randomUUID(),
53
+ args: [data],
54
+ };
55
+
56
+ const payload: PublishPayload = {
57
+ properties: {
58
+ delivery_mode: 2,
59
+ content_type: 'application/json',
60
+ },
61
+ routing_key: queueName,
62
+ payload: JSON.stringify(message),
63
+ payload_encoding: 'string',
64
+ };
65
+
66
+ try {
67
+ const response = await fetch(apiUrl, {
68
+ method: 'POST',
69
+ headers: {
70
+ 'Content-Type': 'application/json',
71
+ Authorization: `Basic ${Buffer.from(`${config.username}:${config.password}`).toString('base64')}`,
72
+ },
73
+ body: JSON.stringify(payload),
74
+ });
75
+
76
+ if (response.ok) {
77
+ const result: PublishResponse = await response.json();
78
+ logger.info('Successfully published message:', result);
79
+ } else {
80
+ logger.error(`Failed to publish message. Status code: ${response.status}`);
81
+ logger.error(`Response: ${await response.text()}`);
82
+ }
83
+ } catch (error) {
84
+ logger.error('Error sending request:', error instanceof Error ? error.message : String(error));
85
+ throw error;
86
+ }
87
+ }
88
+
89
+ export { sendCeleryTaskViaHttp, TaskData, SendTaskOptions };