@@ -629,6 +629,10 @@ public SendResult sendMessage(
629
629
switch (communicationMode ) {
630
630
case ONEWAY :
631
631
this .remotingClient .invokeOneway (addr , request , timeoutMillis );
632
+ if (instance != null ) {
633
+ instance .getProducerStatsManager ().incSendTimes (msg .getTopic (), 1 );
634
+ instance .getProducerStatsManager ().incSendRT (msg .getTopic (), System .currentTimeMillis () - beginStartTime );
635
+ }
632
636
return null ;
633
637
case ASYNC :
634
638
final AtomicInteger times = new AtomicInteger ();
@@ -644,7 +648,19 @@ public SendResult sendMessage(
644
648
if (timeoutMillis < costTimeSync ) {
645
649
throw new RemotingTooMuchRequestException ("sendMessage call timeout" );
646
650
}
647
- return this .sendMessageSync (addr , brokerName , msg , timeoutMillis - costTimeSync , request );
651
+ try {
652
+ SendResult result = this .sendMessageSync (addr , brokerName , msg , timeoutMillis - costTimeSync , request );
653
+ if (instance != null ) {
654
+ instance .getProducerStatsManager ().incSendTimes (msg .getTopic (), 1 );
655
+ instance .getProducerStatsManager ().incSendRT (msg .getTopic (), System .currentTimeMillis () - beginStartTime );
656
+ }
657
+ return result ;
658
+ } catch (Exception e ) {
659
+ if (instance != null ) {
660
+ instance .getProducerStatsManager ().incSendFailedTimes (msg .getTopic (), 1 );
661
+ }
662
+ throw e ;
663
+ }
648
664
default :
649
665
assert false ;
650
666
break ;
@@ -709,6 +725,10 @@ public void operationSucceed(RemotingCommand response) {
709
725
}
710
726
711
727
producer .updateFaultItem (brokerName , System .currentTimeMillis () - beginStartTime , false , true );
728
+ if (instance != null ) {
729
+ instance .getProducerStatsManager ().incSendTimes (msg .getTopic (), 1 );
730
+ instance .getProducerStatsManager ().incSendRT (msg .getTopic (), cost );
731
+ }
712
732
return ;
713
733
}
714
734
@@ -726,6 +746,10 @@ public void operationSucceed(RemotingCommand response) {
726
746
}
727
747
728
748
producer .updateFaultItem (brokerName , System .currentTimeMillis () - beginStartTime , false , true );
749
+ if (instance != null ) {
750
+ instance .getProducerStatsManager ().incSendTimes (msg .getTopic (), 1 );
751
+ instance .getProducerStatsManager ().incSendRT (msg .getTopic (), cost );
752
+ }
729
753
} catch (Exception e ) {
730
754
producer .updateFaultItem (brokerName , System .currentTimeMillis () - beginStartTime , true , true );
731
755
onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
@@ -737,6 +761,9 @@ public void operationSucceed(RemotingCommand response) {
737
761
public void operationFail (Throwable throwable ) {
738
762
producer .updateFaultItem (brokerName , System .currentTimeMillis () - beginStartTime , true , true );
739
763
long cost = System .currentTimeMillis () - beginStartTime ;
764
+ if (instance != null ) {
765
+ instance .getProducerStatsManager ().incSendFailedTimes (msg .getTopic (), 1 );
766
+ }
740
767
if (throwable instanceof RemotingSendRequestException ) {
741
768
MQClientException ex = new MQClientException ("send request failed" , throwable );
742
769
onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
@@ -756,6 +783,9 @@ public void operationFail(Throwable throwable) {
756
783
} catch (Exception ex ) {
757
784
long cost = System .currentTimeMillis () - beginStartTime ;
758
785
producer .updateFaultItem (brokerName , cost , true , false );
786
+ if (instance != null ) {
787
+ instance .getProducerStatsManager ().incSendFailedTimes (msg .getTopic (), 1 );
788
+ }
759
789
onExceptionImpl (brokerName , msg , timeoutMillis - cost , request , sendCallback , topicPublishInfo , instance ,
760
790
retryTimesWhenSendFailed , times , ex , context , true , producer );
761
791
}
0 commit comments