我有下面的代码,我想跟踪httpRequest花费了多少时间并记录下来。
在顺序代码中,我们通常标记开始、执行和标记结束,最后
(结束时间-开始时间)
.
它应该能够打印成功或失败所花费的时间。
io.reactivex.Flowable
.fromIterable(records.records())
.parallel(5)
.flatMap(record -> {
Single<HttpResponse<String>> request = client
.get(xxxxxx, "xxx.xxx.xxx.xxx" , "/xxxxxxx")
.as(BodyCodec.string())
.rxSend();
return request.toFlowable();
}
)
.sequential()
.subscribe(record -> {
System.out.println(record.body());
}, ex -> {
ex.printStackTrace();
});
我设法做到了这样。但不包括例外情况,这是正确的方向吗?
io.reactivex.Flowable
.fromIterable(records.records())
.parallel(5)
.flatMap(record -> {
Single<HttpResponse<String>> request = client
.get(xxxxxx, "xxx.xxx.xxx.xxx" , "xxxxxx")
.as(BodyCodec.string())
.rxSend();
MyWrapper wrapper = new MyWrapper(System.currentTimeMillis(), request);
return Flowable.just(wrapper);
}
)
.sequential()
.subscribe(record -> {
long startTime = record.getStartTime();
record.getHttpResponse().toFlowable().subscribe(t -> {
long endTime = System.currentTimeMillis();
System.out.println("Took: " + (endTime - startTime) + " - " + t.body());
});
}, ex -> {
ex.printStackTrace();
});
谢谢