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

@de-novo/nestjs-redis-streams

v0.0.5

Published

Redis Streams Transport for NestJS.

Downloads

16

Readme

@de-novo/nestjs-redis-streams

NPM Version NPM Downloads GitHub Issues or Pull Requests

Installation

with npm

npm i @de-novo/nestjs-redis-streams

with yarn

yarn add @de-novo/nestjs-redis-streams

with pnpm

pnpm i @de-novo/nestjs-redis-streams

Why

This open-source project was inspired by the discussions within the NestJS community, specifically Issue Add more transport strategies (microservices) #3960. The issue highlighted the need for expanding the microservices strategies in NestJS, including an interest in various data stream processing methods, with a particular focus on Redis streams. Redis streams are essential for efficiently supporting real-time data processing and messaging requirements in distributed systems.

The primary goal of this project is to facilitate the easy use of Redis streams within NestJS applications. By doing so, we aim to assist developers in implementing real-time data stream processing features more conveniently, thereby enhancing the performance and scalability of applications built on NestJS.

Run Example

git clone https://github.com/de-novo/nestjs-redis-stream.git
npm i && npm run build
# redis on
# Docker must be installed.
npm run redis:docker
# client
npm run example:client
# microservice(server)
npm run example:microservice
curl localhost:3000/test/send # use curl
# if you use postman GET: localhost:3000/test/send

Start

Use Server Side (like Kafka Consumer)

//  src/main.js
import { RedisStreamServer } from '@de-novo/nestjs-reids-stream';
import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions } from '@nestjs/microservices';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const redis = await NestFactory.createMicroservice<MicroserviceOptions>(
    AppModule,
    {
      strategy: new RedisStreamServer({
        connection: {
          path: 'redis://localhost:6379',
        },
        streams: {
          consumer: 'test-1',
          consumerGroup: 'test-group',
          //   deleteMessagesAfterAck: true // not recommend
        },
      }),
    },
  );
  redis.listen();
  await app.listen(3000);
}
bootstrap();
import { Controller } from '@nestjs/common';
import { Ctx, MessagePattern, Payload } from '@nestjs/microservices';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @MessagePattern('message')
  sendTest(@Payload() data: any, @Ctx() ctx: any): boolean {
    console.log('data', data, ctx);
    return false;
  }
}

Use Client Side (like Kafka Producer)

// app.module
import { RedisStreamClientModule } from '@de-novo/nestjs-reids-stream';
import { Module } from '@nestjs/common';

import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  imports: [
    RedisStreamClientModule.forRoot({
      connection: {
        path: 'redis://localhost:6379',
      },
      streams: {
        consumer: 'test-1',
        block: 5000,
        consumerGroup: 'test-group',
      },
      responsePattern: ['test.send'],
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
import { RedisStreamClient } from '@de-novo/nestjs-reids-stream';
import { Injectable } from '@nestjs/common';
import { lastValueFrom } from 'rxjs';
@Injectable()
export class AppService {
  constructor(private readonly redisStreamClient: RedisStreamClient) {}

  async sendTest() {
    const res = await lastValueFrom(
      this.redisStreamClient.send('test.send', {
        value: { value_test: 'test' }, // @Payload payload => {value_test:'test'}
        headers: { header_test: 'test' }, // @Ctx ctx => {headers:{header_test:"test"}}
      }),
    );
    return res;
  }

  emitTest() {
    this.redisStreamClient.emit('test.emit', { test: 'test' });
    return 'Emit Test';
  }
}