npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

streamable-topic

v2.0.0

Published

Consumer and producer abstraction for streaming from a Mongo/Redis event store

Downloads

21

Readme

Streamable Topic

Event streaming concepts implemented on top of an abstracted storage backend.

A topic is a list of ordered (with respect to sharding key) messages containing known payloads. You may push new messages to the end of a topic, and consume messages starting from some position. A consumer will keep track of the last message consumed and will always stream new messages as they arrive for you. Given a set of messages with identical shardingKey, these messages are always guaranteed to be streamed in the order they are produced.

Produce messages with logCompactIds to notify the backend that any previous message with the same id is now redundant and can be removed from the storage engine automatically.

Specify the Payload type when you create the Comsumer Producer instances. Make sure that types are at least backwards compatible with existing data, otherwise you may accidently stream something with unexpected incorrect typings. Use optional keys or a whole new version that the topic supports.

Topic Processors (Deprecated)

A processor is a recoverable process that transforms data from one topic to another. It consumes messages from 1 or many topics and writes to some target topic. By their very nature, you need exactly one processor running for each target topic. Messages can get corrupted very easily if you have two processors running which are both trying to write to the target topic. This is why singleton topic processors are a bad pattern. The soleTopicSetter class is now removed from this repository.

Shared state

A better model is to outsource/delegate the state. The shared state model allows a consumer to build up a stateful model within a state manager rather than having to keep track of built state itself. This makes the processors stateless and hence scalable.

Backend Implementations

Right now, I have exported a MongoRedis backend which uses Mongo collections for message storage and a shared Redis for signalling between consumers. The Mongo collection name is the name of the topic and each document represents a message in that topic. The producer for this backend will publish a redis message on the topic channel to notify when a new message has been added to storage. This is used to wake up any listening consumers that are waiting for new messages on that topic. This is a preferable method over having each consumer poll mongo for new messages every x seconds.

In the future I might add an Apache Kafka backend implementation. Kafka already handles topic storage and streaming new messages out of the box without any need for polling mechanisms or signalling between producer and consumer. In fact, the producer and consumer are purposely kept separated.

MongoRedis Example

npx ts-node ./src/backends/mongoRedis/tests/testConsumer.ts

npx ts-node ./src/backends/mongoRedis/tests/testProducer.ts