0.5.0 • Published 2 years ago

ripe-bus-api v0.5.0

Weekly downloads
247
License
Apache-2.0
Repository
github
Last release
2 years ago

RIPE Bus API (for Javascript)

The Javascript API for the RIPE event bus.

Should be able to provide an easy-to-use API to be used by microservices of the PERI family.

Initialization

import { API as RipeBusAPI } from "ripe-bus-api-js";

await RipeBusAPI.load();
const bus = new RipeBusAPI();

Usage

Producer

The producer can send one or more events:

bus.trigger("order.created", { id: 1, ... });

bus.trigger("order.created_multiple", [{ id: 1, ... }, { id: 2, ... }]);

The topic defaults to the first part of the name (separated with '.'). The example below defaults to the order topic and the event name is order.created:

bus.trigger("order.created", { id: 1, ... });

The third parameter allows to pass other options to configure event trigger operation. Additional event metadata is added by the API but you can explicitly set it as follows (using options):

bus.trigger("order.created", { id: 1, ... }, {
    topic: "ripe_core.order",
    origin: "ripe-core",
    hostname: "ripe-core.now.platforme.com",
    timestamp: 16007020
});

Consumer

The consumer listens for a topic and executes a callback. The second parameter allows for a callback function or an object containing the callback and other options. The second parameter also allows for callbacks for onSuccess and onError functions if the KafkaRetry consumer is used. It also receives a list of events of interest: any event with a different name is ignored.

bus.bind("order", message => { ... });

bus.bind("order", {
    events: ["order.created", "order.sent", "order.ready"],
    callback: message => { ... }
});

bus.bind("order", {
    events: "order.created",
    callback: message => { ... },
    onSuccess: message => { ... },
    onError: message => { ... },
    retries: 5
});

It is also possible to bind to multiple topics in a single call:

bus.bind(["order", "ripe_twitch:order"], message => { ... });

Configuration

NameTypeDefaultDescription
BUS_ADAPTERstrkafkaThe name of the bus adapter adapter to be used (eg: kafka, kafkaRetry).
KAFKA_HOSTSstrlocalhost:9092The hostname and port of the Kafka nodes to be used, separated by a , (comma).
KAFKA_CLIENT_IDstrripe-kafkaKafka client ID, uniquely identifies a connection to a Kafka broker (more here).
KAFKA_CONSUMER_GROUP_IDstr${RANDOM_STRING}Kafka consumer group ID, identifies a consumer and is unique for a given Kafka broker (more here).
KAFKA_CONSUMER_RETRY_PERSISTENCE_DIRstrdataKafka consumer persistent directory that will store files for message retries.
KAFKA_RETRIESint5Kafka max number of retries to be used in the sending of a message.

For more details and up-to-date information on Kafka specific configs check the Kafka official documentation.

License

RIPE Bus API (for Javascript) is currently licensed under the Apache License, Version 2.0.

Build Automation

Build Status Build Status GitHub npm Status License

0.5.0

2 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

4 years ago