[英]nestJs httpService.get request in @Interval has no reaction
I have a service with HttpService injected and start request with @Interval(20000).我有一个注入了 HttpService 的服务,并使用 @Interval(20000) 启动请求。 In interval function I do a request to another server with this.http.get(...) but I see no reaction, wether a request nor an exception.
在间隔函数中,我使用 this.http.get(...) 向另一台服务器发出请求,但我没有看到任何反应,无论是请求还是异常。 I see only console log "handleInterval"!
我只看到控制台日志“handleInterval”! What is wrong?
怎么了?
:
import {HttpException, HttpService, Injectable} from '@nestjs/common'
@Injectable()
export class AppService {
constructor(private readonly http: HttpService) {}
@Interval(20000)
handleInterval() {
console.log('handleInterval');
let response = this.http.get('192.168.0.162:8081/diag.fhtml', {responseType: 'arraybuffer'}).pipe(
map(res => {
console.log('received data');
return res.data;
}),
catchError(e => {
console.error(e);
throw new HttpException(e.response.data, e.response.status);
}));
}
:
:
}
Nest's HttpService
makes use of RxJS
Observables. Nest 的
HttpService
使用了RxJS
Observables。 To trigger the request, you need to add .subscribe()
or make the function async
and add .toPromise()
.要触发请求,您需要添加
.subscribe()
或使函数async
并添加.toPromise()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.