Nettle Pie Market

    ripe-bus-api
    TypeScript icon, indicating that this package has built-in type declarations

    0.5.0 • Public • Published

    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

    Name Type Default Description
    BUS_ADAPTER str kafka The name of the bus adapter adapter to be used (eg: kafka, kafkaRetry).
    KAFKA_HOSTS str localhost:9092 The hostname and port of the Kafka nodes to be used, separated by a , (comma).
    KAFKA_CLIENT_ID str ripe-kafka Kafka client ID, uniquely identifies a connection to a Kafka broker (more here).
    KAFKA_CONSUMER_GROUP_ID str ${RANDOM_STRING} Kafka consumer group ID, identifies a consumer and is unique for a given Kafka broker (more here).
    KAFKA_CONSUMER_RETRY_PERSISTENCE_DIR str data Kafka consumer persistent directory that will store files for message retries.
    KAFKA_RETRIES int 5 Kafka 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

    Install

    npm i ripe-bus-api

    DownloadsWeekly Downloads

    3

    Version

    0.5.0

    License

    Apache-2.0

    Unpacked Size

    3.17 MB

    Total Files

    33

    Last publish

    Collaborators

    • platforme