1
1
import { Inject , Injectable , Logger } from '@nestjs/common' ;
2
2
import { NatsConnection , JSONCodec , headers , Msg , MsgHdrs } from 'nats' ;
3
3
import { 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' ;
5
5
import { ContextPropagation } from './utils/context-propagation' ;
6
6
7
7
const jsonCodec = JSONCodec ( ) ;
@@ -16,6 +16,8 @@ export class NatsPubSubCommandBus implements Infra.CommandBus.IPubSubCommandBus
16
16
@Inject ( ProvidersConstants . JETSTREAM_PROVIDER ) private readonly nats : any ,
17
17
@Inject ( ASYNC_LOCAL_STORAGE )
18
18
private readonly asyncLocalStorage : any ,
19
+ @Inject ( TIMEOUT_MILLIS )
20
+ private readonly timeoutMillis : number ,
19
21
) {
20
22
this . nc = this . nats . getConnection ( ) ;
21
23
}
@@ -42,8 +44,8 @@ export class NatsPubSubCommandBus implements Infra.CommandBus.IPubSubCommandBus
42
44
async request ( command : Application . Command ) : Promise < any > {
43
45
const topic = NatsPubSubCommandBus . getTopicFromCommandInstance ( command ) ;
44
46
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());
47
49
command . correlationId = this . getCorelationId ( ) ;
48
50
command . context = this . getContext ( ) ;
49
51
// command
@@ -52,7 +54,7 @@ export class NatsPubSubCommandBus implements Infra.CommandBus.IPubSubCommandBus
52
54
try {
53
55
const response = await this . nc . request ( topic , jsonCodec . encode ( command ) , {
54
56
headers,
55
- timeout : 10000 ,
57
+ timeout : this . timeoutMillis ,
56
58
} ) ;
57
59
return jsonCodec . decode ( response . data ) ;
58
60
} catch ( error : any ) {
0 commit comments