1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | const axios_1 = require("axios");
|
10 | const Decorators_1 = require("../ioc/Decorators");
|
11 | class RabbitmqMgtHttpApi {
|
12 | |
13 |
|
14 |
|
15 | async ping() {
|
16 | try {
|
17 | const url = 'healthchecks/node';
|
18 | const res = await this.sendRequest('get', url);
|
19 | if (res.status !== 200) {
|
20 | throw new Error(`${url} returns status: (${res.status}, ${res.statusText})`);
|
21 | }
|
22 | const result = Object.assign({}, res.data);
|
23 | return Promise.resolve(result);
|
24 | }
|
25 | catch (err) {
|
26 | throw err;
|
27 | }
|
28 | }
|
29 | sendRequest(method, url, params) {
|
30 | return axios_1.default.request({
|
31 | method,
|
32 | baseURL: `${this.rabbitmqConfig.mgtHttpTheme}://${this.rabbitmqConfig.mgtHttpHost}:${this.rabbitmqConfig.mgtHttpPort}/api/`,
|
33 | url,
|
34 | params,
|
35 | headers: { 'content-type': 'application/json' },
|
36 | auth: {
|
37 | username: this.rabbitmqConfig.username,
|
38 | password: this.rabbitmqConfig.password,
|
39 | },
|
40 | });
|
41 | }
|
42 | }
|
43 | __decorate([
|
44 | Decorators_1.AutowireConfig('rabbitmq.client')
|
45 | ], RabbitmqMgtHttpApi.prototype, "rabbitmqConfig", void 0);
|
46 | exports.RabbitmqMgtHttpApi = RabbitmqMgtHttpApi;
|
47 |
|
\ | No newline at end of file |