Skip to content

Commit

Permalink
REM: Add publishing time to publisher log (#295)
Browse files Browse the repository at this point in the history
Information message contains information about time needed to
communicate with MB. Publishing time has been added to
publisher log.
  • Loading branch information
arun-kumarkr authored Aug 19, 2024
1 parent 4aa72b9 commit be307d8
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeoutException;

Expand Down Expand Up @@ -632,9 +633,18 @@ public void send(String routingKey, String msg, String eventId)
: MessageProperties.BASIC;

try {
long publishStartTime = System.nanoTime();
channel.basicPublish(exchangeName, routingKey, msgProps, msg.getBytes());
log.info("Published message {} with size {} bytes on exchange '{}' with routing key '{}'", eventId,
msg.getBytes().length, exchangeName, routingKey);
long publishEndTime = System.nanoTime();
long diff = publishEndTime - publishStartTime;
Duration durationInNanos = Duration.ofNanos(diff);
String duration = String.format("%d:%02d:%02d.%03d",
durationInNanos.toHours(),
durationInNanos.toMinutesPart(),
durationInNanos.toSecondsPart(),
durationInNanos.toMillisPart());
log.info("Published message {} with size {} bytes on exchange '{}' with routing key '{}' with the duration of '{}'", eventId,
msg.getBytes().length, exchangeName, routingKey, duration);
if (waitForConfirmsTimeOut == null || waitForConfirmsTimeOut == 0) {
waitForConfirmsTimeOut = DEFAULT_WAIT_FOR_CONFIRMS_TIMEOUT;
}
Expand Down Expand Up @@ -712,4 +722,4 @@ public String getTypeRoutingKeyFromConfiguration(String eventType) {
}


}
}

0 comments on commit be307d8

Please sign in to comment.