Repository: activemq-artemis
Updated Branches:
  refs/heads/ARTEMIS-780 b3acd1622 -> d8f4c00e0


Catch QueueExists exception when auto creating


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/4041d409
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/4041d409
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/4041d409

Branch: refs/heads/ARTEMIS-780
Commit: 4041d409c9c8ae548f855b0b49b5c527dba392a4
Parents: b3acd16
Author: Martyn Taylor <mtay...@redhat.com>
Authored: Thu Dec 1 16:29:26 2016 +0000
Committer: Martyn Taylor <mtay...@redhat.com>
Committed: Thu Dec 1 16:29:26 2016 +0000

----------------------------------------------------------------------
 .../jms/client/ActiveMQMessageProducer.java     |  6 +++-
 .../artemis/jms/client/ActiveMQSession.java     | 29 ++++++++++++++------
 2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4041d409/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
----------------------------------------------------------------------
diff --git 
a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
 
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
index 4c1d335..b814bc2 100644
--- 
a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
+++ 
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
@@ -36,6 +36,7 @@ import javax.jms.TopicPublisher;
 
 import org.apache.activemq.artemis.api.core.ActiveMQException;
 import org.apache.activemq.artemis.api.core.ActiveMQInterruptedException;
+import org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.client.ClientMessage;
 import org.apache.activemq.artemis.api.core.client.ClientProducer;
@@ -421,7 +422,10 @@ public class ActiveMQMessageProducer implements 
MessageProducer, QueueSender, To
                } else {
                   connection.addKnownDestination(address);
                }
-            } catch (ActiveMQException e) {
+            } catch (ActiveMQQueueExistsException e) {
+               // The queue was created by another client/admin between the 
query check and send create queue packet
+            }
+            catch (ActiveMQException e) {
                throw JMSExceptionHelper.convertFromActiveMQException(e);
             }
          }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/4041d409/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
----------------------------------------------------------------------
diff --git 
a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
 
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
index 3e9b76f..a25215e 100644
--- 
a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
+++ 
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
@@ -301,15 +301,21 @@ public class ActiveMQSession implements QueueSession, 
TopicSession {
             ClientSession.AddressQuery response = 
session.addressQuery(jbd.getSimpleAddress());
 
             if (!response.isExists()) {
-               if (jbd.isQueue() && response.isAutoCreateJmsQueues()) {
-                  // perhaps just relying on the broker to do it is simplest 
(i.e. deleteOnNoConsumers)
-                  session.createAddress(jbd.getSimpleAddress(), 
RoutingType.ANYCAST, true);
-                  session.createQueue(jbd.getSimpleAddress(), 
RoutingType.ANYCAST, jbd.getSimpleAddress(), null, true, true);
-               } else if (!jbd.isQueue() && response.isAutoCreateJmsTopics()) {
-                  session.createAddress(jbd.getSimpleAddress(), 
RoutingType.MULTICAST, true);
-               } else {
-                  throw new InvalidDestinationException("Destination " + 
jbd.getName() + " does not exist");
+               try {
+                  if (jbd.isQueue() && response.isAutoCreateJmsQueues()) {
+                     // perhaps just relying on the broker to do it is 
simplest (i.e. deleteOnNoConsumers)
+                     session.createAddress(jbd.getSimpleAddress(), 
RoutingType.ANYCAST, true);
+                     session.createQueue(jbd.getSimpleAddress(), 
RoutingType.ANYCAST, jbd.getSimpleAddress(), null, true, true);
+                  } else if (!jbd.isQueue() && 
response.isAutoCreateJmsTopics()) {
+                     session.createAddress(jbd.getSimpleAddress(), 
RoutingType.MULTICAST, true);
+                  } else {
+                     throw new InvalidDestinationException("Destination " + 
jbd.getName() + " does not exist");
+                  }
+               }
+               catch (ActiveMQQueueExistsException e) {
+                  // Queue was created between our query and create queue 
request.  Ignore.
                }
+
             }
          }
 
@@ -647,7 +653,12 @@ public class ActiveMQSession implements QueueSession, 
TopicSession {
              */
             if (!response.isExists() || 
!response.getQueueNames().contains(dest.getSimpleAddress())) {
                if (response.isAutoCreateJmsQueues()) {
-                  session.createQueue(dest.getSimpleAddress(), 
RoutingType.ANYCAST, dest.getSimpleAddress(), null, true, true);
+                  try {
+                     session.createQueue(dest.getSimpleAddress(), 
RoutingType.ANYCAST, dest.getSimpleAddress(), null, true, true);
+                  }
+                  catch (ActiveMQQueueExistsException e) {
+                     // The queue was created by another client/admin between 
the query check and send create queue packet
+                  }
                } else {
                   throw new InvalidDestinationException("Destination " + 
dest.getName() + " does not exist");
                }

Reply via email to