Documentation
Quick Start Guide
Installation
npm install @streamflux/sdkBasic Usage
import { init, connect, stream } from "@streamflux/sdk";
// Initialize the client
init({
url: "ws://localhost:8080/ws",
apiKey: "your-api-key"
});
// Connect to the server
await connect();
// Subscribe to a topic
stream("my-topic")
.on("message", (data) => {
console.log("Received:", data);
});
// Publish to a topic
await stream("my-topic").publish({ hello: "world" });Using Time Windows
Windows allow you to batch events over a time period, which is useful for aggregations and rate limiting.
stream("metrics")
.window(5, "seconds")
.onWindow((batch) => {
console.log(`Received ${batch.count} events`);
// Process all events in the window
const total = batch.events.reduce((sum, e) => sum + e.value, 0);
console.log("Total:", total);
});Filtering Events
stream("orders")
.filter((order) => order.amount > 100)
.on("message", (order) => {
// Only receives orders > $100
console.log("High value order:", order);
});