Kafka Stream Processing library for Node
A Node.js interpretation of the Kafka Streams Processor API.
Frolyk provides a minimal layer over Kafka, to effectively write, test and run stream processing applications. It follows a task
based concept, where sources
(kafka topics) flow through user-defined processors
to generate results, either back to Kafka or some other store. It aims to enable both stateless and stateful processing, leveraging Kafka ConsumerGroups to spread these tasks between workers.
import createTask from "../src/task";
const task = createTask();
const locationEvents = task.source("location-events");
task.processor(locationEvents, async (assignment) => {
const countsPerTimeWindow = {};
return async (message, context) => {
const location = parseLocation(message.value);
const win = getWindow(location.timestamp);
const existingCount = countsPerTimeWindow[win] || 0;
const newCount = existingCount + 1;
countsPerTimeWindow[win] = newCount;
context.send("location-counts", newCount);
context.commit();
};
});
await task.start();
const testInterface = await task.inject([
{ topic: "location-events", partition: 0 },
]);
const testLocation = {
latitude: 4,
longitude: 10,
timestamp: Date.now(),
};
testInterface.inject({
topic: "location-events",
partition: 0,
key: null,
testLocation,
});
console.log(testInterface.committedMessages);
Initial goals
Later goals