11import { Inject , Injectable , Logger } from '@nestjs/common' ;
22import { NatsConnection , JSONCodec , headers , Msg , MsgHdrs } from 'nats' ;
33import { Application , Infra } from '@bitloops/bl-boilerplate-core' ;
4- import { ASYNC_LOCAL_STORAGE , ProvidersConstants } from '../jetstream.constants' ;
4+ import { ASYNC_LOCAL_STORAGE , TIMEOUT_MILLIS , ProvidersConstants } from '../jetstream.constants' ;
55import { ContextPropagation } from './utils/context-propagation' ;
66
77const jsonCodec = JSONCodec ( ) ;
@@ -16,6 +16,8 @@ export class NatsPubSubCommandBus implements Infra.CommandBus.IPubSubCommandBus
1616 @Inject ( ProvidersConstants . JETSTREAM_PROVIDER ) private readonly nats : any ,
1717 @Inject ( ASYNC_LOCAL_STORAGE )
1818 private readonly asyncLocalStorage : any ,
19+ @Inject ( TIMEOUT_MILLIS )
20+ private readonly timeoutMillis : number ,
1921 ) {
2022 this . nc = this . nats . getConnection ( ) ;
2123 }
@@ -42,8 +44,8 @@ export class NatsPubSubCommandBus implements Infra.CommandBus.IPubSubCommandBus
4244 async request ( command : Application . Command ) : Promise < any > {
4345 const topic = NatsPubSubCommandBus . getTopicFromCommandInstance ( command ) ;
4446
45- this . logger . log ( 'Requesting in haha :' + topic ) ;
46- console . log ( 'this.asyncLocalStorage.getStore()' , this . asyncLocalStorage . getStore ( ) ) ;
47+ this . logger . log ( 'Requesting in topic :' + topic ) ;
48+ // console.log('this.asyncLocalStorage.getStore()', this.asyncLocalStorage.getStore());
4749 command . correlationId = this . getCorelationId ( ) ;
4850 command . context = this . getContext ( ) ;
4951 // command
@@ -52,7 +54,7 @@ export class NatsPubSubCommandBus implements Infra.CommandBus.IPubSubCommandBus
5254 try {
5355 const response = await this . nc . request ( topic , jsonCodec . encode ( command ) , {
5456 headers,
55- timeout : 10000 ,
57+ timeout : this . timeoutMillis ,
5658 } ) ;
5759 return jsonCodec . decode ( response . data ) ;
5860 } catch ( error : any ) {
0 commit comments