diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java index ede1b01ede..3a893696bd 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/inflow/ActiveMQActivation.java @@ -572,10 +572,10 @@ public class ActiveMQActivation { ActiveMQRALogger.LOGGER.instantiatingDestination(spec.getDestinationType(), spec.getDestination()); if (Topic.class.getName().equals(spec.getDestinationType())) { - destination = (ActiveMQDestination) ActiveMQJMSClient.createTopic(spec.getDestination()); + destination = (ActiveMQDestination) ActiveMQJMSClient.createTopic((spec.getTopicPrefix() == null ? "" : spec.getTopicPrefix()) + spec.getDestination()); isTopic = true; } else { - destination = (ActiveMQDestination) ActiveMQJMSClient.createQueue(spec.getDestination()); + destination = (ActiveMQDestination) ActiveMQJMSClient.createQueue((spec.getQueuePrefix() == null ? "" : spec.getQueuePrefix()) + spec.getDestination()); } } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/ResourceAdapterTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/ResourceAdapterTest.java index 811cc29dba..6216bb354d 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/ResourceAdapterTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/ra/ResourceAdapterTest.java @@ -26,12 +26,17 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; +import org.apache.activemq.artemis.api.core.RoutingType; +import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory; import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ServerLocator; +import org.apache.activemq.artemis.api.core.management.AddressControl; +import org.apache.activemq.artemis.api.core.management.ResourceNames; import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; +import org.apache.activemq.artemis.core.server.impl.AddressInfo; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.ra.ActiveMQResourceAdapter; @@ -100,6 +105,66 @@ public class ResourceAdapterTest extends ActiveMQRATestBase { } + @Test + public void testQueuePrefixWhenUseJndiIsFalse() throws Exception { + final String prefix = "jms.queue."; + final String destinationName = "test"; + final SimpleString prefixedDestinationName = SimpleString.toSimpleString(prefix + destinationName); + server.createQueue(prefixedDestinationName, RoutingType.ANYCAST, prefixedDestinationName, null, false, false); + ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); + ra.setConnectorClassName(INVM_CONNECTOR_FACTORY); + ra.start(new BootstrapContext()); + Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection(); + conn.close(); + + ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); + spec.setResourceAdapter(ra); + spec.setUseJNDI(false); + spec.setDestinationType("javax.jms.Queue"); + spec.setDestination(destinationName); + spec.setQueuePrefix(prefix); + spec.setMaxSession(1); + spec.setSetupAttempts(1); + + ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec); + + activation.start(); + + assertEquals(1, server.locateQueue(prefixedDestinationName).getConsumerCount()); + + activation.stop(); + } + + @Test + public void testTopicPrefixWhenUseJndiIsFalse() throws Exception { + final String prefix = "jms.topic."; + final String destinationName = "test"; + final SimpleString prefixedDestinationName = SimpleString.toSimpleString(prefix + destinationName); + server.addAddressInfo(new AddressInfo(prefixedDestinationName).addRoutingType(RoutingType.MULTICAST)); + ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter(); + ra.setConnectorClassName(INVM_CONNECTOR_FACTORY); + ra.start(new BootstrapContext()); + Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection(); + conn.close(); + + ActiveMQActivationSpec spec = new ActiveMQActivationSpec(); + spec.setResourceAdapter(ra); + spec.setUseJNDI(false); + spec.setDestinationType("javax.jms.Topic"); + spec.setDestination(destinationName); + spec.setTopicPrefix(prefix); + spec.setMaxSession(1); + spec.setSetupAttempts(1); + + ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec); + + activation.start(); + + assertEquals(1, ((AddressControl)server.getManagementService().getResource(ResourceNames.ADDRESS + prefixedDestinationName)).getQueueNames().length); + + activation.stop(); + } + @Test public void testStartStop() throws Exception { ActiveMQResourceAdapter qResourceAdapter = new ActiveMQResourceAdapter();