I have a producer that sends messages for 15 second. I wanted to investigate the total number of messages sent to the broker. The first method I employed involved counting messages "manually", ie:
// ...
private int sentMessages = 0;
@Override
public void run() {
sendMessage(msg));
sentMessages++;
}
The second method I used involved analysing the producer's metrics.
I compared the number of produced messages, and significantly different results I observed baffled me. sendMessages
was equal to 65243
whereas the producer's record-sent-total
was equal 47883
.
What might be the reason behind such a great difference between them?
I believe sendMessage(msg) processing in asynchronous way. So some message might failed to send. Try to update sentMessages count based on successful response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.