Flux.map处理多次,怎么办

时间:2018-10-23 10:52:49

标签: flux gateway

记录器有时打印内容已满,有时是阶段,我希望内容接受完毕后再打印日志,该怎么办

ServerHttpResponse response = exchange.getResponse();
        DataBufferFactory bufferFactory = response.bufferFactory();
        ServerHttpResponseDecorator decoratedResponse = new ServerHttpResponseDecorator(response) {
            @Override
            public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
                {
                    if (body instanceof Flux) {
                        Flux<? extends DataBuffer> fluxBody = (Flux<? extends DataBuffer>) body;
                        return super.writeWith(fluxBody.map(dataBuffer -> {
                            byte[] content = new byte[dataBuffer.readableByteCount()];
                            dataBuffer.read(content);

                            DataBufferUtils.release(dataBuffer);

                            logger.info("[content={}]", new String(content, Charsets.UTF_8));



                            }
                            return bufferFactory.wrap(content);
                        }));
                    }
                    return super.writeWith(body);
                }
            }

0 个答案:

没有答案