Skip to content

Commit

Permalink
(chore): fix rabbitmq connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
belovetech committed Sep 26, 2023
1 parent 8cc198b commit d3b5662
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
54 changes: 29 additions & 25 deletions packages/shared-libs/__tests__/message.queue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import { expect, describe, it, beforeAll, afterAll } from 'vitest';
import { MessageQueue } from '../src';

describe('MessageQueue', () => {
let messageQueue: MessageQueue;
describe(
'MessageQueue',
() => {
let messageQueue: MessageQueue;

beforeAll(() => {
messageQueue = new MessageQueue('amqp://localhost');
});
beforeAll(() => {
messageQueue = new MessageQueue('amqp://localhost');
});

afterAll(() => {
messageQueue.closeConnection();
});
afterAll(() => {
messageQueue.closeConnection();
});

it('should bind exchange with queue', async () => {
await messageQueue.bindExchangeWithQueue('Booking-Ticket', 'Booking');
expect(messageQueue.queue).toBeDefined();
expect(messageQueue.exchange).toBeDefined();
});
it('should bind exchange with queue', async () => {
await messageQueue.bindExchangeWithQueue('Booking-Ticket', 'Booking');
expect(messageQueue.queue).toBeDefined();
expect(messageQueue.exchange).toBeDefined();
});

it('should send and receive message', async () => {
const message = { data: 'hello world' };
await messageQueue.sendMessage(message);
const receivedMessage = await messageQueue.getMessage();
expect(receivedMessage).toEqual(message);
});
it('should send and receive message', async () => {
const message = { data: 'hello world' };
await messageQueue.sendMessage(message);
const receivedMessage = await messageQueue.getMessage();
expect(receivedMessage).toEqual(message);
});

it('should send message with retry', async () => {
const message = { data: 'hello world' };
const result = await messageQueue.sendMessageWithRetry(message, 3);
expect(result).toEqual('DONE');
});
});
it('should send message with retry', async () => {
const message = { data: 'hello world' };
const result = await messageQueue.sendMessageWithRetry(message, 3);
expect(result).toEqual('DONE');
});
},
{ timeout: 20000 }
);
6 changes: 4 additions & 2 deletions packages/shared-libs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
],
"scripts": {
"build": "rm -rf dist && tsc",
"test": "vitest --watch",
"test": "npm run docker-rabbitmq && vitest --watch",
"ui:test": "vitest --ui",
"lint": "npm run prettier:check && npm run eslint",
"lint:fix": "npm run eslint:fix && npm run prettier:fix",
"prettier:cli": "prettier \"**/*.ts\" \"**/*.js\"",
"prettier:check": "npm run prettier:cli -- -l",
"prettier:fix": "npm run prettier:cli -- --write",
"eslint": "eslint --report-unused-disable-directives .",
"eslint:fix": "npm run eslint -- --fix"
"eslint:fix": "npm run eslint -- --fix",
"remove-rabbitmq-container": "docker rm -f rabbitmq",
"docker-rabbitmq": "npm run remove-rabbitmq-container && docker run -it -d --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.12-management"
},
"devDependencies": {
"@types/express": "^4.17.17",
Expand Down

0 comments on commit d3b5662

Please sign in to comment.