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

hemera-nats-streaming

v6.2.0

Published

This is a plugin to use NATS-Streaming with Hemera

Downloads

15

Readme

Hemera-nats-streaming package

Build Status npm styled with prettier

This is a plugin to use NATS-Streaming with Hemera. We use the official Node-nats-streaming client. Since nats-streaming based on NATS Server you are able to run both technologies with one NATS-streaming-server.

  1. Download and start nats-streaming-server
  2. Start hemera and use this plugin to initialize a connection to the streaming server
  3. You can now use hemera and nats-streaming with one server!

Install

npm i hemera-nats-streaming --save

Usage

const hemera = new Hemera(nats, {
  logLevel: 'debug'
})
hemera.use(hemeraNatsStreaming, {
  clusterId: 'test-cluster',
  clientId: 'test-client',
  options: {} // NATS/STAN options
})

Subscribe

Create a new NATS-Streaming subscription on the given subject. Under the hood all messages are forwarded to the hemera subscriber with request-reply semantics. If you create a subscription on subject news you will receive all messages on topic natss.news in hemera.

  hemera.natss.add({
    subject: 'news'
    queue: 'news.workers', // (optional) nats-streaming queue group
    options: {}, // (optional) nats-streaming transport options
    pattern: {} // (optional) the pattern which arrive hemera
})

Returns the subscription object of nats-streaming client.

Available options:

  • startWithLastReceived (boolean) Subscribe starting with the most recently published value
  • deliverAllAvailable (boolean) Receive all stored values in order
  • startAtSequence: (integer) Receive all messages starting at a specific sequence number
  • startTime: (Date) Subscribe starting at a specific time
  • startAtTimeDelta (integer)
  • durableName (string) Create a durable subscription
  • maxInFlight (integer) The maximum number of outstanding acknowledgements
  • manualAckMode: (boolean, default: true)
  • ackWait (integer, default: 30000 ms) If an acknowledgement is not received within the configured timeout interval, NATS Streaming will attempt redelivery of the message.

Publish in hemera

Publish a message to NATS-Streaming server.

hemera.act({
  topic: 'natss',
  cmd: 'publish',
  subject: 'news',
  data: { foo: 'bar' }
})

Subscribe in hemera

Create a NATS subscription to listen on NATS-Streaming events.

hemera.add(
  {
    topic: 'natss.news'
  },
  async () => {
    //... throw or resolve to represent the operation state
  }
)

Plugin decorators

  • hemera.natss.add
  • hemera.natss.ParseError

FAQ

Why you don't implement nats-streaming in hemera?

They use the same server but the purpose is quite different with hemera we want to provide a simple toolkit without any delivery guarantee. NATS-streaming was created to fill this gap with a mimimalistic protocol extension. We can use this feature while creating a simple bridge to nats-streaming. It will create a minimal roundtrip overhead but it's tolerable. The greatest fact is that we can run both technologies side by side with one nats-streaming-server.

Why we need NATS-Streaming?

Usually we would use a queue like RabbitMQ to ensure reliable message delivery but maintaining RabbitMQ as well as writing or finding a reliable driver is hard. The authors of NATS-Streaming and NATS know this and that's the reason why they made it as easy as possible.

What's the difference when I use NATS-Streaming directly?

That's good question. In NATS-Streaming there aren't request/reply semantic. If you publish something it doesn't mean that the requestor has received it but it will guarantee that the messages are persistent and replayed in the way you defined it.

Caveats

  • The Hemera proxy subscription can only encode/decode JSON at the moment.
  • Messages from NATS-Streaming are forwarded to a Hemera subscriber. We can only support (request / reply), (queue-group) semantic (no fanout) to ensure message acknowledgement.