问题描述
我已经实现了gRPC,如下所示:
@Client(microserviceOptions)
private client: ClientGrpc;
private grpcService: IGrpcService;
// constructor(private mathService: MathService) {}
onModuleInit() {
this.grpcService = this.client.getService<IGrpcService>('AppController');
}
在nestJS中实现gRPC时,我观察到当我们直接进行简单的过程调用时,它可以完美地工作在文件中。下面的代码片段运行正常。这意味着它将致电服务并成功工作
@Post('upload')
async fileValidator( @Body('data') data: number[] ){
return this.grpcService.accumulate({ data })
}
但是,在调用gRPC服务之前执行了一些其他处理后,不会调用同一gRPC服务。例如,下面的代码不起作用,这意味着未调用gRPC服务。
this.logger.log('Adding ' + data.toString());
let fileName = join(__dirname,'./','sample_17_10_2020_11_5_16.csv')
let stream = createReadStream(fileName)
let lineCount = 0;
let totalRecords = null
const rl = createInterface(stream)
var chunks = [];
var tempChunk = [];
rl.on('line',(line)=>{
let splitted = line.split(',');
if( splitted[0] == ''){
} else if(splitted.length == 5){
//count
lineCount++;
tempChunk.push(line);
}else if(splitted.length == 3){
//this is first line .. ignore
} else if(splitted.length == 1){
//this is last line
totalRecords = splitted[0]
}
if((lineCount != 0 && lineCount % 100 == 0 ) || (totalRecords != null)){
if(tempChunk.length > 0){
chunks.push(tempChunk)
tempChunk = []
}
}
}).on('close',()=>{
return this.grpcService.accumulate({ data });
})
这里可能有什么问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)