@nestjs-plugins/nestjs-nats-jetstream-transport
Advanced tools
Comparing version 1.0.10 to 1.0.11
import { ClientProxy, ReadPacket, WritePacket } from "@nestjs/microservices"; | ||
import { JetStreamClient } from "nats"; | ||
import { NatsConnection } from "nats"; | ||
import { NatsJetStreamClientOptions } from "./interfaces"; | ||
@@ -7,6 +7,5 @@ export declare class NatsJetStreamClientProxy extends ClientProxy { | ||
private nc; | ||
private js; | ||
private sc; | ||
constructor(options: NatsJetStreamClientOptions); | ||
connect(): Promise<JetStreamClient>; | ||
connect(): Promise<NatsConnection>; | ||
close(): void; | ||
@@ -13,0 +12,0 @@ protected publish(packet: ReadPacket<any>, callback: (packet: WritePacket<any>) => void): () => void; |
@@ -27,5 +27,6 @@ "use strict"; | ||
async connect() { | ||
this.nc = await (0, nats_1.connect)(this.options.connectionOptions); | ||
this.js = this.nc.jetstream(this.options.jetStreamOption); | ||
return this.js; | ||
if (!this.nc) { | ||
this.nc = await (0, nats_1.connect)(this.options.connectionOptions); | ||
} | ||
return this.nc; | ||
} | ||
@@ -36,4 +37,4 @@ close() { | ||
publish(packet, callback) { | ||
this.js | ||
.publish(packet.pattern, this.sc.encode(JSON.stringify(packet.data)), this.options.jetStreamPublishOptions) | ||
const js = this.nc.jetstream(this.options.jetStreamOption); | ||
js.publish(packet.pattern, this.sc.encode(JSON.stringify(packet.data)), this.options.jetStreamPublishOptions) | ||
.then((pubAck) => { | ||
@@ -46,3 +47,4 @@ callback({ response: pubAck }); | ||
async dispatchEvent(packet) { | ||
return this.js.publish(packet.pattern, this.sc.encode(JSON.stringify(packet.data)), this.options.jetStreamPublishOptions); | ||
const js = this.nc.jetstream(this.options.jetStreamOption); | ||
return js.publish(packet.pattern, this.sc.encode(JSON.stringify(packet.data)), this.options.jetStreamPublishOptions); | ||
} | ||
@@ -49,0 +51,0 @@ }; |
import { ModuleMetadata } from "@nestjs/common"; | ||
import { ConnectionOptions, JetStreamOptions, JetStreamPublishOptions } from "nats"; | ||
export declare type NatsJetStreamConnection = Partial<ConnectionOptions> & Pick<ConnectionOptions, "name">; | ||
export interface NatsJetStreamClientOptions { | ||
connectionOptions: NatsJetStreamConnection; | ||
connectionOptions: ConnectionOptions; | ||
jetStreamOption?: JetStreamOptions; | ||
@@ -15,3 +14,3 @@ jetStreamPublishOptions?: JetStreamPublishOptions; | ||
id: string; | ||
connectionOptions: NatsJetStreamConnection; | ||
connectionOptions: ConnectionOptions; | ||
consumerOptions: Partial<ServerConsumerOptions>; | ||
@@ -18,0 +17,0 @@ jetStreamOptions?: JetStreamOptions; |
{ | ||
"name": "@nestjs-plugins/nestjs-nats-jetstream-transport", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"description": "Nats JetStream Transport for NestJS", | ||
@@ -44,3 +44,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "efc90de0e6c0cf3ecc742ceb621c150a5464d8f4" | ||
"gitHead": "8e5778217ecac9b5089785c0081413be407d97af" | ||
} |
@@ -233,5 +233,5 @@ # 🚀 Nats JetStream Transport Module for NestJS | ||
this.client | ||
.send<PubAck, OrderDeleteEvent>(ORDER_DELETED, { id: 1 }) | ||
.emit<PubAck, OrderDeleteEvent>(ORDER_DELETED, { id: 1 }) | ||
.subscribe((pubAck) => { | ||
console.log(pubAck.seq); | ||
console.log(pubAck); | ||
}); | ||
@@ -312,3 +312,3 @@ return 'order deleted'; | ||
import { CustomStrategy } from '@nestjs/microservices'; | ||
import { NatsJetStreamServer } from '@nestjs-plugins/nats-jetstream-transport'; | ||
import { NatsJetStreamServer } from '@nestjs-plugins/nestjs-nats-jetstream-transport'; | ||
@@ -315,0 +315,0 @@ async function bootstrap() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
130858