Skip to content

Commit

Permalink
docs: use typed events, remove legacy events
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed Nov 26, 2023
1 parent 5d85cb0 commit 7c899f8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 79 deletions.
23 changes: 23 additions & 0 deletions docs/api/type-aliases/TRedisSMQEvent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
> [RedisSMQ](../../../README.md) / [Docs](../../README.md) / [API Reference](../README.md) / TRedisSMQEvent
# Type alias: TRedisSMQEvent

> **TRedisSMQEvent**: [`TEvent`](https://github.com/weyoss/redis-smq-common/blob/master/docs/api/README.md#tevent) & \{
>
> `heartbeatTick`: (`timestamp`: `number`, `consumerId`: `string`, `heartbeatPayload`: [`IConsumerHeartbeat`](../interfaces/IConsumerHeartbeat.md)) => `void` ;
>
> `messageAcknowledged`: (`messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md), `messageHandlerId`: `string`, `consumerId`: `string`) => `void` ;
>
> `messageDeadLettered`: (`cause`: [`EConsumeMessageDeadLetterCause`](../enumerations/EConsumeMessageDeadLetterCause.md), `messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md), `messageHandlerId`: `string`, `consumerId`: `string`) => `void` ;
>
> `messageDelayed`: (`messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md), `messageHandlerId`: `string`, `consumerId`: `string`) => `void` ;
>
> `messagePublished`: (`messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md)) => `void` ;
>
> `messageReceived`: (`messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md), `consumerId`: `string`) => `void` ;
>
> `messageRequeued`: (`messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md), `messageHandlerId`: `string`, `consumerId`: `string`) => `void` ;
>
> `messageUnacknowledged`: (`cause`: [`EConsumeMessageUnacknowledgedCause`](../enumerations/EConsumeMessageUnacknowledgedCause.md), `messageId`: `string`, `queue`: [`IQueueParams`](../interfaces/IQueueParams.md), `messageHandlerId`: `string`, `consumerId`: `string`) => `void`
>
> }
56 changes: 0 additions & 56 deletions docs/api/variables/events.md

This file was deleted.

32 changes: 12 additions & 20 deletions docs/event-listeners.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
>[RedisSMQ](../README.md) / [Docs](README.md) / Event listeners
> [RedisSMQ](../README.md) / [Docs](README.md) / IEvent listeners
# Event listeners
# IEvent listeners

Event listeners can be a way to automate processing every event from each consumer or producer instance.
IEvent listeners can be a way to automate processing every event from each consumer or producer instance.

Let's suppose that for some reason you want to catch all `events.MESSAGE_ACKNOWLEDGED` events from all created
Let's suppose that for some reason you want to catch all `events.MESSAGE_ACKNOWLEDGED` events from all created
consumer instances in your application.

There are many ways to take in order to achieve your goal. The most repetitive and error prone way is to manually
There are many ways to take in order to achieve your goal. The most repetitive and error prone way is to manually
register an event listener after creating each consumer instance like this way:

```javascript
const consumer = new Consumer();
consumer.on(events.MESSAGE_ACKNOWLEDGED, (msg) => {
consumer.on('messageAcknowledged', (msg) => {
//...
})
```

A more convenient way to do the same thing but with less manual work, is to configure RedisSMQ to initialize and
A more convenient way to do the same thing but with less manual work, is to configure RedisSMQ to initialize and
manage event listeners for you.

## Consumer Event Listeners
## Consumer IEvent Listeners

Let's create a consumer event listener class which we will use to demonstrate how to work with consumer event listeners.

```typescript
import { IEventListener, IEventProvider, TEventListenerInitArgs } from 'redis-smq';
import { events } from 'redis-smq';
import { ICallback } from "redis-smq-common";

export class ConsumerEventListener implements IEventListener {
Expand Down Expand Up @@ -79,16 +78,9 @@ const config: IConfig = {
Configuration.getSetConfig(config);
```

### Consumer Message Events:
## Producer IEvent Listeners

* events.MESSAGE_RECEIVED
* events.MESSAGE_ACKNOWLEDGED
* events.MESSAGE_UNACKNOWLEDGED
* events.MESSAGE_DEAD_LETTERED

## Producer Event Listeners

The producer event listener class also implements the `IEventListener` interface:
The producer event listener class also implements the `IEventListener` interface:

Example:

Expand Down Expand Up @@ -120,6 +112,6 @@ const config: IConfig = {
Configuration.getSetConfig(config);
```

### Producer Message Events:
## Message Events

* events.MESSAGE_PUBLISHED
See [TRedisSMQEvent](./api/type-aliases/TRedisSMQEvent.md).
5 changes: 2 additions & 3 deletions misc/health-check/combined-run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Queue,
disconnect,
EQueueType,
events,
} from '../../index';

const queueName = `queue_${Date.now()}`;
Expand All @@ -39,11 +38,11 @@ consumer.consume(
(err) => err && console.log(err),
);

consumer.on(events.UP, () => {
consumer.on('up', () => {
console.log('UP');
});

consumer.on(events.DOWN, () => {
consumer.on('down', () => {
console.log('DOWN');
});

Expand Down

0 comments on commit 7c899f8

Please sign in to comment.