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

eventstore-stream-subscriber

v1.0.38

Published

Eventhandler for an eventstore stream

Downloads

15

Readme

eventstore-stream-subscriber

Subscribe to an Eventstore stream with the possibility to add separate event handlers for specific event types.

Subscribe to realtime events only

var subscriber = require("eventstore-stream-subscriber")();

// register eventhandlers for eventtypes of a stream
subscriber.registerHandler("myEventType", (subscription, evt) => {
    let e = evt.originalEvent.data.toString();
    console.log("Event received");
    console.log(e);
});

// configure the subscriber
subscriber.configure({
    resolveLinkTos : false,
    logHeartbeats : false
});

// connect and start consuming events
subscriber.createConnection({}).then(() =>
    subscriber.subscribeToStream("myStream")
        .catch((reason) => console.log(reason))
)
.catch((reason) => console.log(reason));

Catch up from beginning of stream and continue to consume realtime events

subscriber.createConnection({}).then(() =>
    subscriber.catchupAndSubscribeToStream("myStream")
        .catch((reason) => console.log(reason))
)
.catch((reason) => console.log(reason));

Read the entire stream from start to end

        // register a global handler (will receive all)
        subscriber.registerGlobalHandler((subscription, evt, eventType) => {
            console.log(`${eventType} event arrived!`);
            console.log(JSON.stringify(evt));
        });

        subscriber.configure({ resolveLinkTos: true });

        const streamName = "Order-123";
        await subscriber.readWholeStreamFromStart(streamName, {}, "c3")
            .then((rs) => console.log("ok"))
            .catch(reason => console.log("reason: " + reason));
            
    });

Configuration

The default configuration:

var configuration = {
    resolveLinkTos : true,
    logHeartbeats : false,
    userName : "admin",
    password : "changeit",
    eventstoreHost : "127.0.0.1",
    eventstorePort : 1113
}

Override these settings in createConnection:


subscriber.createConnection({eventstoreHost : "eventstore.local", eventstorePort : 2113}).then(() =>
    subscriber.catchupAndSubscribeToStream("myStream")
        .catch((reason) => console.log(reason))
)
.catch((reason) => console.log(reason));

Or using .env (make sure to pass these vars to your application)

# eventstore.production.env
EVENTSTORE_STREAM_SUB_HOST=eventstoreprod.somewhere.com
EVENTSTORE_STREAM_SUB_PORT=3113

Since .env overrides the configuration object, both of these will have the same effect when .env variables are present:

//With local config
subscriber.createConnection({eventstoreHost : "eventstore.local", eventstorePort : 2113}).then(() =>
    subscriber.catchupAndSubscribeToStream("myStream")
        .catch((reason) => console.log(reason))
)
.catch((reason) => console.log(reason));

/*
    Resolves to tcp://eventstoreprod.somewhere.com:3113
*/

//without local config
subscriber.createConnection({}).then(() =>
    subscriber.catchupAndSubscribeToStream("myStream")
        .catch((reason) => console.log(reason))
)
.catch((reason) => console.log(reason));

/*
    Resolves to tcp://eventstoreprod.somewhere.com:3113
*/

Logging

The following loglevels can be set in the environment variable EVENTSTORE_STREAM_SUB_LOGLEVEL:

info warning error fatal