Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@nestjs-plugins/nestjs-nats-streaming-transport
Advanced tools
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
Pass the module options to the static forRoot function defined on the NatsStreamingTransport class. These options are use with the Publisher object provision.
static forRoot(
clusterID: string,
clientID: string,
connectOptions: TransportConnectOptions,
): DynamicModule
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { NatsStreamingTransport } from '@transport/nats-streaming-transport';
@Module({
imports: [
NatsStreamingTransport.forRoot(
'my-cluster'/* clusterID */,
'user-service-publisher'/* clientID */,
{
url: 'http://127.0.0.1:4222',
} /* TransportConnectOptions */
),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
// app.service.ts
import { Injectable } from '@nestjs/common';
import { Publisher } from '@transport/nats-streaming-transport';
import { stringify } from 'querystring';
interface VesselCreatedEvent {id: number, name: string }
@Injectable()
export class AppService {
constructor(private publisher: Publisher) {}
getHello(): string {
this.publisher.emit<void,VesselCreatedEvent>('user-created', {id: 1, name: 'Bernt Anker'})
return 'Hello Bernt!';
}
}
The Listener object subcribes to events and the constructor takes 5 parameters.
constructor(
clusterID: string,
clientID: string,
queueGroupName: string,
connectOptions: TransportConnectOptions,
subscriptionOptions: TransportSubscriptionOptions)
// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Listener } from '@nestjs-plugins/nats-streaming-transport';
import { MicroserviceOptions } from '@nestjs/microservices';
async function bootstrap() {
const options = {
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,
} /* TransportSubriptionOptions */ ,
),
};
const microservice = await NestFactory.createMicroservice<
MicroserviceOptions
>(AppModule, options);
await microservice.listen(() => console.log('Microservice is listening'));
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
bootstrap();
// app.controller.ts
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern, Payload, Ctx, MessagePattern } from '@nestjs/microservices';
import { NatsStreamingContext } from 'nestjs-plugins/nats-streaming-transport';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
@EventPattern('user-created)
public async stationCreatedHandler(@Payload() data: {id: number, name:string}, @Ctx() context: NatsStreamingContext) {
console.log(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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
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.