@autofleet/rabbit 3.3.22-connection-test-beta → 3.4.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/.nvmrc +1 -1
- package/dist/index.d.ts +29 -0
- package/dist/index.js +459 -94
- package/dist/lib/celery.d.ts +9 -0
- package/dist/lib/celery.js +54 -0
- package/dist/lib/types.d.ts +1 -0
- package/package.json +6 -3
- package/src/index.ts +542 -107
- package/src/lib/celery.ts +89 -0
- package/src/lib/types.ts +2 -0
|
@@ -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/dist/lib/types.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface ConsumeOptions {
|
|
|
25
25
|
useConsumeWithLock?: boolean;
|
|
26
26
|
auditContext?: any;
|
|
27
27
|
enableRabbitTrace?: boolean;
|
|
28
|
+
isQuorumQueue?: boolean;
|
|
28
29
|
}
|
|
29
30
|
export type CallbackFunction = (msg: ConsumeMessage, ack: any, nack: any) => Promise<any>;
|
|
30
31
|
export type newChannelOpts = {
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-0",
|
|
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.
|
|
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",
|
|
@@ -43,4 +46,4 @@
|
|
|
43
46
|
},
|
|
44
47
|
"author": "",
|
|
45
48
|
"license": "ISC"
|
|
46
|
-
}
|
|
49
|
+
}
|