Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTEMIS-4649 Use unique STOMP message ID per subscription #4825

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

thezbyg
Copy link
Contributor

@thezbyg thezbyg commented Feb 17, 2024

Use combined consumer and message ID as STOMP message ID.

@jbertram
Copy link
Contributor

The tests you added don't actually fail without the fix. This WARN message is logged:

WARN  [org.apache.activemq.artemis.core.protocol.stomp] AMQ332069: Sent ERROR frame to STOMP client /127.0.0.1:43064: AMQ339026 subscription id sub2 does not match sub1

However, the test succeeds. The tests should fail without the fix.

@thezbyg
Copy link
Contributor Author

thezbyg commented Feb 18, 2024

Fixed tests to fail without the fix and removed accidentally included logging in unrelated tests.

@jbertram
Copy link
Contributor

Can you squash your commits?

@@ -344,7 +348,8 @@ public StompFrame createMessageFrame(ICoreMessage serverMessage, StompSubscripti
}
frame.setByteBody(data);

StompUtils.copyStandardHeadersFromMessageToFrame((serverMessage), frame, deliveryCount);
frame.addHeader(Stomp.Headers.Message.MESSAGE_ID, String.valueOf(consumer.getID()) + StompSession.MESSAGE_ID_SEPARATOR + String.valueOf(serverMessage.getMessageID()));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to be done for every message dispatched from the broker so it would be worth making this is as fast as possible. Perhaps something like:

frame.addHeader(Stomp.Headers.Message.MESSAGE_ID, new StringBuilder(32).append(consumer.getID()).append(StompSession.MESSAGE_ID_SEPARATOR).append(serverMessage.getMessageID()).toString());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but I set initial StringBuilder capacity to 41 to fit two long values and separator.

Copy link
Contributor

Choose a reason for hiding this comment

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

How did you arrive at the 41 value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Minimum long value is 20 characters (-9223372036854775808), so two long values and separator could require 41 characters total.

Copy link
Contributor

Choose a reason for hiding this comment

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

Message and consumer IDs should never be < 0 so the potential values are 0 (1 character) through 9223372036854775807 (19 characters). Since these characters are just digits (i.e. part of ISO-8859-1) then they will be represented by a single byte in the byte[] that backs the String. We want to avoid expanding the backing array but we also want to avoid over-allocating (and therefore wasting) space. Ten characters for each long seems like a fair middle ground.

Use combined consumer and message ID as STOMP message ID.
@jbertram jbertram merged commit 0d1d88a into apache:main Feb 19, 2024
6 checks passed
@jbertram
Copy link
Contributor

@thezbyg, thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants