MountainOne commented on issue #1588: Retry doesn't work when sending msg in aync mode(eg. when broker is down) URL: https://github.com/apache/rocketmq/issues/1588#issuecomment-555010606 @xiangwangcheng I fully understand what you mean. But the callback function passed to `remotingClient.invokeAsync` will always be called, not only when the message is sent successfully. The callback function that you said is only called when the message is sent successfully should be the parameter `sendCallback` passed to `MQClientAPIImpl#sendMessageAsync`. When the broker has gone down, the message sent will not be returned. `producer` will compare with the `timeoutMillis` according to the time the message has been sent. If it is greater than that, the message will be sent timeout. Set the send status of `responseFuture` to false and execute the `InvokeCallback` callback function passed in `remotingClient.invokeAsync()`. Regardless of whether the message was sent successfully or not, `InvokerCallback()` will be executed. Then, based on the returned response, if response returns and no exception occurs, it will not be retried; if it is null or an exception occurs, it will be retried. The specific async communication logic can refer to `NettyRemotingClient#invokeAsync` and `NettyRemotingAbstract#invokeAsyncImpl` in the remoting module. Here is a list of key codes. 我完全明白您的意思。 但传给`remotingClient.invokeAsync`的回调函数总是会被调用的,不仅仅是在消息发送成功的时候。您所说的在只有在消息发送成功时才调用的回调函数应该是传给`MQClientAPIImpl#sendMessageAsync`的参数`sendCallback`。 当 broker 已经宕机时,发送的消息将无法返回。`producer`会根据消息已经发出的时间与`timeoutMillis`比较,大于则判断消息发送超时。将`responseFuture`的发送状态设置为 false 并执行`remotingClient.invokeAsync()`中传入的`InvokeCallback`回调函数。不管消息发送成功与否,`InvokerCallback()`都会执行。然后根据返回的 response 判断,如果 response 返回了且没有出现异常,就不会重试;如果为 null 或者出现异常,就会进行重试。 具体的异步通信逻辑可以参考 remoting 模块中的`NettyRemotingClient#invokeAsync`和`NettyRemotingAbstract#invokeAsyncImpl`。这里列一下关键代码,在`NettyRemotingAbstract#invokeAsyncImpl`中。 ```Java channel.writeAndFlush(request).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture f) throws Exception { if (f.isSuccess()) { responseFuture.setSendRequestOK(true); return; } requestFail(opaque); log.warn("send a request command to channel <{}> failed.", RemotingHelper.parseChannelRemoteAddr(channel)); } }); ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
