ARTEMIS-2020 Use prefixes when useJNDI=false in RA

This commit is contained in:
Justin Bertram 2018-08-09 11:20:46 -05:00 committed by Clebert Suconic
parent 6bdfcd04f5
commit 1171f01b30
2 changed files with 67 additions and 2 deletions

View File

@ -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());
}
}
}

View File

@ -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();