@@ -523,65 +523,72 @@ private void sendMessageAsync(
523
523
final DefaultMQProducerImpl producer
524
524
) throws InterruptedException , RemotingException {
525
525
final long beginStartTime = System .currentTimeMillis ();
526
- this .remotingClient .invokeAsync (addr , request , timeoutMillis , new InvokeCallback () {
527
- @ Override
528
- public void operationComplete (ResponseFuture responseFuture ) {
529
- long cost = System .currentTimeMillis () - beginStartTime ;
530
- RemotingCommand response = responseFuture .getResponseCommand ();
531
- if (null == sendCallback && response != null ) {
532
-
533
- try {
534
- SendResult sendResult = MQClientAPIImpl .this .processSendResponse (brokerName , msg , response , addr );
535
- if (context != null && sendResult != null ) {
536
- context .setSendResult (sendResult );
537
- context .getProducer ().executeSendMessageHookAfter (context );
538
- }
539
- } catch (Throwable e ) {
540
- }
541
-
542
- producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), false );
543
- return ;
544
- }
545
-
546
- if (response != null ) {
547
- try {
548
- SendResult sendResult = MQClientAPIImpl .this .processSendResponse (brokerName , msg , response , addr );
549
- assert sendResult != null ;
550
- if (context != null ) {
551
- context .setSendResult (sendResult );
552
- context .getProducer ().executeSendMessageHookAfter (context );
553
- }
526
+ try {
527
+ this .remotingClient .invokeAsync (addr , request , timeoutMillis , new InvokeCallback () {
528
+ @ Override
529
+ public void operationComplete (ResponseFuture responseFuture ) {
530
+ long cost = System .currentTimeMillis () - beginStartTime ;
531
+ RemotingCommand response = responseFuture .getResponseCommand ();
532
+ if (null == sendCallback && response != null ) {
554
533
555
534
try {
556
- sendCallback .onSuccess (sendResult );
535
+ SendResult sendResult = MQClientAPIImpl .this .processSendResponse (brokerName , msg , response , addr );
536
+ if (context != null && sendResult != null ) {
537
+ context .setSendResult (sendResult );
538
+ context .getProducer ().executeSendMessageHookAfter (context );
539
+ }
557
540
} catch (Throwable e ) {
558
541
}
559
542
560
543
producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), false );
561
- } catch (Exception e ) {
562
- producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), true );
563
- onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
564
- retryTimesWhenSendFailed , times , e , context , false , producer );
544
+ return ;
565
545
}
566
- } else {
567
- producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), true );
568
- if (!responseFuture .isSendRequestOK ()) {
569
- MQClientException ex = new MQClientException ("send request failed" , responseFuture .getCause ());
570
- onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
571
- retryTimesWhenSendFailed , times , ex , context , true , producer );
572
- } else if (responseFuture .isTimeout ()) {
573
- MQClientException ex = new MQClientException ("wait response timeout " + responseFuture .getTimeoutMillis () + "ms" ,
574
- responseFuture .getCause ());
575
- onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
576
- retryTimesWhenSendFailed , times , ex , context , true , producer );
546
+
547
+ if (response != null ) {
548
+ try {
549
+ SendResult sendResult = MQClientAPIImpl .this .processSendResponse (brokerName , msg , response , addr );
550
+ assert sendResult != null ;
551
+ if (context != null ) {
552
+ context .setSendResult (sendResult );
553
+ context .getProducer ().executeSendMessageHookAfter (context );
554
+ }
555
+
556
+ try {
557
+ sendCallback .onSuccess (sendResult );
558
+ } catch (Throwable e ) {
559
+ }
560
+
561
+ producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), false );
562
+ } catch (Exception e ) {
563
+ producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), true );
564
+ onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
565
+ retryTimesWhenSendFailed , times , e , context , false , producer );
566
+ }
577
567
} else {
578
- MQClientException ex = new MQClientException ("unknow reseaon" , responseFuture .getCause ());
579
- onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
580
- retryTimesWhenSendFailed , times , ex , context , true , producer );
568
+ producer .updateFaultItem (brokerName , System .currentTimeMillis () - responseFuture .getBeginTimestamp (), true );
569
+ if (!responseFuture .isSendRequestOK ()) {
570
+ MQClientException ex = new MQClientException ("send request failed" , responseFuture .getCause ());
571
+ onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
572
+ retryTimesWhenSendFailed , times , ex , context , true , producer );
573
+ } else if (responseFuture .isTimeout ()) {
574
+ MQClientException ex = new MQClientException ("wait response timeout " + responseFuture .getTimeoutMillis () + "ms" ,
575
+ responseFuture .getCause ());
576
+ onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
577
+ retryTimesWhenSendFailed , times , ex , context , true , producer );
578
+ } else {
579
+ MQClientException ex = new MQClientException ("unknow reseaon" , responseFuture .getCause ());
580
+ onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
581
+ retryTimesWhenSendFailed , times , ex , context , true , producer );
582
+ }
581
583
}
582
584
}
583
- }
584
- });
585
+ });
586
+ } catch (Exception ex ) {
587
+ long cost = System .currentTimeMillis () - beginStartTime ;
588
+ producer .updateFaultItem (brokerName , cost , true );
589
+ onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
590
+ retryTimesWhenSendFailed , times , ex , context , true , producer );
591
+ }
585
592
}
586
593
587
594
private void onExceptionImpl (final String brokerName ,
0 commit comments