@nestjs-plugins/nestjs-nats-jetstream-transport
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -12,4 +12,4 @@ import { ClientProxy, ReadPacket, WritePacket } from "@nestjs/microservices"; | ||
serializeError(err: NatsError): NatsError; | ||
protected publish(packet: ReadPacket<any>, callback: (packet: WritePacket<any>) => void): () => void; | ||
protected publish(packet: ReadPacket, callback: (packet: WritePacket) => void): () => void; | ||
protected dispatchEvent(packet: ReadPacket): Promise<any>; | ||
} |
@@ -34,3 +34,4 @@ "use strict"; | ||
await this.nc.drain(); | ||
this.nc.close(); | ||
await this.nc.close(); | ||
this.nc = undefined; | ||
} | ||
@@ -58,6 +59,6 @@ serializeError(err) { | ||
const subject = this.normalizePattern(packet.pattern); | ||
const jetstreamOpts = this.options.jetStreamOption; | ||
const jetstreamPublishOpts = this.options.jetStreamPublishOptions; | ||
const js = this.nc.jetstream(jetstreamOpts); | ||
return js.publish(subject, payload, jetstreamPublishOpts); | ||
const jetStreamOpts = this.options.jetStreamOption; | ||
const jetStreamPublishOpts = this.options.jetStreamPublishOptions; | ||
const js = this.nc.jetstream(jetStreamOpts); | ||
return js.publish(subject, payload, jetStreamPublishOpts); | ||
} | ||
@@ -64,0 +65,0 @@ }; |
@@ -32,3 +32,3 @@ "use strict"; | ||
await this.nc.drain(); | ||
this.nc.close(); | ||
await this.nc.close(); | ||
} | ||
@@ -38,29 +38,35 @@ async bindEventHandlers() { | ||
const js = this.nc.jetstream(this.options.jetStreamOptions); | ||
eventHandlers.forEach(async ([subject, eventHandler]) => { | ||
var e_1, _a; | ||
for (const [subject, eventHandler] of eventHandlers) { | ||
const consumerOptions = (0, server_consumer_options_builder_1.serverConsumerOptionsBuilder)(this.options.consumerOptions, subject); | ||
const subscription = await js.subscribe(subject, consumerOptions); | ||
this.logger.log(`Subscribed to ${subject} events`); | ||
try { | ||
for (var subscription_1 = __asyncValues(subscription), subscription_1_1; subscription_1_1 = await subscription_1.next(), !subscription_1_1.done;) { | ||
const msg = subscription_1_1.value; | ||
const done = (async () => { | ||
var e_1, _a; | ||
try { | ||
for (var subscription_1 = __asyncValues(subscription), subscription_1_1; subscription_1_1 = await subscription_1.next(), !subscription_1_1.done;) { | ||
const msg = subscription_1_1.value; | ||
try { | ||
const data = this.codec.decode(msg.data); | ||
const context = new nats_jetstream_context_1.NatsJetStreamContext([msg]); | ||
this.send((0, rxjs_1.from)(eventHandler(data, context)), () => null); | ||
} | ||
catch (err) { | ||
this.logger.error(err.message, err.stack); | ||
msg.term(); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
const data = this.codec.decode(msg.data); | ||
const context = new nats_jetstream_context_1.NatsJetStreamContext([msg]); | ||
this.send((0, rxjs_1.from)(eventHandler(data, context)), () => null); | ||
if (subscription_1_1 && !subscription_1_1.done && (_a = subscription_1.return)) await _a.call(subscription_1); | ||
} | ||
catch (err) { | ||
this.logger.error(err.message, err.stack); | ||
msg.term(); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (subscription_1_1 && !subscription_1_1.done && (_a = subscription_1.return)) await _a.call(subscription_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}); | ||
})(); | ||
done.then(() => { | ||
subscription.destroy(); | ||
this.logger.log(`Unsubscribed ${subject}`); | ||
}); | ||
} | ||
} | ||
@@ -67,0 +73,0 @@ bindMessageHandlers() { |
{ | ||
"name": "@nestjs-plugins/nestjs-nats-jetstream-transport", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Nats JetStream Transport for NestJS", | ||
@@ -44,3 +44,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "a11cbe493879a0aafc4b18c28275392bcaa602a8" | ||
"gitHead": "82ab51007213ac70fc9a29ac192555ad1eedeea6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
137606
388