@autofleet/rabbit 3.3.0-beta.0 → 3.3.0-beta.10

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.
@@ -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;
@@ -3,6 +3,7 @@ export declare const DEFAULT_LOCK_TIMEOUT: number;
3
3
  export declare const RETRY_HEADER = "x-retry-count";
4
4
  export declare const TRACING_HEADER = "x-trace-id";
5
5
  export declare const USER_TRACING_HEADER = "x-af-user-id";
6
+ export declare const AUTOMATION_ID_HEADER = "x-af-automation-id";
6
7
  export declare const USER_OBJECT = "userObject";
7
8
  export declare const DEFAULT_USE_CONSUME_WITH_LOCK = false;
8
9
  export declare const CONNECTION_CREATED_CONST = "connectionCreated";
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_OPTIONS = exports.CONNECTION_FAILED_CONST = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.USER_OBJECT = exports.USER_TRACING_HEADER = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
3
+ exports.DEFAULT_OPTIONS = exports.CONNECTION_FAILED_CONST = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.USER_OBJECT = exports.AUTOMATION_ID_HEADER = exports.USER_TRACING_HEADER = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
4
4
  exports.DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 12;
5
5
  exports.DEFAULT_LOCK_TIMEOUT = 1000 * 5;
6
6
  exports.RETRY_HEADER = 'x-retry-count';
7
7
  exports.TRACING_HEADER = 'x-trace-id';
8
8
  exports.USER_TRACING_HEADER = 'x-af-user-id';
9
+ exports.AUTOMATION_ID_HEADER = 'x-af-automation-id';
9
10
  exports.USER_OBJECT = 'userObject';
10
11
  exports.DEFAULT_USE_CONSUME_WITH_LOCK = false;
11
12
  exports.CONNECTION_CREATED_CONST = 'connectionCreated';
@@ -8,6 +8,9 @@ export interface QueuesCache {
8
8
  export interface QueueSetupPromisesDictionary {
9
9
  [key: string]: Promise<Replies.AssertQueue> | undefined;
10
10
  }
11
+ export interface AssertExchangePromisesDictionary {
12
+ [key: string]: Promise<Replies.AssertExchange> | undefined;
13
+ }
11
14
  export type CustomMessageHeaders = {
12
15
  redisTimestampValidationKey?: string;
13
16
  };
@@ -22,6 +25,7 @@ export interface ConsumeOptions {
22
25
  useConsumeWithLock?: boolean;
23
26
  auditContext?: any;
24
27
  enableRabbitTrace?: boolean;
28
+ isQuorumQueue?: boolean;
25
29
  }
26
30
  export type CallbackFunction = (msg: ConsumeMessage, ack: any, nack: any) => Promise<any>;
27
31
  export type newChannelOpts = {
@@ -1,5 +1,5 @@
1
1
  import { ChannelWrapper } from 'amqp-connection-manager';
2
- import { ConfirmChannel } from 'amqplib';
3
- export declare const assertExchangeFanout: (c: ChannelWrapper | ConfirmChannel, exchangeName: string) => Promise<import("amqplib").Replies.AssertExchange>;
2
+ import { ConfirmChannel, Replies } from 'amqplib';
3
+ export declare const assertExchangeFanout: (c: ChannelWrapper | ConfirmChannel, exchangeName: string) => Promise<Replies.AssertExchange>;
4
4
  export declare const wrapSetImmediate: (callback: () => any) => Promise<any>;
5
5
  export declare const rand: () => number;
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.3.0-beta.0",
3
+ "version": "3.3.0-beta.10",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
+ "engines": {
7
+ "node": ">=16.7.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",
@@ -15,7 +18,7 @@
15
18
  "dev": "nodemon"
16
19
  },
17
20
  "dependencies": {
18
- "@autofleet/zehut": "3.0.8",
21
+ "@autofleet/zehut": "^3.1.2",
19
22
  "amqp-connection-manager": "4.1.9",
20
23
  "amqplib": "0.10.3",
21
24
  "bluebird": "^3.7.2",