0.0.12 • Published 12 months ago

@flowbuild/streamers v0.0.12

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

Coverage lines Coverage branches Coverage functions Coverage statements

Dependencies:

It is necessary to have a Message Broker running in order to use the Stream Interface. The available Brokers are:

kafka
bullmq
mqtt
rabbitmq

Install:

npm i @flowbuild/streamers

Configuration:

The required configuration object has a structure similar to:

{
    "topics":{
        "event-topic":{
            "producesTo":["bullmq", "kafka", "mqtt", "rabbitmq"],
            "consumesFrom":["bullmq", "kafka", "mqtt", "rabbitmq"],
        },
    },
    "kafka": {
        "CLIENT_ID": "my-kafka-id",
        "BROKER_HOST": "localhost",
        "BROKER_PORT": "9092",
        "GROUP_CONSUMER_ID": "my-consumer-group",
    },
    "bullmq": {
        "REDIS_HOST": "localhost",
        "REDIS_PORT": "6379",
        "REDIS_PASSWORD": "",
        "REDIS_DB": 4,
    },
    "mqtt": {
        "MQTT_HOST": "localhost",
        "MQTT_PORT": "1883",
        "MQTT_PROTOCOL": "http",
        "MQTT_USERNAME": "username",
        "MQTT_PASSWORD": "password",
    },
    "rabbitmq": {
        "RABBITMQ_HOST": "localhost:5672",
        "RABBITMQ_USERNAME": "user",
        "RABBITMQ_PASSWORD": "password",
        "RABBITMQ_QUEUE": "flowbuild"
    }
}

In topics you must put the name of the events and a relation of Consumption and Production listing the brokers that will be used.

For each broker you want to use, you must put the necessary configuration in the respective configuration key

Example:

const stream = new StreamInterface({
    "topics":{
        "event-topic":{
            "producesTo":["bullmq", "kafka", "mqtt", "rabbitmq"],
            "consumesFrom":["bullmq", "kafka", "mqtt", "rabbitmq"],
        },
    },
    "kafka": {
        "CLIENT_ID": "my-kafka-id",
        "BROKER_HOST": "localhost",
        "BROKER_PORT": "9092",
        "GROUP_CONSUMER_ID": "my-consumer-group",
    },
    "bullmq": {
        "REDIS_HOST": "localhost",
        "REDIS_PORT": "6379",
        "REDIS_PASSWORD": "",
        "REDIS_DB": 4,
    },
    "mqtt": {
        "MQTT_HOST": "localhost",
        "MQTT_PORT": "1883",
        "MQTT_PROTOCOL": "http",
        "MQTT_USERNAME": "username",
        "MQTT_PASSWORD": "password",
    },
    "rabbitmq": {
        "RABBITMQ_HOST": "localhost:5672",
        "RABBITMQ_USERNAME": "user",
        "RABBITMQ_PASSWORD": "password",
        "RABBITMQ_QUEUE": "flowbuild"
    }
});

const consumerCallback = (topic: string, receivedMessage: string) => {
    console.log({topic, receivedMessage});
};

await stream.connect(consumerCallback);
await stream.produce(
    "event-topic", 
    {"mensagem": "This is an test"},
);

await stream.produce(
    "event-topic", 
    {"mensagem": "This is another test"},
);
0.0.12

12 months ago

0.0.11

12 months ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago