ifmcommon v0.0.88
Description
Nest framework TypeScript starter repository.
Installation
$ npm install ifmcommon
Exception Filters
# usage of nestJs exception filter
import {HttpExceptionFilter ,MongoExceptionFilter } from ifmcommon
# get i18NService from app.module.ts
const i18NService = app.get<I18nService>(I18nService);
# to use as a global exception filter
# first parameter i18NService, second parameter is the kafkaConfig, third parameter is the topic which send to kafka
app.useGlobalFilters(
new MongoExceptionFilter(i18NService, kafkaConf, Topics.FACILITY_EXCEPTIONS),
new HttpExceptionFilter(i18NService, kafkaConf, Topics.FACILITY_EXCEPTIONS),
);
Interceptor
# usage of nestJs common interceptor
import {LoggingInterceptor ,HttpCacheInterceptor, TimeoutInterceptor } from ifmcommon
# to use as a global interceptor
# first parameter is kafkaConfig, second parameter is the topic which send to kafka for log purpose, third parameter is the topic which send to kafka for history purpose
app.useGlobalInterceptors(
new LoggingInterceptor(kafkaConf, Topics.FACILITY_LOGGER, Topics.FACILITY_OPERATION),
new TimeoutInterceptor(),
);
# LoggingInterceptor is used to log the request and response
# HttpCacheInterceptor is used to cache the request and response for getRequest() if u use @NoCache() decorator in controller it skip the cache
# TimeoutInterceptor is used to timeout the request if u use @Timeout() decorator in controller it skip the timeout
Kafka Connection
import {PostKafka,KafkaService } from ifmcommon
# usage of nestJs kafka connection
this.postKafka = new PostKafka(new KafkaService(kafkaConfig));
$kafkaconfig from kafkaJs kafkaConfig options
# producer method in postKafka
async producerSendMessage(topicName: string, message: string, key?: string) {
await this.producer.connect();
await this.producer.send({
topic: topicName,
messages: [
{
key: key || uuidv4(),
value: message,
},
],
});
await this.producer.disconnect();
}
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
3 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago