Skip to content

Commit

Permalink
docs(api): enhance class documentation with detailed descriptions and…
Browse files Browse the repository at this point in the history
… examples

- Added comprehensive descriptions for Configuration, Consumer, ConsumerGroups, Message, Namespace, and Producer classes
- Included detailed parameter and return type information for methods
- Provided examples for key methods to illustrate usage
- Improved table of contents and hierarchy information for classes
  • Loading branch information
weyoss committed Feb 5, 2025
1 parent 5b4a47c commit 67f8a21
Show file tree
Hide file tree
Showing 21 changed files with 1,360 additions and 238 deletions.
20 changes: 20 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Contributions

If you want to make any project better, your contributions are very welcome!

## Pull requests

It is best to open an issue in GitHub about what you want to implement / change or to suggest new features.

Before submitting any pull request please make sure that your code does not stick out and consistent with the project
coding style. You can check the status of your coding style by simply running `npm run lint`.

Cover your code with new tests if needed. Only fully tested changes are accepted.

Each time when you are ready to submit your changes don't forget to run `npm test` to check that your code is complying
with eslint project rules and that all of the tests are successfully completed.

## Bugs

If you find any bugs, please do not hesitate to open an issue in GitHub including the case to reproduce the bug
when possible.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A High-Performance Redis Simple Message Queue for Node.js
* [Message expiration and consumption timeout](docs/messages.md)
* [Queue rate limiting for controlling message consumption rates](docs/queue-rate-limiting.md)
* [Built-in scheduler for delayed message delivery and repeating messages](docs/scheduling-messages.md)
* [RESTful API](https://github.com/weyoss/redis-smq-rest-api) and web UI for interacting with the message queue
* [RESTful API](docs/redis-smq-rest-api.md) and [Web UI](docs/redis-smq-web-ui.md) for interacting with the message queue
* [Support for ESM and CJS modules](docs/esm-cjs-modules.md)

**Use Cases**
Expand Down Expand Up @@ -67,7 +67,7 @@ For more information, visit the [RedisSMQ Docs](docs/README.md).

**Contributing**

Interested in contributing to this project? Please check out our [CONTRIBUTING.md](https://github.com/weyoss/guidelines/blob/master/CONTRIBUTIONS.md).
Interested in contributing to this project? Please check out our [CONTRIBUTING.md](CONTRIBUTING.md).

**License**

Expand Down
9 changes: 6 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ To help you get up and running with RedisSMQ, we’ve organized essential resour
- **[Message Handler Worker Threads](message-handler-worker-threads.md)**: Learn about worker threads and how they manage message processing.
- **[EventBus](event-bus.md)**: Discover the EventBus feature for event-driven architecture.
- **[Multiplexing](multiplexing.md)**: Understand how to use multiplexing for improved message handling.
- **[Graceful Shutdown](graceful-shutdown.md)**: Learn best practices for safely shutting down your RedisSMQ class instances.
- **[Performance](performance.md)**: Learn about the performance of RedisSMQ.
- **[RedisSMQ Architecture](redis-smq-architecture.md)**: Gain insights into the architectural design of RedisSMQ.
- **[Logs](https://github.com/weyoss/redis-smq-common/blob/master/docs/README.md#logs)**: Learn how to access and utilize logs for monitoring and debugging.
- **[HTTP API](https://github.com/weyoss/redis-smq-monitor)**: Access the HTTP API for integrating RedisSMQ with other applications.
- **[Web UI](https://github.com/weyoss/redis-smq-monitor-client)**: Explore the web interface for easy management of RedisSMQ.
- **[HTTP REST API](redis-smq-rest-api)**: Access the HTTP API for integrating RedisSMQ with other applications.
- **[Web UI](redis-smq-web-ui.md)**: Explore the web interface for easy management of RedisSMQ.
- **[ESM & CJS Modules](esm-cjs-modules.md)**: Find out how to work with ECMAScript Modules and CommonJS modules.

We hope this documentation serves as a valuable resource as you implement and use RedisSMQ in your projects!
We hope this documentation serves as a valuable resource as you implement and use RedisSMQ in your projects!

You can also check out the [FAQs](faqs/README.md) for common questions and issues.
2 changes: 1 addition & 1 deletion docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
- [QueueRateLimit](classes/QueueRateLimit.md)
- [QueueScheduledMessages](classes/QueueScheduledMessages.md)

### Errors
### Error Classes

- [ConfigurationError](classes/ConfigurationError.md)
- [ConfigurationMessageQueueSizeError](classes/ConfigurationMessageQueueSizeError.md)
Expand Down
80 changes: 77 additions & 3 deletions docs/api/classes/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Class: Configuration

Configuration class for managing and setting up the RedisSMQ message queue.
This class is responsible for creating and managing instances of other configuration classes,
such as Namespace, Redis, Logger, Messages, and EventBus.

## Table of contents

### Methods
Expand All @@ -16,32 +20,102 @@

**getConfig**(): [`IRedisSMQConfigRequired`](../interfaces/IRedisSMQConfigRequired.md)

Retrieves the current configuration settings for the RedisSMQ library.

#### Returns

[`IRedisSMQConfigRequired`](../interfaces/IRedisSMQConfigRequired.md)

An object containing the required configuration properties:
- `namespace`: An instance of the Namespace class, representing the namespace for Redis keys.
- `redis`: An instance of the Redis class, managing the Redis connection.
- `logger`: An instance of the Logger class, responsible for logging messages.
- `messages`: An instance of the Messages class, managing message templates.
- `eventBus`: An instance of the EventBus class, handling event subscriptions and notifications.

**`Example`**

```typescript
const myConfig = Configuration.getSetConfig();
console.log(myConfig.namespace); // Output: Namespace instance
console.log(myConfig.redis); // Output: Redis instance
console.log(myConfig.logger); // Output: Logger instance
console.log(myConfig.messages); // Output: Messages instance
console.log(myConfig.eventBus); // Output: EventBus instance
```

___

### getSetConfig

**getSetConfig**(`config?`): [`IRedisSMQConfigRequired`](../interfaces/IRedisSMQConfigRequired.md)

A static method that returns the singleton instance of the Configuration class.
If an instance does not exist, it creates a new one using the provided configuration.

#### Parameters

| Name | Type |
| :------ | :------ |
| `config` | [`IRedisSMQConfig`](../interfaces/IRedisSMQConfig.md) |
| Name | Type | Description |
| :------ | :------ | :------ |
| `config` | [`IRedisSMQConfig`](../interfaces/IRedisSMQConfig.md) | An optional configuration object for the RedisSMQ. If not provided, an empty object is used. |

#### Returns

[`IRedisSMQConfigRequired`](../interfaces/IRedisSMQConfigRequired.md)

The singleton instance of the Configuration class,
containing the required configuration properties.

**`Example`**

```typescript
const config = {
namespace: 'myNamespace',
redis: {
host: 'localhost',
port: 6379,
},
};

const myConfig = Configuration.getSetConfig(config);
console.log(myConfig); // Output: { namespace: 'myNamespace', redis: { host: 'localhost', port: 6379 }, ... }
```

___

### reset

**reset**(): `void`

Resets the singleton instance of the Configuration class.
This method is used to clear the current configuration and allow for a new instance to be created.

#### Returns

`void`

**`Remarks`**

This method is useful when testing or when changing the configuration settings dynamically.
After calling this method, the next time `getSetConfig` is called, a new instance of the Configuration class will be created.

**`Example`**

```typescript
// Create a configuration instance
const config = {
namespace: 'myNamespace',
redis: {
host: 'localhost',
port: 6379,
},
};

const myConfig = Configuration.getSetConfig(config);

// Reset the configuration
Configuration.reset();

// Create a new configuration instance
const newConfig = Configuration.getSetConfig();
```
113 changes: 104 additions & 9 deletions docs/api/classes/Consumer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Class: Consumer

Consumer class responsible for receiving and processing messages from a message queue.
It implements the `Runnable` interface to handle lifecycle events like startup and shutdown.
The Consumer can be configured for multiplexing, allowing it to handle multiple queues simultaneously with a single Redis connection.

## Hierarchy

- `Runnable`\<[`TConsumerEvent`](../README.md#tconsumerevent)\>
Expand Down Expand Up @@ -39,11 +43,13 @@

**new Consumer**(`enableMultiplexing?`): [`Consumer`](Consumer.md)

Creates a new Consumer instance.

#### Parameters

| Name | Type |
| :------ | :------ |
| `enableMultiplexing?` | `boolean` |
| Name | Type | Description |
| :------ | :------ | :------ |
| `enableMultiplexing?` | `boolean` | (Optional) If set to true, the consumer uses a multiplexed message handler runner; otherwise, it uses a standard message handler runner. |

#### Returns

Expand All @@ -59,26 +65,62 @@ Runnable\<TConsumerEvent\>.constructor

**cancel**(`queue`, `cb`): `void`

Cancel consuming messages from the provided queue.
Cancels the consumption of messages from a specified queue.

This function is responsible for stopping the consumption of messages from a specific queue.
It removes the message handler associated with the given queue from the message handler runner.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `queue` | [`TQueueExtendedParams`](../README.md#tqueueextendedparams) | Queue parameters |
| `cb` | `ICallback`\<`void`\> | A callback function |
| `queue` | [`TQueueExtendedParams`](../README.md#tqueueextendedparams) | The queue parameters. This parameter represents the queue from which messages will be consumed. It can be a string representing the queue name or an object containing additional queue options. |
| `cb` | `ICallback`\<`void`\> | Callback function to be called once cancellation is complete. This callback function will be invoked after the message handler associated with the given queue is removed. If an error occurs during the cancellation process, the error will be passed as the first argument to the callback function. Otherwise, the callback function will be invoked with no arguments. |

#### Returns

`void`

**`Example`**

```typescript
const consumer = new Consumer();
consumer.consume(
'my-queue',
(message, done) => {
// Handle the message
// ...
// Acknowledge the message
done();
},
(err) => {
if (err) {
console.error('Error consuming messages:', err);
} else {
console.log('Consumption set up successfully');
}
},
);

// Cancel consumption after some time
setTimeout(() => {
consumer.cancel('my-queue', (err) => {
if (err) {
console.error('Error canceling consumption:', err);
} else {
console.log('Consumption cancelled successfully');
}
});
}, 10000);
```

___

### consume

**consume**(`queue`, `messageHandler`, `cb`): `void`

Start listening for messages on the specified queue.
Consumes messages from a specified queue using the provided message handler.

#### Parameters

Expand All @@ -92,6 +134,28 @@ Start listening for messages on the specified queue.

`void`

**`Example`**

```typescript
const consumer = new Consumer();
consumer.consume(
'my-queue',
(message, done) => {
// Handle the message
// ...
// Acknowledge the message
done();
},
(err) => {
if (err) {
console.error('Error consuming messages:', err);
} else {
console.log('Consumption set up successfully');
}
},
);
```

**`See`**

https://github.com/weyoss/redis-smq/blob/master/docs/consuming-messages.md
Expand Down Expand Up @@ -143,13 +207,44 @@ ___

**getQueues**(): [`IQueueParsedParams`](../interfaces/IQueueParsedParams.md)[]

Retrieve the list of queues being consumed by a Consumer instance.
Retrieves a list of queues the consumer is currently configured to handle.

This function returns an array of parsed queue parameters that the consumer is currently set up to handle.
The parsed queue parameters include the queue name, options, and any additional parameters specified.

#### Returns

[`IQueueParsedParams`](../interfaces/IQueueParsedParams.md)[]

- Queue list
- An array of parsed queue parameters.
Each element in the array represents a queue that the consumer is currently consuming messages from.

**`Example`**

```typescript
const consumer = new Consumer();
consumer.consume(
'my-queue',
(message, done) => {
// Handle the message
// ...
// Acknowledge the message
done();
},
(err) => {
if (err) {
console.error('Error consuming messages:', err);
} else {
console.log('Consumption set up successfully');
}
},
);

// Get the list of queues the consumer is handling
const queues = consumer.getQueues();
console.log('Queues:', queues);
// Output: Queues: [{ queueParams: { name:'my-queue', ns: 'default' }, groupId: null }]
```

___

Expand Down
Loading

0 comments on commit 67f8a21

Please sign in to comment.