ARTEMIS-2339 Set JMS Name on compatible destinations

This commit is contained in:
Clebert Suconic 2019-05-15 18:03:15 -04:00
parent c9a7bbceb3
commit 9c9bd48154
5 changed files with 53 additions and 17 deletions

View File

@ -55,7 +55,9 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
return input.replace("\\", "\\\\").replace(".", "\\."); return input.replace("\\", "\\\\").replace(".", "\\.");
} }
protected void setName(String name) { /** createQueue and createTopic from {@link ActiveMQSession} may change the name
* in case Prefix usage */
void setName(String name) {
this.name = name; this.name = name;
} }
@ -297,15 +299,21 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
} }
public static ActiveMQTemporaryQueue createTemporaryQueue(final ActiveMQSession session, final String prefix) { public static ActiveMQTemporaryQueue createTemporaryQueue(final ActiveMQSession session, final String prefix) {
String address = prefix + UUID.randomUUID().toString(); String name = UUID.randomUUID().toString();
String address = prefix + name;
return createTemporaryQueue(address, session); ActiveMQTemporaryQueue queue = createTemporaryQueue(address, session);
queue.setName(name);
return queue;
} }
public static ActiveMQTemporaryTopic createTemporaryTopic(final ActiveMQSession session, final String prefix) { public static ActiveMQTemporaryTopic createTemporaryTopic(final ActiveMQSession session, final String prefix) {
String address = prefix + UUID.randomUUID().toString(); String name = UUID.randomUUID().toString();
String address = prefix + name;
return createTemporaryTopic(address, session); ActiveMQTemporaryTopic topic = createTemporaryTopic(address, session);
topic.setName(name);
return topic;
} }
public static ActiveMQTemporaryTopic createTemporaryTopic(String address, final ActiveMQSession session) { public static ActiveMQTemporaryTopic createTemporaryTopic(String address, final ActiveMQSession session) {

View File

@ -1296,6 +1296,10 @@ public class ActiveMQSession implements QueueSession, TopicSession {
queue = ActiveMQDestination.createQueue(queueNameToUse); queue = ActiveMQDestination.createQueue(queueNameToUse);
} }
if (queueName != queueNameToUse) {
queue.setName(queueName);
}
QueueQuery response = session.queueQuery(queue.getSimpleAddress()); QueueQuery response = session.queueQuery(queue.getSimpleAddress());
if (!response.isExists() && !response.isAutoCreateQueues()) { if (!response.isExists() && !response.isAutoCreateQueues()) {
@ -1319,6 +1323,11 @@ public class ActiveMQSession implements QueueSession, TopicSession {
topic = ActiveMQDestination.createTopic(topicNameToUse); topic = ActiveMQDestination.createTopic(topicNameToUse);
} }
if (topicNameToUse != topicName) {
topic.setName(topicName);
}
AddressQuery query = session.addressQuery(topic.getSimpleAddress()); AddressQuery query = session.addressQuery(topic.getSimpleAddress());
if (!query.isExists() && !query.isAutoCreateAddresses()) { if (!query.isExists() && !query.isAutoCreateAddresses()) {

View File

@ -31,6 +31,9 @@ try {
Connection connection = cf.createConnection(); Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue myQueue = session.createQueue("myQueue"); Queue myQueue = session.createQueue("myQueue");
GroovyRun.assertEquals("myQueue", myQueue.getQueueName());
MessageConsumer queueConsumer = session.createConsumer(myQueue); MessageConsumer queueConsumer = session.createConsumer(myQueue);
consumerCreated.countDown(); consumerCreated.countDown();
connection.start() connection.start()

View File

@ -34,6 +34,8 @@ connection.start();
Queue myQueue = session.createQueue("myQueue"); Queue myQueue = session.createQueue("myQueue");
GroovyRun.assertEquals("myQueue", myQueue.getQueueName());
System.out.println("myQueue::" + myQueue); System.out.println("myQueue::" + myQueue);
TemporaryTopic replyTopic = session.createTemporaryTopic(); TemporaryTopic replyTopic = session.createTemporaryTopic();
MessageConsumer consumer = session.createConsumer(replyTopic); MessageConsumer consumer = session.createConsumer(replyTopic);

View File

@ -55,6 +55,7 @@ import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServers; import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory; import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager; import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
@ -679,10 +680,17 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
Connection connection = connectionFactory.createConnection(); Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(); Session session = connection.createSession();
assertTrue(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
assertTrue(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
assertTrue(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
assertTrue(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
// The name should not include the prefix
assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString()));
assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()));
assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString()));
assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString()));
connection.close(); connection.close();
@ -692,10 +700,16 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
connection = connectionFactory.createConnection(); connection = connectionFactory.createConnection();
session = connection.createSession(); session = connection.createSession();
assertTrue(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
assertTrue(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
assertTrue(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
assertTrue(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); assertTrue(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
// The name should not include the prefix
assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString()));
assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()));
assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString()));
assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString()));
connection.close(); connection.close();
} }
@ -712,10 +726,10 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
Connection connection = connectionFactory.createConnection(); Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(); Session session = connection.createSession();
assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); assertFalse(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); assertFalse(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); assertFalse(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); assertFalse(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
connection.close(); connection.close();
} }