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

rmq-eddy-current

v1.1.0

Published

A small TS node package for offsetting work to RMQ with the intention of consuming the work by the emitter (or 1 of the emitters in the cluster)

Downloads

137

Readme

Table of Contents generated with DocToc

rmq-eddy-current

A small TS node package for offsetting work to RMQ with the intention of consuming the work by the emitter (or 1 of the emitters in the cluster)

Install and setup

Ensure you install the peer dependencies then follow the example below.

Example

If you have many connections you might want to connect them all in a single static class for ease of access throughout your app. You may also want to inject a function from elsewhere as the consumeCb function. As the emit and parse is from the same service, you now have a typed payload to play with.

// import it
import { Eddy } from 'rmq-eddy-current/build/Eddy';

// set the settings for the connection, verbose here for demo
const baseConfig =  {
  protocol: 'amqp',
  hostname: 'mrrabbit.domain.com',
  port: 5672,
  username: 'guest',
  password: 'guest',
  verboseLogging: false,
  queue: `q.somequeue`,
  dleQueue: 'q.dle_queue',
  dleExchange: 'myapp.dleExchange',
  exchange: 'myapp.serviceNameExchange',
  exchangeType: 'direct'
}

// declare the interface for the data shape to be sent via the q
export interface IsomeQueue{
  id: string,
  campaignId: string
}

// initialise it
export const someQueue = new Eddy<IsomeQueue>({
    ...baseConfig,
    consumeCb: async (obj: IsomeQueue): Promise<ConsumerResponse> => {
      // Example thing to be called
      await BuiltwithRepository.patchRecordAsUsed(obj.id, obj.campaignId)
      
      // and anything else...
      
      // then return
      return { processed: true, requeue: false }
});

// Connect the eddy to your rmq 
await someQueue.connect();

// Publish to it
someQueue.publish({
  id: '321354654lop',
  campaignId: '00thgdfhsfgh'
})

Scenario

  1. You have *n services in 1 cluster, ie they are clones of each other
  2. A job comes in to process 20k records
  3. 1 of the services in your cluster throws each record to the Q, 1 by 1, in seconds
  4. All services in your cluster consume the q (as they are all connected to it)

When to use a rmq-eddy-current

Typically, you would employ dedicated workers for this kind of work. However, there are complexities with workers, firstly they must be co-ordinated and maintained.

When you have highly infrequent workloads (typically backoffice kind of stuff) 10k records to parse here and there, it is far more cost-effective to let the service which enqueues the work to also process the work. Assuming performance of that service is not mission critical. Think of it like an eddy current in a stream, the main body of water for the service is flowing but little eddy's quickly spin up do their work then spin down.

When to not use and eddy

When doing the work would impact the performance of the app to an audience which should not be affected... for example, your customers. Or when the work load is fair consistent, like every 2nd day you need to chunk through a lot of data.

This was not designed for sending data between 2 different services.