发送消息后,队列中没有显示
最后发现只能在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)
标签:rabbitmq,System,cart,消息,flatMap,rpcClient,new,out,丢失 From: https://www.cnblogs.com/baiyifengyun/p/17131980.html