@autofleet/rabbit 3.2.21-beta.0.2 → 3.2.21-beta.0.4
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 +2 -1
- package/dist/index.js +3 -8
- package/dist/lib/celery.d.ts +5 -0
- package/dist/lib/celery.js +54 -0
- package/package.json +1 -2
- package/src/index.ts +4 -5
- package/src/lib/celery.ts +85 -0
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { AmqpConnectionManager, ChannelWrapper, CreateChannelOpts } from 'amqp-c
|
|
|
4
4
|
import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
|
|
5
5
|
import { RedisConfig } from './lib/redis';
|
|
6
6
|
import { CallbackFunction, ConsumeMessageOrNull, ConsumeOptions, CustomMessageHeaders, QueuesCache, RedisLockType, ExchangesCache, QueueSetupPromisesDictionary, AssertExchangePromisesDictionary } from './lib/types';
|
|
7
|
+
import { sendCeleryTaskViaHttp } from './lib/celery';
|
|
7
8
|
export interface IAfRabbitMq {
|
|
8
9
|
ack: any;
|
|
9
10
|
nack: any;
|
|
@@ -98,4 +99,4 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
98
99
|
gracefulShutdown(signal: string): Promise<void>;
|
|
99
100
|
}
|
|
100
101
|
export default RabbitMq;
|
|
101
|
-
export
|
|
102
|
+
export { sendCeleryTaskViaHttp, };
|
package/dist/index.js
CHANGED
|
@@ -4,11 +4,10 @@ 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.
|
|
7
|
+
exports.sendCeleryTaskViaHttp = void 0;
|
|
8
8
|
const events_1 = require("events");
|
|
9
9
|
const util_1 = require("util");
|
|
10
10
|
const moment_1 = __importDefault(require("moment"));
|
|
11
|
-
const celery_node_1 = __importDefault(require("celery-node"));
|
|
12
11
|
const redis_lock_1 = __importDefault(require("redis-lock"));
|
|
13
12
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
14
13
|
const zehut_1 = require("@autofleet/zehut");
|
|
@@ -19,6 +18,8 @@ const redis_1 = __importDefault(require("./lib/redis"));
|
|
|
19
18
|
const utils_1 = require("./lib/utils");
|
|
20
19
|
const consts_1 = require("./lib/consts");
|
|
21
20
|
const types_1 = require("./lib/types");
|
|
21
|
+
const celery_1 = require("./lib/celery");
|
|
22
|
+
Object.defineProperty(exports, "sendCeleryTaskViaHttp", { enumerable: true, get: function () { return celery_1.sendCeleryTaskViaHttp; } });
|
|
22
23
|
// const debug = nodeDebug('af-rabbitmq')
|
|
23
24
|
const debug = logger_1.default.debug.bind(logger_1.default);
|
|
24
25
|
const PUBLISH_TIMEOUT = 1000 * 10;
|
|
@@ -545,9 +546,3 @@ class RabbitMq {
|
|
|
545
546
|
}
|
|
546
547
|
}
|
|
547
548
|
exports.default = RabbitMq;
|
|
548
|
-
const sendToCelelryQueue = async (queueName, taskName, payload) => {
|
|
549
|
-
const host = process.env.RABBITMQ_SERVICE_HOST || 'localhost';
|
|
550
|
-
const client = celery_node_1.default.createClient(host, undefined, queueName);
|
|
551
|
-
return client.sendTask(taskName, [payload], undefined, (0, node_crypto_1.randomUUID)());
|
|
552
|
-
};
|
|
553
|
-
exports.sendToCelelryQueue = sendToCelelryQueue;
|
|
@@ -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) {
|
|
16
|
+
const apiUrl = `http://${config.host}:15672/api/exchanges/%2f/amq.default/publish`;
|
|
17
|
+
const message = {
|
|
18
|
+
task: 'planning_tasks.process_planning_task',
|
|
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: 'planning-task',
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.2.21-beta.0.
|
|
3
|
+
"version": "3.2.21-beta.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"amqp-connection-manager": "4.1.9",
|
|
20
20
|
"amqplib": "0.10.3",
|
|
21
21
|
"bluebird": "^3.7.2",
|
|
22
|
-
"celery-node": "^0.5.9",
|
|
23
22
|
"moment": "^2.29.1",
|
|
24
23
|
"redis": "^3.1.2",
|
|
25
24
|
"redis-lock": "^0.1.4"
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { EventEmitter, once } from 'events';
|
|
4
4
|
import { promisify } from 'util';
|
|
5
5
|
import moment from 'moment';
|
|
6
|
-
import celery from 'celery-node';
|
|
7
6
|
import RedisLock from 'redis-lock';
|
|
8
7
|
import {
|
|
9
8
|
AmqpConnectionManager, ChannelWrapper, connect, CreateChannelOpts,
|
|
@@ -42,6 +41,8 @@ import {
|
|
|
42
41
|
AssertExchangePromisesDictionary,
|
|
43
42
|
} from './lib/types';
|
|
44
43
|
|
|
44
|
+
import { sendCeleryTaskViaHttp } from './lib/celery';
|
|
45
|
+
|
|
45
46
|
// const debug = nodeDebug('af-rabbitmq')
|
|
46
47
|
const debug = logger.debug.bind(logger);
|
|
47
48
|
|
|
@@ -737,8 +738,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
737
738
|
|
|
738
739
|
export default RabbitMq;
|
|
739
740
|
|
|
740
|
-
export
|
|
741
|
-
|
|
742
|
-
const client = celery.createClient(host, undefined, queueName);
|
|
743
|
-
return client.sendTask(taskName, [payload], undefined, randomUUID());
|
|
741
|
+
export {
|
|
742
|
+
sendCeleryTaskViaHttp,
|
|
744
743
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
// Environment configuration
|
|
4
|
+
const config = {
|
|
5
|
+
host: process.env.RABBITMQ_SERVICE_HOST || '10.132.15.204',
|
|
6
|
+
username: process.env.RABBITMQ_USERNAME || 'default_user_Zjlb8cnBF-jwc61bbC8',
|
|
7
|
+
password: process.env.RABBITMQ_PASSWORD || 'SDjnZWKAgz9TROLDV85OUZb6FOLlfw1b',
|
|
8
|
+
};
|
|
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
|
+
delivery_mode: number;
|
|
24
|
+
content_type: string;
|
|
25
|
+
};
|
|
26
|
+
routing_key: string;
|
|
27
|
+
payload: string;
|
|
28
|
+
payload_encoding: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface PublishResponse {
|
|
32
|
+
routed: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface SendTaskOptions {
|
|
36
|
+
taskName: string;
|
|
37
|
+
queueName: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function sendTaskViaHttp(
|
|
41
|
+
data: TaskData,
|
|
42
|
+
{ taskName, queueName }: SendTaskOptions,
|
|
43
|
+
): Promise<void> {
|
|
44
|
+
const apiUrl = `http://${config.host}:15672/api/exchanges/%2f/amq.default/publish`;
|
|
45
|
+
|
|
46
|
+
const message: TaskMessage = {
|
|
47
|
+
task: taskName,
|
|
48
|
+
id: randomUUID(),
|
|
49
|
+
args: [data],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const payload: PublishPayload = {
|
|
53
|
+
properties: {
|
|
54
|
+
delivery_mode: 2,
|
|
55
|
+
content_type: 'application/json',
|
|
56
|
+
},
|
|
57
|
+
routing_key: queueName,
|
|
58
|
+
payload: JSON.stringify(message),
|
|
59
|
+
payload_encoding: 'string',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch(apiUrl, {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
Authorization: `Basic ${Buffer.from(`${config.username}:${config.password}`).toString('base64')}`,
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(payload),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (response.ok) {
|
|
73
|
+
const result: PublishResponse = await response.json();
|
|
74
|
+
console.log('Successfully published message:', result);
|
|
75
|
+
} else {
|
|
76
|
+
console.error(`Failed to publish message. Status code: ${response.status}`);
|
|
77
|
+
console.error(`Response: ${await response.text()}`);
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error('Error sending request:', error instanceof Error ? error.message : String(error));
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { sendTaskViaHttp, TaskData, SendTaskOptions };
|