ARTEMIS-2339 Set JMS Name on compatible destinations
This commit is contained in:
parent
c9a7bbceb3
commit
9c9bd48154
|
@ -55,7 +55,9 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -297,15 +299,21 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
|
|||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
@ -1296,6 +1296,10 @@ public class ActiveMQSession implements QueueSession, TopicSession {
|
|||
queue = ActiveMQDestination.createQueue(queueNameToUse);
|
||||
}
|
||||
|
||||
if (queueName != queueNameToUse) {
|
||||
queue.setName(queueName);
|
||||
}
|
||||
|
||||
QueueQuery response = session.queueQuery(queue.getSimpleAddress());
|
||||
|
||||
if (!response.isExists() && !response.isAutoCreateQueues()) {
|
||||
|
@ -1319,6 +1323,11 @@ public class ActiveMQSession implements QueueSession, TopicSession {
|
|||
topic = ActiveMQDestination.createTopic(topicNameToUse);
|
||||
}
|
||||
|
||||
if (topicNameToUse != topicName) {
|
||||
topic.setName(topicName);
|
||||
}
|
||||
|
||||
|
||||
AddressQuery query = session.addressQuery(topic.getSimpleAddress());
|
||||
|
||||
if (!query.isExists() && !query.isAutoCreateAddresses()) {
|
||||
|
|
|
@ -31,6 +31,9 @@ try {
|
|||
Connection connection = cf.createConnection();
|
||||
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
|
||||
Queue myQueue = session.createQueue("myQueue");
|
||||
|
||||
GroovyRun.assertEquals("myQueue", myQueue.getQueueName());
|
||||
|
||||
MessageConsumer queueConsumer = session.createConsumer(myQueue);
|
||||
consumerCreated.countDown();
|
||||
connection.start()
|
||||
|
|
|
@ -34,6 +34,8 @@ connection.start();
|
|||
|
||||
Queue myQueue = session.createQueue("myQueue");
|
||||
|
||||
GroovyRun.assertEquals("myQueue", myQueue.getQueueName());
|
||||
|
||||
System.out.println("myQueue::" + myQueue);
|
||||
TemporaryTopic replyTopic = session.createTemporaryTopic();
|
||||
MessageConsumer consumer = session.createConsumer(replyTopic);
|
||||
|
|
|
@ -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.ActiveMQServers;
|
||||
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.spi.core.security.ActiveMQJAASSecurityManager;
|
||||
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
|
||||
|
@ -679,10 +680,17 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
|
|||
Connection connection = connectionFactory.createConnection();
|
||||
Session session = connection.createSession();
|
||||
|
||||
assertTrue(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString()));
|
||||
assertTrue(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()));
|
||||
assertTrue(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString()));
|
||||
assertTrue(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString()));
|
||||
assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
|
||||
assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
|
||||
assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
|
||||
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();
|
||||
|
||||
|
@ -692,10 +700,16 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
|
|||
connection = connectionFactory.createConnection();
|
||||
session = connection.createSession();
|
||||
|
||||
assertTrue(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString()));
|
||||
assertTrue(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()));
|
||||
assertTrue(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString()));
|
||||
assertTrue(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString()));
|
||||
assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
|
||||
assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
|
||||
assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
|
||||
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();
|
||||
}
|
||||
|
@ -712,10 +726,10 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase {
|
|||
Connection connection = connectionFactory.createConnection();
|
||||
Session session = connection.createSession();
|
||||
|
||||
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()));
|
||||
assertFalse(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
|
||||
assertFalse(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
|
||||
assertFalse(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
|
||||
assertFalse(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
|
||||
|
||||
connection.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue