3.3.8 • Published 3 years ago

@epsor/consumer-wrapper v3.3.8

Weekly downloads
382
License
ISC
Repository
github
Last release
3 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

3 years ago

3.3.7

3 years ago

3.3.6

4 years ago

3.3.5

5 years ago

3.3.4

5 years ago

3.3.3

5 years ago

3.3.2

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.1

5 years ago

2.2.18

5 years ago

3.1.0

5 years ago

3.0.2

5 years ago

2.2.17

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.16

5 years ago

2.2.15

6 years ago

2.2.14

6 years ago

2.2.13

6 years ago

2.2.12

6 years ago

2.2.11

6 years ago

2.2.10

6 years ago

2.2.9

6 years ago

2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.2.2-beta

6 years ago

2.2.1-beta

6 years ago

2.2.0-beta

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago