This is an automated email from the ASF dual-hosted git repository.
robbie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 89b3ebb077 ARTEMIS-5209: clarify/reorder duplicate detection docs,
improve test for AMQP
89b3ebb077 is described below
commit 89b3ebb077b203dd0c9ae3b85983d6b2ac1231e9
Author: Robbie Gemmell <[email protected]>
AuthorDate: Mon Jan 20 11:33:30 2025 +0000
ARTEMIS-5209: clarify/reorder duplicate detection docs, improve test for
AMQP
---
docs/user-manual/duplicate-detection.adoc | 26 ++++++++++----------
.../tests/integration/amqp/AmqpSenderTest.java | 28 ++++++++++++++++++----
2 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/docs/user-manual/duplicate-detection.adoc
b/docs/user-manual/duplicate-detection.adoc
index 2f8eb79f0e..a859cbdf7a 100644
--- a/docs/user-manual/duplicate-detection.adoc
+++ b/docs/user-manual/duplicate-detection.adoc
@@ -40,36 +40,38 @@ If the server detects a duplicate message for any message
in the transaction, th
The name of the property that you set is given by the value of
`org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID`,
which is `_AMQ_DUPL_ID`
-The value of the property can be of type `byte[]` or `SimpleString` if you're
using the core API.
-If you're using JMS it must be a `String`, and its value should be unique.
+When using JMS the value of the property must be a `String`, and similarly a
string type would be used in other client APIs or protocols used with the
broker.
+Its value should be unique.
An easy way of generating a unique id is by generating a UUID.
-Here's an example of setting the property using the core API:
+Here's an example of setting the property using the JMS API:
[,java]
----
...
-ClientMessage message = session.createMessage(true);
+Message jmsMessage = session.createMessage();
-SimpleString myUniqueID = "This is my unique id"; // Could use a UUID for
this
+String myUniqueID = "This is my unique id"; // Could use a UUID for this
-message.setStringProperty(HDR_DUPLICATE_DETECTION_ID, myUniqueID);
+message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), myUniqueID);
+
+...
----
-And here's an example using the JMS API:
+If using the Artemis Core client the value of the property can be of type
`byte[]` or `SimpleString`.
+
+Here's an example of setting the property using using the Core API:
[,java]
----
...
-Message jmsMessage = session.createMessage();
-
-String myUniqueID = "This is my unique id"; // Could use a UUID for this
+ClientMessage message = session.createMessage(true);
-message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), myUniqueID);
+SimpleString myUniqueID = "This is my unique id"; // Could use a UUID for
this
-...
+message.setStringProperty(HDR_DUPLICATE_DETECTION_ID, myUniqueID);
----
== Configuring the Duplicate ID Cache
diff --git
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpSenderTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpSenderTest.java
index 10f54b293c..a25bd9739d 100644
---
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpSenderTest.java
+++
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpSenderTest.java
@@ -263,7 +263,7 @@ public class AmqpSenderTest extends AmqpClientTestSupport {
@TestTemplate
@Timeout(60)
public void testDuplicateDetection() throws Exception {
- final int MSG_COUNT = 10;
+ final int MSG_COUNT = 5;
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
@@ -276,14 +276,32 @@ public class AmqpSenderTest extends AmqpClientTestSupport
{
receiver.flow(10);
assertNull(receiver.receiveNoWait(), "somehow the queue had messages
from a previous test");
+ final String bodyValueA = "MessageA";
+ final String bodyValueB = "MessageB";
for (int i = 1; i <= MSG_COUNT; ++i) {
- AmqpMessage message = new AmqpMessage();
-
message.setApplicationProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(),
"123");
- sender.send(message);
+ AmqpMessage sentMessageA = new AmqpMessage();
+ sentMessageA.setText(bodyValueA);
+
sentMessageA.setApplicationProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(),
"123");
+ sender.send(sentMessageA);
}
AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
- assertNull(receiver.receiveNoWait());
+ assertNotNull(message, "A message should have been received");
+ assertEquals(bodyValueA, message.getText(), "Unexpected message body");
+ assertNull(receiver.receiveNoWait(), "No more messages should be
received");
+
+ // Send another bunch with a different ID, again expect only one to
arrive
+ for (int i = 1; i <= MSG_COUNT; ++i) {
+ AmqpMessage sentMessageB = new AmqpMessage();
+ sentMessageB.setText(bodyValueB);
+
sentMessageB.setApplicationProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(),
"456");
+ sender.send(sentMessageB);
+ }
+
+ AmqpMessage message2 = receiver.receive(5, TimeUnit.SECONDS);
+ assertNotNull(message2, "A message should have been received");
+ assertEquals(bodyValueB, message2.getText(), "Unexpected message body");
+ assertNull(receiver.receiveNoWait(), "No more messages should be
received");
sender.close();
connection.close();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact