Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
@nestjs-plugins/nestjs-nats-streaming-transport
Advanced tools
Nats Streaming Transport for NestJS
Build Event Driven Microservices Architecture with Nats Streaming Server and NestJS.
Exposes the node-nats-streaming library through @ctx context object.
npm i @nestjs/microservices
npm i @nestjs-plugins/nestjs-nats-streaming-transport
docker run -p 4222:4222 -p 8222:8222 nats-streaming -m 8222 -cid 'my-cluster' -SD
Read more about nats-streaming-server
Read more about node-nats-streaming
A simple Event interface used in this example
// @app/events;
export interface UserCreatedEvent {
id: number,
username: string
}
A simple enum to describe pattern used as subjects.
// '@app/events
export enum Patterns {
UserCreated = 'user:created'
}
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { NatsStreamingTransport } from '@nestjs-plugins/nestjs-nats-streaming-transport'
@Module({
imports: [
NatsStreamingTransport.register(
{
clientId: 'user-service-publisher',
clusterId: 'my-cluster',
connectOptions: {
url: 'http://127.0.0.1:4222',
},
}
),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
// app.service.ts
import { Injectable } from '@nestjs/common';
import { Publisher } from '@nestjs-plugins/nestjs-nats-streaming-transport';
import { UserCreatedEvent, Patterns } from '@app/events'
@Injectable()
export class AppService {
constructor(private publisher: Publisher) { }
getHello(): string {
const event: UserCreatedEvent = { id: Math.floor(Math.random() * Math.floor(1000)), username: 'bernt' }
this.publisher.emit<string, UserCreatedEvent>(Patterns.UserCreated, event).subscribe(guid => {
console.log('published message with guid:', guid)
})
return `published message: ${JSON.stringify(event)}`
}
}
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Listener } from '@nestjs-plugins/nestjs-nats-streaming-transport'
import { CustomStrategy } from '@nestjs/microservices';
async function bootstrap() {
const options: CustomStrategy = {
strategy: new Listener(
'my-cluster' /* clusterID */,
'user-service-listener' /* clientID */,
'user-service-group', /* queueGroupName */
{
url: 'http://127.0.0.1:4222'
} /* TransportConnectOptions */,
{
durableName: 'user-queue-group',
manualAckMode: true,
deliverAllAvailable: true,
} /* TransportSubscriptionOptions */ ,
),
};
// hybrid microservice and web application
const app = await NestFactory.create(AppModule);
const microService = app.connectMicroservice(options)
microService.listen(() => app.listen(3000))
}
bootstrap();
// app.controller.ts
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern, Payload, Ctx } from '@nestjs/microservices';
import { NatsStreamingContext } from '@nestjs-plugins/nestjs-nats-streaming-transport';
import { Patterns } from '@app/events';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) { }
@Get()
getHello(): string {
return this.appService.getHello();
}
@EventPattern(Patterns.UserCreated)
public async stationCreatedHandler(@Payload() data: { id: number, name: string }, @Ctx() context: NatsStreamingContext) {
console.log(`received message: ${JSON.stringify(data)}`)
context.message.ack()
}
}
FAQs
Nats Streaming Transport for NestJS
The npm package @nestjs-plugins/nestjs-nats-streaming-transport receives a total of 925 weekly downloads. As such, @nestjs-plugins/nestjs-nats-streaming-transport popularity was classified as not popular.
We found that @nestjs-plugins/nestjs-nats-streaming-transport demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.