@munlib/common 1.0.47 → 1.0.49
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/build/events/ExpirationCompletedEvent.d.ts +0 -2
- package/build/events/OrderCreatedEvent.d.ts +0 -2
- package/build/events/OrderUpdatedEvent.d.ts +0 -2
- package/build/events/PaymentCreatedEvent.d.ts +0 -2
- package/build/events/base-listener.d.ts +12 -6
- package/build/events/base-listener.js +16 -5
- package/build/events/base-publisher.d.ts +8 -4
- package/build/events/subjects.d.ts +16 -1
- package/build/events/subjects.js +29 -11
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OrderStatus } from "..";
|
|
2
|
-
import { Subjects } from "./subjects";
|
|
3
2
|
interface CartInterface {
|
|
4
3
|
fechaHoraLocal: string;
|
|
5
4
|
fechaCompensacion: string;
|
|
@@ -16,7 +15,6 @@ interface Titulo {
|
|
|
16
15
|
rubro: string;
|
|
17
16
|
}
|
|
18
17
|
export interface OrderCreatedEvent {
|
|
19
|
-
subject: Subjects.OrderCreated;
|
|
20
18
|
data: {
|
|
21
19
|
id: string;
|
|
22
20
|
status: OrderStatus;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { OrderStatus } from "..";
|
|
2
|
-
import { Subjects } from "./subjects";
|
|
3
2
|
interface CartInterface {
|
|
4
3
|
fechaHoraLocal: string;
|
|
5
4
|
fechaCompensacion: string;
|
|
@@ -16,7 +15,6 @@ interface Titulo {
|
|
|
16
15
|
rubro: string;
|
|
17
16
|
}
|
|
18
17
|
export interface OrderUpdatedEvent {
|
|
19
|
-
subject: Subjects.OrderUpdated;
|
|
20
18
|
data: {
|
|
21
19
|
id: string;
|
|
22
20
|
status: OrderStatus;
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { Channel } from "amqplib";
|
|
2
|
-
import {
|
|
2
|
+
import { ExchangeNames, ExchangeTypes, QueueNames, RoutingKeys } from "./subjects";
|
|
3
3
|
interface Event {
|
|
4
|
-
|
|
4
|
+
exchangeName: ExchangeNames;
|
|
5
|
+
exchangeType: ExchangeTypes;
|
|
6
|
+
queueName: QueueNames;
|
|
7
|
+
routingKey: RoutingKeys;
|
|
5
8
|
data: any;
|
|
6
9
|
}
|
|
7
10
|
export declare abstract class Listener<T extends Event> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
protected exchangeName: T["exchangeName"];
|
|
12
|
+
protected exchangeType: T["exchangeType"];
|
|
13
|
+
protected queueName: T["queueName"];
|
|
14
|
+
protected routingKey: T["routingKey"];
|
|
15
|
+
protected channel: Channel;
|
|
16
|
+
abstract onMessage(data: T["data"]): void;
|
|
17
|
+
constructor(channel: Channel, exchangeName: ExchangeNames, exchangeType: ExchangeTypes, queueName: QueueNames, routingKey: RoutingKeys);
|
|
12
18
|
listen(): Promise<void>;
|
|
13
19
|
parseMessage(msg: any): any;
|
|
14
20
|
}
|
|
@@ -38,22 +38,33 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Listener = void 0;
|
|
40
40
|
var Listener = /** @class */ (function () {
|
|
41
|
-
function Listener(channel) {
|
|
41
|
+
function Listener(channel, exchangeName, exchangeType, queueName, routingKey) {
|
|
42
42
|
this.channel = channel;
|
|
43
|
+
this.exchangeName = exchangeName;
|
|
44
|
+
this.exchangeType = exchangeType;
|
|
45
|
+
this.queueName = queueName;
|
|
46
|
+
this.routingKey = routingKey;
|
|
43
47
|
}
|
|
44
48
|
Listener.prototype.listen = function () {
|
|
45
49
|
return __awaiter(this, void 0, void 0, function () {
|
|
46
50
|
var _this = this;
|
|
47
51
|
return __generator(this, function (_a) {
|
|
48
52
|
switch (_a.label) {
|
|
49
|
-
case 0: return [4 /*yield*/, this.channel.
|
|
53
|
+
case 0: return [4 /*yield*/, this.channel.assertExchange(this.exchangeName, this.exchangeType, {
|
|
54
|
+
durable: false,
|
|
55
|
+
})];
|
|
50
56
|
case 1:
|
|
51
57
|
_a.sent();
|
|
52
|
-
this.channel.
|
|
58
|
+
return [4 /*yield*/, this.channel.assertQueue(this.queueName, { durable: false })];
|
|
59
|
+
case 2:
|
|
60
|
+
_a.sent();
|
|
61
|
+
return [4 /*yield*/, this.channel.bindQueue(this.queueName, this.exchangeName, this.routingKey)];
|
|
62
|
+
case 3:
|
|
63
|
+
_a.sent();
|
|
64
|
+
this.channel.consume(this.queueName, function (msg) {
|
|
53
65
|
if (msg) {
|
|
54
66
|
var parsedData = _this.parseMessage(msg);
|
|
55
|
-
_this.onMessage(parsedData
|
|
56
|
-
_this.channel.ack(msg);
|
|
67
|
+
_this.onMessage(parsedData);
|
|
57
68
|
}
|
|
58
69
|
});
|
|
59
70
|
return [2 /*return*/];
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { Channel } from "amqplib
|
|
2
|
-
import {
|
|
1
|
+
import { Channel } from "amqplib";
|
|
2
|
+
import { ExchangeNames, ExchangeTypes, RoutingKeys } from "./subjects";
|
|
3
3
|
interface Event {
|
|
4
|
-
|
|
4
|
+
exchangeName: ExchangeNames;
|
|
5
|
+
exchangeType: ExchangeTypes;
|
|
6
|
+
routingKey: RoutingKeys;
|
|
5
7
|
data: any;
|
|
6
8
|
}
|
|
7
9
|
export declare abstract class Publisher<T extends Event> {
|
|
8
|
-
abstract
|
|
10
|
+
abstract exchangeName: T["exchangeName"];
|
|
11
|
+
abstract exchangeType: T["exchangeType"];
|
|
12
|
+
abstract routingKey: T["routingKey"];
|
|
9
13
|
protected channel: Channel;
|
|
10
14
|
constructor(channel: Channel);
|
|
11
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare enum
|
|
1
|
+
export declare enum RoutingKeys {
|
|
2
2
|
ProductCreated = "product:created",
|
|
3
3
|
ProductUpdated = "product:updated",
|
|
4
4
|
ProductDeleted = "product:deleted",
|
|
@@ -7,3 +7,18 @@ export declare enum Subjects {
|
|
|
7
7
|
ExpirationCompleted = "expiration:completed",
|
|
8
8
|
PaymentCreated = "payment:created"
|
|
9
9
|
}
|
|
10
|
+
export declare enum ExchangeNames {
|
|
11
|
+
exchangeName = "billetera:bus"
|
|
12
|
+
}
|
|
13
|
+
export declare enum ExchangeTypes {
|
|
14
|
+
Direct = "direct",
|
|
15
|
+
Topic = "topic",
|
|
16
|
+
Default = "default",
|
|
17
|
+
Fanout = "fanout"
|
|
18
|
+
}
|
|
19
|
+
export declare enum QueueNames {
|
|
20
|
+
OrderQueue = "order:Queue",
|
|
21
|
+
PaymentQueue = "payment:Queue",
|
|
22
|
+
DeudasQueue = "deudas:Queue",
|
|
23
|
+
ConsultasQueue = "consultas:Queue"
|
|
24
|
+
}
|
package/build/events/subjects.js
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
(function (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})(
|
|
3
|
+
exports.QueueNames = exports.ExchangeTypes = exports.ExchangeNames = exports.RoutingKeys = void 0;
|
|
4
|
+
var RoutingKeys;
|
|
5
|
+
(function (RoutingKeys) {
|
|
6
|
+
RoutingKeys["ProductCreated"] = "product:created";
|
|
7
|
+
RoutingKeys["ProductUpdated"] = "product:updated";
|
|
8
|
+
RoutingKeys["ProductDeleted"] = "product:deleted";
|
|
9
|
+
RoutingKeys["OrderCreated"] = "order:created";
|
|
10
|
+
RoutingKeys["OrderUpdated"] = "order:updated";
|
|
11
|
+
RoutingKeys["ExpirationCompleted"] = "expiration:completed";
|
|
12
|
+
RoutingKeys["PaymentCreated"] = "payment:created";
|
|
13
|
+
})(RoutingKeys || (exports.RoutingKeys = RoutingKeys = {}));
|
|
14
|
+
var ExchangeNames;
|
|
15
|
+
(function (ExchangeNames) {
|
|
16
|
+
ExchangeNames["exchangeName"] = "billetera:bus";
|
|
17
|
+
})(ExchangeNames || (exports.ExchangeNames = ExchangeNames = {}));
|
|
18
|
+
var ExchangeTypes;
|
|
19
|
+
(function (ExchangeTypes) {
|
|
20
|
+
ExchangeTypes["Direct"] = "direct";
|
|
21
|
+
ExchangeTypes["Topic"] = "topic";
|
|
22
|
+
ExchangeTypes["Default"] = "default";
|
|
23
|
+
ExchangeTypes["Fanout"] = "fanout";
|
|
24
|
+
})(ExchangeTypes || (exports.ExchangeTypes = ExchangeTypes = {}));
|
|
25
|
+
var QueueNames;
|
|
26
|
+
(function (QueueNames) {
|
|
27
|
+
QueueNames["OrderQueue"] = "order:Queue";
|
|
28
|
+
QueueNames["PaymentQueue"] = "payment:Queue";
|
|
29
|
+
QueueNames["DeudasQueue"] = "deudas:Queue";
|
|
30
|
+
QueueNames["ConsultasQueue"] = "consultas:Queue";
|
|
31
|
+
})(QueueNames || (exports.QueueNames = QueueNames = {}));
|