@seidor-cloud-produtos/orbit-backend-lib 0.0.30 → 0.0.32
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/clean-arch/application/queue/handler.d.ts +4 -2
- package/dist/clean-arch/application/queue/handler.js +9 -0
- package/dist/clean-arch/{application → infra}/queue/create-consumers.d.ts +1 -1
- package/dist/clean-arch/{application → infra}/queue/queue-controller.d.ts +4 -4
- package/dist/clean-arch/{application → infra}/queue/queue-controller.js +3 -3
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +1 -1
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +1 -1
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.spec.d.ts +1 -0
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.spec.js +35 -0
- package/package.json +1 -1
- /package/dist/clean-arch/{application → infra}/queue/create-consumers.js +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import Handler from '
|
|
2
|
-
import QueueConnection from '
|
|
1
|
+
import Handler from '../../application/queue/handler';
|
|
2
|
+
import QueueConnection from '../../application/queue/queue-connection';
|
|
3
3
|
export interface IEventHandler {
|
|
4
4
|
queueName: string;
|
|
5
5
|
callback: Handler;
|
|
6
6
|
}
|
|
7
7
|
export default abstract class QueueController {
|
|
8
|
-
readonly
|
|
8
|
+
readonly queue: QueueConnection;
|
|
9
9
|
protected abstract eventHandlers: IEventHandler[];
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(queue: QueueConnection);
|
|
11
11
|
runConsumers(): Promise<void>;
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
class QueueController {
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
4
|
+
constructor(queue) {
|
|
5
|
+
this.queue = queue;
|
|
6
6
|
}
|
|
7
7
|
async runConsumers() {
|
|
8
8
|
this.eventHandlers.forEach(eventHandler =>
|
|
9
|
-
this.
|
|
9
|
+
this.queue.on(eventHandler.queueName, eventHandler.callback),
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Handler from '../../../application/queue/handler';
|
|
2
2
|
import QueueConnection from '../../../application/queue/queue-connection';
|
|
3
|
-
import QueueController from '../../../application/queue/queue-controller';
|
|
4
3
|
import DomainEvent from '../../../domain/events/domain-event';
|
|
4
|
+
import QueueController from '../queue-controller';
|
|
5
5
|
export default class AmqpQueue implements QueueConnection {
|
|
6
6
|
private uri;
|
|
7
7
|
private static instance;
|
|
@@ -26,7 +26,7 @@ class AmqpQueue {
|
|
|
26
26
|
async on(queueName, callback) {
|
|
27
27
|
try {
|
|
28
28
|
const channel = await this.connection.createChannel();
|
|
29
|
-
await channel.prefetch(
|
|
29
|
+
await channel.prefetch(callback.getSimultaneity());
|
|
30
30
|
await channel.consume(queueName, async message => {
|
|
31
31
|
try {
|
|
32
32
|
await callback.handle(JSON.parse(message?.content.toString()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
const tslib_1 = require('tslib');
|
|
4
|
+
const amqp_lib_1 = tslib_1.__importDefault(require('./amqp-lib'));
|
|
5
|
+
describe('AmqpQueue', () => {
|
|
6
|
+
it('should not publish if empty memory', async () => {
|
|
7
|
+
const mq = new amqp_lib_1.default();
|
|
8
|
+
mq['messagesInMemory'] = [];
|
|
9
|
+
const mockPublish = (mq['publish'] = vi.fn());
|
|
10
|
+
await mq['publishMessagesOfMemory']();
|
|
11
|
+
expect(mockPublish.mock.calls.length).toBe(0);
|
|
12
|
+
});
|
|
13
|
+
it('should publish if has messages with correct params', async () => {
|
|
14
|
+
const mq = new amqp_lib_1.default();
|
|
15
|
+
mq['messagesInMemory'] = [
|
|
16
|
+
{
|
|
17
|
+
exchangeName: 'exchangeName_1',
|
|
18
|
+
domainEvent: 'domainEvent_1',
|
|
19
|
+
configs: 'my_cfg_1',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
exchangeName: 'exchangeName_2',
|
|
23
|
+
domainEvent: 'domainEvent_2',
|
|
24
|
+
configs: 'my_cfg_2',
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
const mockPublish = (mq['publish'] = vi.fn());
|
|
28
|
+
await mq['publishMessagesOfMemory']();
|
|
29
|
+
console.log(mockPublish.mock.calls);
|
|
30
|
+
expect(mockPublish.mock.calls).toEqual([
|
|
31
|
+
['exchangeName_1', 'domainEvent_1', 'my_cfg_1'],
|
|
32
|
+
['exchangeName_2', 'domainEvent_2', 'my_cfg_2'],
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
});
|
package/package.json
CHANGED
|
File without changes
|