rabbitmq消息丢失

发送消息后,队列中没有显示

最后发现只能在flatMap中创建和关闭RpcClient

public Mono<ServerResponse> addCart(ServerRequest request){
        AtomicReference<Cart> temp = new AtomicReference<>();
        return request.bodyToMono(Cart.class)
                .flatMap(cart -> doctorService.addCart(cart))
                .flatMap(cart -> {
                    System.out.println("cart : " + cart);
                    Supplier<String> correlationIdSupplier = () -> UUID.randomUUID().toString();
                    RpcClient rpcClient = this.sender
                            .rpcClient("", RPC_QUEUE, correlationIdSupplier);
                    Mono<Delivery> reply =
                            rpcClient.rpc(Mono.just(new RpcClient.RpcRequest(cart.toString().getBytes())))
                                    .doOnError(e -> System.out.println("send failed" + e));
                    rpcClient.close();
                    temp.set(cart);
                    reply.subscribe(m ->  System.out.println("返回的数据为: " + new String(m.getBody()) ));
                    return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).bodyValue(temp);
                });
    }


来自为知笔记(Wiz)


posted on 2023-02-18 09:24  白衣风云  阅读(12)  评论(0编辑  收藏  举报

导航