Repository: activemq-6 Updated Branches: refs/heads/master 661232079 -> 323337148
Fixing TransactionFailoverExample The TransactionFailoverExample IDs are not really unique if the journal is not cleaned up This commit will make the IDs to use an UUID so the ID will always be unique even if you reuse the journal Project: http://git-wip-us.apache.org/repos/asf/activemq-6/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-6/commit/0ff13d0c Tree: http://git-wip-us.apache.org/repos/asf/activemq-6/tree/0ff13d0c Diff: http://git-wip-us.apache.org/repos/asf/activemq-6/diff/0ff13d0c Branch: refs/heads/master Commit: 0ff13d0cf0b85a7cacb4fb3e27b1fc2ebe54cffd Parents: 6612320 Author: Clebert Suconic <[email protected]> Authored: Mon Feb 23 16:19:00 2015 -0500 Committer: Clebert Suconic <[email protected]> Committed: Tue Feb 24 12:00:34 2015 -0500 ---------------------------------------------------------------------- .../ReplicatedTransactionFailoverExample.java | 11 +++++++++-- .../jms/example/TransactionFailoverExample.java | 16 +++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-6/blob/0ff13d0c/examples/jms/replicated-transaction-failover/src/main/java/org/apache/activemq/jms/example/ReplicatedTransactionFailoverExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/replicated-transaction-failover/src/main/java/org/apache/activemq/jms/example/ReplicatedTransactionFailoverExample.java b/examples/jms/replicated-transaction-failover/src/main/java/org/apache/activemq/jms/example/ReplicatedTransactionFailoverExample.java index 80f8ed6..98f096b 100644 --- a/examples/jms/replicated-transaction-failover/src/main/java/org/apache/activemq/jms/example/ReplicatedTransactionFailoverExample.java +++ b/examples/jms/replicated-transaction-failover/src/main/java/org/apache/activemq/jms/example/ReplicatedTransactionFailoverExample.java @@ -37,6 +37,13 @@ import org.apache.activemq.common.example.ActiveMQExample; */ public class ReplicatedTransactionFailoverExample extends ActiveMQExample { + + // You need to guarantee uniqueIDs when using duplicate detection + // It needs to be unique even after a restart + // as these IDs are stored on the journal for control + // We recommend some sort of UUID, but for this example the Current Time as string would be enough + String uniqueID = Long.toString(System.currentTimeMillis()); + public static void main(final String[] args) { new ReplicatedTransactionFailoverExample().run(args); @@ -146,7 +153,7 @@ public class ReplicatedTransactionFailoverExample extends ActiveMQExample // We set the duplicate detection header - so the server will ignore the same message // if sent again after failover - message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "uniqueid" + i); + message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), uniqueID + i); producer.send(message); @@ -169,7 +176,7 @@ public class ReplicatedTransactionFailoverExample extends ActiveMQExample // We set the duplicate detection header - so the server will ignore the same message // if sent again after failover - message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "uniqueid" + i); + message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), uniqueID + i); producer.send(message); http://git-wip-us.apache.org/repos/asf/activemq-6/blob/0ff13d0c/examples/jms/transaction-failover/src/main/java/org/apache/activemq/jms/example/TransactionFailoverExample.java ---------------------------------------------------------------------- diff --git a/examples/jms/transaction-failover/src/main/java/org/apache/activemq/jms/example/TransactionFailoverExample.java b/examples/jms/transaction-failover/src/main/java/org/apache/activemq/jms/example/TransactionFailoverExample.java index d9cbd95..9666c8f 100644 --- a/examples/jms/transaction-failover/src/main/java/org/apache/activemq/jms/example/TransactionFailoverExample.java +++ b/examples/jms/transaction-failover/src/main/java/org/apache/activemq/jms/example/TransactionFailoverExample.java @@ -37,11 +37,19 @@ import org.apache.activemq.common.example.ActiveMQExample; */ public class TransactionFailoverExample extends ActiveMQExample { + public static void main(final String[] args) { new TransactionFailoverExample().run(args); } + // You need to guarantee uniqueIDs when using duplicate detection + // It needs to be unique even after a restart + // as these IDs are stored on the journal for control + // We recommend some sort of UUID, but for this example the Current Time as string would be enough + String uniqueID = Long.toString(System.currentTimeMillis()); + + @Override public boolean runExample() throws Exception { @@ -138,15 +146,13 @@ public class TransactionFailoverExample extends ActiveMQExample final int numMessages, final boolean killServer) throws Exception { + // We send half of messages for (int i = 0; i < numMessages / 2; i++) { TextMessage message = session.createTextMessage("This is text message " + i); - // We set the duplicate detection header - so the server will ignore the same message - // if sent again after failover - - message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "uniqueid" + i); + message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), uniqueID + i); producer.send(message); @@ -169,7 +175,7 @@ public class TransactionFailoverExample extends ActiveMQExample // We set the duplicate detection header - so the server will ignore the same message // if sent again after failover - message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), "uniqueid" + i); + message.setStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), uniqueID + i); producer.send(message);
