2020import  java .net .URISyntaxException ;
2121import  java .security .KeyManagementException ;
2222import  java .security .NoSuchAlgorithmException ;
23+ import  java .time .Duration ;
2324import  java .util .*;
2425import  java .util .concurrent .TimeoutException ;
2526
@@ -632,9 +633,18 @@ public void send(String routingKey, String msg, String eventId)
632633                    : MessageProperties .BASIC ;
633634
634635        try  {
636+             long  publishStartTime  = System .nanoTime ();
635637            channel .basicPublish (exchangeName , routingKey , msgProps , msg .getBytes ());
636-             log .info ("Published message {} with size {} bytes on exchange '{}' with routing key '{}'" , eventId ,
637-                     msg .getBytes ().length , exchangeName , routingKey );
638+             long  publishEndTime  = System .nanoTime ();
639+             long  diff  = publishEndTime  - publishStartTime ;
640+             Duration  durationInNanos  = Duration .ofNanos (diff );
641+             String  duration  = String .format ("%d:%02d:%02d.%03d" ,
642+                     durationInNanos .toHours (),
643+                     durationInNanos .toMinutesPart (),
644+                     durationInNanos .toSecondsPart (),
645+                     durationInNanos .toMillisPart ());
646+             log .info ("Published message {} with size {} bytes on exchange '{}' with routing key '{}' with the duration of '{}'" , eventId ,
647+                     msg .getBytes ().length , exchangeName , routingKey , duration );
638648            if  (waitForConfirmsTimeOut  == null  || waitForConfirmsTimeOut  == 0 ) {
639649                waitForConfirmsTimeOut  = DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT ;
640650            }
@@ -712,4 +722,4 @@ public String getTypeRoutingKeyFromConfiguration(String eventType) {
712722    }
713723
714724
715- }
725+ }
0 commit comments