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

@cheermix/rabbitmq

v1.2.1

Published

Combined with rxjs, it allows you to write message queues in a more functional way.

Downloads

18

Readme

Usage

Combined with rxjs, it allows you to write message queues in a more functional way

import joi from "joi"
import {
  batchConsume,
  consume,
  filterOnSchema,
  filterAndAck,
  initQueue,
  publish,
} from "@cheermix/rabbitmq"
import { buffer, filter, map } from "rxjs"
import { maxBy, minBy } from "lodash"

// Demo interface
interface BinanceCandlestickChart {
  coinType: string
  timeFrame: number
  date: string
  open: number
  close: number
  high: number
  low: number
}

// Demo data
const data: BinanceCandlestickChart[] = [
  {
    coinType: "BTC/USDT",
    timeFrame: 300000,
    date: "2022-10-01T00:00:00.000+08:00",
    open: 19756.02,
    close: 19665.06,
    high: 19758.66,
    low: 19601.5,
  },
  {
    coinType: "BTC/USDT",
    timeFrame: 300000,
    date: "2022-10-01T00:05:00.000+08:00",
    open: 19666.74,
    close: 19622.14,
    high: 19700,
    low: 19603.76,
  },
  // ...
]

// Initialize the mq configuration,
// push the five-minute candle chart data,
// and then subscribe to obtain them.
initQueue([
  {
    exchange: "crawler",
    queue: "crawler.FiveMinutesBinanceCandlestickChart",
    routePattern: "FiveMinutesBinanceCandlestickChart",
  },
  {
    exchange: "crawler",
    queue: "crawler.FifteenMinutesBinanceCandlestickChart",
    routePattern: "FifteenMinutesBinanceCandlestickChart",
  },
])
  .then(async function () {
    const pushAll = data.map(x => publish("crawler", "FiveMinutesBinanceCandlestickChart", x))
    await Promise.all(pushAll)
  })
  .then(async function () {
    const any$ = consume("crawler.FiveMinutesBinanceCandlestickChart")

    const candlestickChart$ = any$.pipe(
      filterOnSchema<BinanceCandlestickChart>({
        coinType: joi.string().required(),
        timeFrame: joi.number().integer().required(),
        date: joi.string().required(),
        open: joi.number().required(),
        close: joi.number().required(),
        high: joi.number().required(),
        low: joi.number().required(),
      })
    )

    candlestickChart$.subscribe(function (data) {
      data.exchangeName
      data.routingKey
      data.message // This is BinanceCandlestickChart
      data.ack()
    })
  })

// Assuming that the data in the queue is complete and the time sequence is correct,
// let's synthesize a 15-minute BTC candlestick chart.
// Remember to set MQ_PREFETCH larger, at least greater than 3 here.
async function main() {
  const any$ = consume("crawler.FiveMinutesBinanceCandlestickChart")

  const candlestickChart$ = any$.pipe(
    filterOnSchema<BinanceCandlestickChart>({
      coinType: joi.string().required(),
      timeFrame: joi.number().integer().required(),
      date: joi.string().required(),
      open: joi.number().required(),
      close: joi.number().required(),
      high: joi.number().required(),
      low: joi.number().required(),
    })
  )

  const fiveMinCandlestickChart$ = candlestickChart$.pipe(
    filterAndAck(x => x.message.coinType == "BTC/USDT"),
    filterAndAck(x => x.message.timeFrame == 300000)
  )

  const fifteenMinCandlestickChart$ = fiveMinCandlestickChart$.pipe(
    buffer(3),
    map(messages => ({
      message: {
        coinType: messages[0].message.coinType,
        timeFrame: messages[0].message.timeFrame * 3,
        date: messages[0].message.date,
        open: messages[0].message.open,
        close: messages[2].message.close,
        high: maxBy(messages, x => x.message.high),
        low: minBy(messages, x => x.message.low),
      },
      ackAll: () => messages.forEach(m => m.ack()),
    }))
  )

  fifteenMinCandlestickChart$.subscribe(function (data) {
    publish("crawler", "FifteenMinutesBinanceCandlestickChart", data.message)
    data.ackAll()
  })
}

Environment

| Name | Type | Default Value | Is Require? | Description | | ----------- | ------ | ------------- | ----------- | ------------- | | MQ_URL | string | | yes | Connect URL | | MQ_PREFETCH | number | 1 | no | Consume limit |