Skip to content

Commit

Permalink
refactor!: rebase on [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed Mar 24, 2024
1 parent 582f355 commit 2c5edbd
Show file tree
Hide file tree
Showing 389 changed files with 8,626 additions and 7,372 deletions.
14 changes: 7 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ module.exports = {
env: {
node: true,
jest: true,
es6: true
es6: true,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
ignorePatterns: ['.eslintrc.cjs', 'node_modules/**', 'dist/**'],
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
],
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
env: { 'browser': true, 'es6': true, 'node': true },
env: {
browser: true,
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
Expand All @@ -42,4 +43,3 @@ module.exports = {
},
],
};

2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dist/examples
examples
src/**
tests/**
.eslintrc.cjs
.eslintrc*
.gitignore
.npmignore
.prettierrc
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RedisSMQ is a Node.js library for queuing messages (aka jobs) and processing the

* [High-performance message processing](docs/performance.md).
* Flexible Producer/Consumer model which offers [Multi-Queue Producers](docs/producing-messages.md) & [Multi-Queue Consumers](docs/consuming-messages.md).
* RedisSMQ offers different exchange types: [Direct Exchange](docs/message-exchanges.md#direct-exchange), [Topic Exchange](docs/message-exchanges.md#topic-exchange), and [FanOut Exchange](docs/message-exchanges.md#fanout-exchange) for publishing a message to one or multiple queues.
* RedisSMQ offers different exchange types: [Direct ExchangeAbstract](docs/message-exchanges.md#direct-exchange), [Topic ExchangeAbstract](docs/message-exchanges.md#topic-exchange), and [FanOut ExchangeAbstract](docs/message-exchanges.md#fanout-exchange) for publishing a message to one or multiple queues.
* Supports [Point-2-Point](docs/queue-delivery-models.md#point-2-point-delivery-model) and [Pub/Sub](docs/queue-delivery-models.md#pubsub-delivery-model) [delivery models](docs/queue-delivery-models.md).
* Both [delivery models](docs/queue-delivery-models.md) are reliable. For cases of failure, while delivering/consuming messages, [at-least-once](docs/api/classes/ProducibleMessage.md#setretrythreshold) and [at-most-once](docs/api/classes/ProducibleMessage.md#setretrythreshold) modes may be configured.
* [3 queuing strategies](docs/queues.md): [FIFO queues](docs/queues.md#fifo-first-in-first-out-queues), [LIFO queues](docs/queues.md#lifo-last-in-first-out-queues), and [Priority Queues](docs/queues.md#priority-queues).
Expand Down Expand Up @@ -68,9 +68,14 @@ A queue is responsible for holding messages which are produced by producers and

```javascript
const queue = new Queue();
queue.save('my_queue', EQueueType.LIFO_QUEUE, EQueueDeliveryModel.POINT_TO_POINT, (err) => {
if (err) console.error(err)
});
queue.save(
'my_queue',
EQueueType.LIFO_QUEUE,
EQueueDeliveryModel.POINT_TO_POINT,
(err) => {
if (err) console.error(err);
},
);
```

In the example above we are defining a [LIFO queue](docs/queues.md#lifo-last-in-first-out-queues) with a [POINT-2-POINT delivery model](docs/queue-delivery-models.md#point-2-point-delivery-model).
Expand All @@ -81,10 +86,10 @@ See [Queues](docs/queues.md) for more details.

```javascript
const msg = new ProducibleMessage();
msg.setQueue('my_queue').setBody('Hello Word!')
msg.setQueue('my_queue').setBody('Hello Word!');
producer.produce(msg, (err, ids) => {
if (err) console.error(err);
else console.log(`Produced message IDs are: ${ids.join(', ')}`)
else console.log(`Produced message IDs are: ${ids.join(', ')}`);
});
```

Expand All @@ -97,7 +102,7 @@ const consumer = new Consumer();
const messageHandler = (msg, cb) => {
console.log(msg.body);
cb();
}
};
consumer.consume('my_queue', messageHandler, (err) => {
if (err) console.error(err);
});
Expand Down
5 changes: 2 additions & 3 deletions examples/javascript/using-async-await.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* in the root directory of this source tree.
*/

const { promisifyAll, promisify } = require('bluebird');
const { promisifyAll } = require('bluebird');
const { logger, ERedisConfigClient } = require('redis-smq-common');
const {
Consumer,
Expand All @@ -17,7 +17,6 @@ const {
EQueueType,
EQueueDeliveryMode,
Configuration,
disconnect,
} = require('../..');

const config = {
Expand Down Expand Up @@ -62,7 +61,7 @@ const createQueue = async () => {
EQueueType.LIFO_QUEUE,
EQueueDeliveryMode.POINT_TO_POINT,
);
await promisify(disconnect)();
await queue.shutdownAsync();
}
};

Expand Down
13 changes: 6 additions & 7 deletions examples/javascript/using-async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
* in the root directory of this source tree.
*/

import { logger, ERedisConfigClient } from 'redis-smq-common';
import { ERedisConfigClient, logger } from 'redis-smq-common';
import bluebird from 'bluebird';
import {
Configuration,
Consumer,
EQueueDeliveryMode,
EQueueType,
Producer,
ProducibleMessage,
Queue,
EQueueType,
EQueueDeliveryMode,
Configuration,
disconnect,
} from '../..'; // redis-smq

const { promisify, promisifyAll } = bluebird;
const { promisifyAll } = bluebird;

const config = {
namespace: 'ns1',
Expand Down Expand Up @@ -64,7 +63,7 @@ const createQueue = async () => {
EQueueType.LIFO_QUEUE,
EQueueDeliveryMode.POINT_TO_POINT,
);
await promisify(disconnect)();
await queue.shutdownAsync();
}
};

Expand Down
3 changes: 1 addition & 2 deletions examples/javascript/using-callbacks.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
ProducibleMessage,
Queue,
Configuration,
disconnect,
EQueueType,
EQueueDeliveryMode,
} = require('../..'); // redis-smq
Expand Down Expand Up @@ -61,7 +60,7 @@ const createQueue = (cb) => {
EQueueDeliveryMode.POINT_TO_POINT,
(err) => {
if (err) cb(err);
else disconnect(cb);
else queue.shutdown(cb);
},
);
} else cb();
Expand Down
13 changes: 6 additions & 7 deletions examples/javascript/using-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
* in the root directory of this source tree.
*/

import { logger, ERedisConfigClient } from 'redis-smq-common';
import { ERedisConfigClient, logger } from 'redis-smq-common';
import {
Configuration,
Consumer,
Producer,
EQueueDeliveryMode,
EQueueType,
Message,
Producer,
Queue,
Configuration,
disconnect,
EQueueType,
EQueueDeliveryMode,
} from '../..'; // redis-smq

const config = {
Expand Down Expand Up @@ -61,7 +60,7 @@ const createQueue = (cb) => {
EQueueDeliveryMode.POINT_TO_POINT,
(err) => {
if (err) cb(err);
else disconnect(cb);
else queue.shutdown(cb);
},
);
} else cb();
Expand Down
19 changes: 8 additions & 11 deletions examples/typescript/using-async-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
* in the root directory of this source tree.
*/

import { promisify, promisifyAll } from 'bluebird';
import { promisifyAll } from 'bluebird';
import { ERedisConfigClient, logger } from 'redis-smq-common';
import {
Configuration,
Consumer,
EQueueDeliveryModel,
EQueueType,
IRedisSMQConfig,
Producer,
ProducibleMessage,
Queue,
IRedisSMQConfig,
EQueueType,
ExchangeDirect,
disconnect,
} from '../..'; // redis-smq
import { Configuration } from '../../src/config/configuration';
import { EQueueDeliveryModel } from '../../types';
} from '../../index.js'; // redis-smq

export const config: IRedisSMQConfig = {
namespace: 'ns1',
Expand Down Expand Up @@ -64,15 +62,14 @@ const createQueue = async () => {
EQueueType.LIFO_QUEUE,
EQueueDeliveryModel.POINT_TO_POINT,
);
await promisify(disconnect)();
await queue.shutdownAsync();
}
};

const produce = async () => {
await producer.runAsync();
const msg = new ProducibleMessage();
const e = new ExchangeDirect('test_queue');
msg.setBody({ ts: `Current time is ${Date.now()}` }).setExchange(e);
msg.setBody({ ts: `Current time is ${Date.now()}` }).setQueue('test_queue');
await producer.produceAsync(msg);
};

Expand Down
19 changes: 9 additions & 10 deletions examples/typescript/using-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@

import { ERedisConfigClient, ICallback, logger } from 'redis-smq-common';
import {
Configuration,
Consumer,
EQueueDeliveryModel,
EQueueType,
IRedisSMQConfig,
Producer,
ProducibleMessage,
Queue,
EQueueType,
IRedisSMQConfig,
ExchangeDirect,
disconnect,
} from '../..'; // redis-smq
import { Configuration } from '../../src/config/configuration';
import { EQueueDeliveryModel } from '../../types';
} from '../../index.js'; // redis-smq

export const config: IRedisSMQConfig = {
namespace: 'ns1',
Expand Down Expand Up @@ -63,7 +61,7 @@ const createQueue = (cb: ICallback<void>): void => {
EQueueDeliveryModel.POINT_TO_POINT,
(err) => {
if (err) cb(err);
else disconnect(cb);
else queue.shutdown(cb);
},
);
} else cb();
Expand All @@ -75,9 +73,10 @@ const produce = (cb: ICallback<void>): void => {
producer.run((err) => {
if (err) cb(err);
else {
const e = new ExchangeDirect('test_queue');
const msg = new ProducibleMessage();
msg.setBody({ ts: `Current time is ${Date.now()}` }).setExchange(e);
msg
.setBody({ ts: `Current time is ${Date.now()}` })
.setQueue('test_queue');
producer.produce(msg, (err) => cb(err));
}
});
Expand Down
33 changes: 3 additions & 30 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,6 @@
* in the root directory of this source tree.
*/

import { ICallback } from 'redis-smq-common';
import { _destroyCommonRedisClient } from './src/common/_get-common-redis-client';

export * from './types/index';
export * from './src/lib/consumer/errors';
export * from './src/lib/queue/errors';
export * from './src/lib/exchange/errors';
export * from './src/lib/producer/errors';
export * from './src/lib/message/errors';
export * from './src/lib/consumer/message-handler/errors';
export { Consumer } from './src/lib/consumer/consumer';
export { Producer } from './src/lib/producer/producer';
export { Message } from './src/lib/message/message';
export { ProducibleMessage } from './src/lib/message/producible-message';
export { ExchangeDirect } from './src/lib/exchange/exchange-direct';
export { ExchangeTopic } from './src/lib/exchange/exchange-topic';
export { ExchangeFanOut } from './src/lib/exchange/exchange-fan-out';
export { Namespace } from './src/lib/queue/namespace';
export { Queue } from './src/lib/queue/queue/queue';
export { QueueMessages } from './src/lib/queue/queue-messages/queue-messages';
export { QueueAcknowledgedMessages } from './src/lib/queue/queue-acknowledged-messages';
export { QueueDeadLetteredMessages } from './src/lib/queue/queue-dead-lettered-messages';
export { QueuePendingMessages } from './src/lib/queue/queue-pending-messages/queue-pending-messages';
export { QueueScheduledMessages } from './src/lib/queue/queue-scheduled-messages';
export { QueueRateLimit } from './src/lib/queue/queue-rate-limit/queue-rate-limit';
export { ConsumerGroups } from './src/lib/consumer/consumer-groups/consumer-groups';
export { Configuration } from './src/config/configuration';
export function disconnect(cb: ICallback<void>): void {
_destroyCommonRedisClient(cb);
}
export * from './src/common/index.js';
export * from './src/config/index.js';
export * from './src/lib/index.js';
9 changes: 6 additions & 3 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
* in the root directory of this source tree.
*/

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
const { resolve } = require('path');

module.exports = {
rootDir: resolve('./'),
testMatch: ['**/dist/**/*.test.js'],
setupFilesAfterEnv: ['<rootDir>/dist/tests/jest.setup.js'],
testMatch: ['<rootDir>/dist/cjs/tests/**/*.test.js'],
setupFilesAfterEnv: ['<rootDir>/dist/cjs/tests/setup.js'],
coverageDirectory: '<rootDir>/coverage',
verbose: true,
testTimeout: 160000,
resetMocks: true,
resetModules: true,
};
21 changes: 21 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c)
* Weyoss <[email protected]>
* https://github.com/weyoss
*
* This source code is licensed under the MIT license found in the LICENSE file
* in the root directory of this source tree.
*/

import { resolve } from 'path';

export default {
rootDir: resolve('./'),
testMatch: ['<rootDir>/dist/esm/tests/**/*.test.js'],
setupFilesAfterEnv: ['<rootDir>/dist/esm/tests/setup.js'],
coverageDirectory: '<rootDir>/coverage',
verbose: true,
testTimeout: 160000,
resetMocks: true,
resetModules: true,
};
Loading

0 comments on commit 2c5edbd

Please sign in to comment.