Skip to content

Expose connection outgoingPendingMessageCount and outgoingPendingBytes#1412

Merged
scottf merged 2 commits intomainfrom
write-queue-info
Sep 5, 2025
Merged

Expose connection outgoingPendingMessageCount and outgoingPendingBytes#1412
scottf merged 2 commits intomainfrom
write-queue-info

Conversation

@scottf
Copy link
Contributor

@scottf scottf commented Sep 4, 2025

MessageQueue is used in multiple ways, for both incoming and outgoing messages, but this PR focuses on NatsConnectionWriter which is used for outgoing messages.

NatsConnectionWriter is used by NatsConnection to publish messages. (The concept of Producer is a Kafka concept and is more analogous to your specific application component that publishes messages. NATS itself has no concept of a Producer, and for that matter using broker is confusing as well as that is also a Kafka concept.)

The MessageQueue's
length is a count of items [messages] in the queue. sizeInBytes is the number of bytes calculated from the serialized form of all the messages in the queue.

The change to NatsConnectionWriter exposes the MessageQueue's length and sizeInBytes with two new internal (packaged scoped) messages that specifically expose the Outgoing MessageQueue's information

long outgoingPendingMessageCount() {
    return outgoing.length();
}

long outgoingPendingBytes() {
    return outgoing.sizeInBytes();
}

The change to the Connection interface and the NatsConnection implementation exposes publicly the length and sizeInBytes from the NatsConnectionWriter.

public long outgoingPendingMessageCount() {
    return writer.outgoingPendingMessageCount();
}

public long outgoingPendingBytes() {
    return writer.outgoingPendingBytes();
}

@scottf scottf requested a review from jnmoyne September 4, 2025 20:19
Copy link
Collaborator

@jnmoyne jnmoyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@scottf scottf merged commit cc66c06 into main Sep 5, 2025
5 checks passed
@scottf scottf deleted the write-queue-info branch September 5, 2025 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants