3.3.8 • Published 2 years ago

@epsor/consumer-wrapper v3.3.8

Weekly downloads
382
License
ISC
Repository
github
Last release
2 years ago

CircleCI npm version

@epsor/consumer-wrapper

It wrap the consumer connection to kafka, redis connexion, mongodb connexion to help you to develop new consumer faster.

Requirements

@epsor/consumer-wrapper assumes that a few environment variables are set:

  • EVENT_TOPIC - The event topic to consume
  • MONGODB_URL - The mongoDB server url
  • REDIS_URL - The redis server url
  • KAFKA_HOST - The kafka server info IP:PORT
  • KAFKA_GROUP_ID - The kafka group id

AbstractHandler

This package comes with AbstractHandler which is supposed to be extanded by your consumers handler.

Here an example of a handler:

import { MongoDuplicateEntryError } from '@epsor/mongodb-wrapper';

class UserCreateHandler extends AbstractHandler {
  /** @inheritdoc */
  static get handlerName() {
    return 'UserCreate';
  }

  /** @inheritdoc */
  static get allowedTypes() {
    return ['user.created'];
  }

  /** @inheritdoc */
  static async handle({ mongo }, userCreatedDto) {
    const users = await mongo.collection('users');
    try {
      await users.insertOne(userCreatedDto.fields);
    } catch (err) {
      if (err instanceof MongoDuplicateEntryError) {
        // An error occurred
      }
    }
  }
}

Run a consumer

import { Consumer } from '@epsor/consumer-wrapper';

/** @type {AbstractHandler[]} */
import handlers from './handlers';

(async () => {
  const consumer = new Consumer('b2c', handlers);
  await consumer.initDependencies();
  await consumer.createCollections('users');
  await consumer.run();
})();

Health check

This package contains an express api endpoint to check pod's health.

How to
  • npm start to start the server.
  • go to http://localhost:{HEALTHCHECK_PORT}/.well-known/express/server-health. Default port is 8000

please look at the README.md of epsor-v2 to get the list of supported ports for every consumers.

3.3.8

2 years ago

3.3.7

2 years ago

3.3.6

2 years ago

3.3.5

3 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.2.2

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.1

4 years ago

2.2.18

4 years ago

3.1.0

4 years ago

3.0.2

4 years ago

2.2.17

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.2.16

4 years ago

2.2.15

4 years ago

2.2.14

4 years ago

2.2.13

4 years ago

2.2.12

4 years ago

2.2.11

4 years ago

2.2.10

5 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.2.2-beta

5 years ago

2.2.1-beta

5 years ago

2.2.0-beta

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago