https://github.com/flow-build/streamers
Interface para Streamers de Eventos
https://github.com/flow-build/streamers
Last synced: 8 months ago
JSON representation
Interface para Streamers de Eventos
- Host: GitHub
- URL: https://github.com/flow-build/streamers
- Owner: flow-build
- Created: 2023-04-03T13:39:14.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-26T15:37:34.000Z (about 3 years ago)
- Last Synced: 2025-05-28T23:47:22.772Z (about 1 year ago)
- Language: TypeScript
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
FlowBuild Streamers
This library provides functionality for writing and consuming events across multiple brokers




## 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:
```bash
npm i @flowbuild/streamers
```
## Configuration:
The required configuration object has a structure similar to:
```json
{
"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:
```typescript
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"},
);
```