@autofleet/rabbit 3.2.26-beta.3 → 3.3.0-beta.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/src/lib/types.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { AmqpConnectionManager } from 'amqp-connection-manager';
2
1
  import { ConsumeMessage, Options, Replies } from 'amqplib';
3
2
 
4
3
  export interface ExchangesCache {
@@ -13,10 +12,6 @@ export interface QueueSetupPromisesDictionary {
13
12
  [key: string]: Promise<Replies.AssertQueue> | undefined
14
13
  }
15
14
 
16
- export interface AssertExchangePromisesDictionary {
17
- [key: string]: Promise<Replies.AssertExchange> | undefined
18
- }
19
-
20
15
  export type CustomMessageHeaders = {
21
16
  redisTimestampValidationKey?: string;
22
17
  }
@@ -60,10 +55,3 @@ export const CONSUMER_DEFAULT_OPTIONS: Options.Consume = {
60
55
  [HA_PROMOTE_ON_SHUTDOWN]: 'always',
61
56
  },
62
57
  };
63
-
64
- export type ConnectionData = {
65
- connection: AmqpConnectionManager | null;
66
- creatingConnection: boolean;
67
- connectionCreatedEventName: string;
68
- connectionFailedEventName: string;
69
- };
package/src/lib/utils.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  import { ChannelWrapper } from 'amqp-connection-manager';
2
- import { ConfirmChannel, Replies } from 'amqplib';
3
-
4
- export const assertExchangeFanout = async (
5
- c: ChannelWrapper | ConfirmChannel,
6
- exchangeName: string,
7
- ): Promise<Replies.AssertExchange> => c.assertExchange(exchangeName, 'fanout');
2
+ import { ConfirmChannel } from 'amqplib';
8
3
 
4
+ export const assertExchangeFanout = async (c: ChannelWrapper | ConfirmChannel, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
9
5
  export const wrapSetImmediate = (callback: () => any) => new Promise<any>((resolve, reject) => {
10
6
  setImmediate(async () => {
11
7
  try {
@@ -1,9 +0,0 @@
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 };
@@ -1,54 +0,0 @@
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/src/lib/celery.ts DELETED
@@ -1,89 +0,0 @@
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 };