mirror of https://github.com/apache/activemq.git
Additional fixes for https://issues.apache.org/jira/browse/AMQ-3855 - timing issue in adding wildcard subscriptions can result in duplicate messages sent to MQTT
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1341820 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1b28cf1792
commit
144dda0308
|
@ -109,9 +109,6 @@ public class Topic extends BaseDestination implements Task {
|
|||
}
|
||||
|
||||
public void addSubscription(ConnectionContext context, final Subscription sub) throws Exception {
|
||||
|
||||
super.addSubscription(context, sub);
|
||||
|
||||
if (!sub.getConsumerInfo().isDurable()) {
|
||||
|
||||
// Do a retroactive recovery if needed.
|
||||
|
@ -121,23 +118,34 @@ public class Topic extends BaseDestination implements Task {
|
|||
// while we are recovering a subscription to avoid out of order messages.
|
||||
dispatchLock.writeLock().lock();
|
||||
try {
|
||||
boolean applyRecovery = false;
|
||||
synchronized (consumers) {
|
||||
sub.add(context, this);
|
||||
consumers.add(sub);
|
||||
if (!consumers.contains(sub)){
|
||||
sub.add(context, this);
|
||||
consumers.add(sub);
|
||||
applyRecovery=true;
|
||||
super.addSubscription(context, sub);
|
||||
}
|
||||
}
|
||||
if (applyRecovery){
|
||||
subscriptionRecoveryPolicy.recover(context, this, sub);
|
||||
}
|
||||
subscriptionRecoveryPolicy.recover(context, this, sub);
|
||||
} finally {
|
||||
dispatchLock.writeLock().unlock();
|
||||
}
|
||||
|
||||
} else {
|
||||
synchronized (consumers) {
|
||||
sub.add(context, this);
|
||||
consumers.add(sub);
|
||||
if (!consumers.contains(sub)){
|
||||
sub.add(context, this);
|
||||
consumers.add(sub);
|
||||
super.addSubscription(context, sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DurableTopicSubscription dsub = (DurableTopicSubscription) sub;
|
||||
super.addSubscription(context, sub);
|
||||
sub.add(context, this);
|
||||
if(dsub.isActive()) {
|
||||
synchronized (consumers) {
|
||||
|
|
|
@ -255,7 +255,7 @@ public class MQTTTest {
|
|||
javax.jms.Topic jmsTopic = s.createTopic("foo.far");
|
||||
MessageProducer producer = s.createProducer(jmsTopic);
|
||||
|
||||
Topic[] topics = {new Topic(utf8("foo/far"), QoS.AT_MOST_ONCE)};
|
||||
Topic[] topics = {new Topic(utf8("foo/+"), QoS.AT_MOST_ONCE)};
|
||||
connection.subscribe(topics);
|
||||
for (int i = 0; i < numberOfMessages; i++) {
|
||||
String payload = "This is Test Message: " + i;
|
||||
|
|
Loading…
Reference in New Issue