Search in sources :

Example 11 with ActiveMQDestination

use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.

the class ActiveMQDestinationTest method testEquals.

// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testEquals() throws Exception {
    String destinationName = RandomUtil.randomString();
    String address = QUEUE_QUALIFIED_PREFIX + destinationName;
    ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
    ActiveMQDestination sameDestination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
    ActiveMQDestination differentDestination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address + RandomUtil.randomString());
    Assert.assertFalse(destination.equals(null));
    Assert.assertTrue(destination.equals(destination));
    Assert.assertTrue(destination.equals(sameDestination));
    Assert.assertFalse(destination.equals(differentDestination));
}
Also used : ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 12 with ActiveMQDestination

use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.

the class ReferenceableTest method testReferenceQueue.

@Test
public void testReferenceQueue() throws Exception {
    Reference queueRef = ((Referenceable) queue1).getReference();
    String factoryName = queueRef.getFactoryClassName();
    Class<?> factoryClass = Class.forName(factoryName);
    ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
    Object instance = factory.getObjectInstance(queueRef, null, null, null);
    ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
    ActiveMQQueue queue2 = (ActiveMQQueue) instance;
    ProxyAssertSupport.assertEquals(queue1.getQueueName(), queue2.getQueueName());
    simpleSendReceive(cf, queue2);
}
Also used : Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 13 with ActiveMQDestination

use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.

the class ReferenceableTest method testReferenceTopic.

@Test
public void testReferenceTopic() throws Exception {
    Reference topicRef = ((Referenceable) ActiveMQServerTestCase.topic1).getReference();
    String factoryName = topicRef.getFactoryClassName();
    Class factoryClass = Class.forName(factoryName);
    ObjectFactory factory = (ObjectFactory) factoryClass.newInstance();
    Object instance = factory.getObjectInstance(topicRef, null, null, null);
    ProxyAssertSupport.assertTrue(instance instanceof ActiveMQDestination);
    ActiveMQTopic topic2 = (ActiveMQTopic) instance;
    ProxyAssertSupport.assertEquals(ActiveMQServerTestCase.topic1.getTopicName(), topic2.getTopicName());
    simpleSendReceive(cf, topic2);
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) Referenceable(javax.naming.Referenceable) ObjectFactory(javax.naming.spi.ObjectFactory) Reference(javax.naming.Reference) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 14 with ActiveMQDestination

use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.

the class ResourceAdapterTest method testStartStopActivationManyTimes.

@Test
public void testStartStopActivationManyTimes() throws Exception {
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory factory = locator.createSessionFactory();
    ClientSession session = factory.createSession(false, false, false);
    ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
    session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
    session.close();
    ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
    ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
    ra.setUserName("userGlobal");
    ra.setPassword("passwordGlobal");
    ra.start(new BootstrapContext());
    Connection conn = ra.getDefaultActiveMQConnectionFactory().createConnection();
    conn.close();
    ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
    spec.setResourceAdapter(ra);
    spec.setUseJNDI(false);
    spec.setUser("user");
    spec.setPassword("password");
    spec.setDestinationType("javax.jms.Topic");
    spec.setDestination("test");
    spec.setMinSession(1);
    spec.setMaxSession(15);
    ActiveMQActivation activation = new ActiveMQActivation(ra, new MessageEndpointFactory(), spec);
    ServerLocatorImpl serverLocator = (ServerLocatorImpl) ra.getDefaultActiveMQConnectionFactory().getServerLocator();
    Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources();
    for (int i = 0; i < 10; i++) {
        System.out.println(i);
        activation.start();
        assertEquals(1, resources.size());
        activation.stop();
    }
    ra.stop();
    assertEquals(0, resources.size());
    locator.close();
}
Also used : MessageEndpointFactory(org.apache.activemq.artemis.tests.unit.ra.MessageEndpointFactory) ActiveMQActivation(org.apache.activemq.artemis.ra.inflow.ActiveMQActivation) Connection(javax.jms.Connection) XARecoveryConfig(org.apache.activemq.artemis.service.extensions.xa.recovery.XARecoveryConfig) BootstrapContext(org.apache.activemq.artemis.tests.unit.ra.BootstrapContext) MessageEndpoint(javax.resource.spi.endpoint.MessageEndpoint) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) ServerLocatorImpl(org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ActiveMQActivationSpec(org.apache.activemq.artemis.ra.inflow.ActiveMQActivationSpec) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 15 with ActiveMQDestination

use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.

the class EmbeddedJMSResource method getMessageCount.

/**
 * Get the number of messages in a specific JMS Destination.
 * <p>
 * The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue
 * or topic://myTopic.  If the destination type prefix is not included in the destination name, a prefix
 * of "queue://" is assumed.
 *
 * NOTE:  For JMS Topics, this returned count will be the total number of messages for all subscribers.  For
 * example, if there are two subscribers on the topic and a single message is published, the returned count will
 * be two (one message for each subscriber).
 *
 * @param destinationName the full name of the JMS Destination
 * @return the number of messages in the JMS Destination
 */
public long getMessageCount(String destinationName) {
    long count = 0;
    ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, ActiveMQDestination.TYPE.QUEUE);
    if (destination.isQueue()) {
        Queue queue = getDestinationQueue(destinationName);
        if (queue == null) {
            log.warn("getMessageCount(destinationName) - destination {} not found; returning -1", destinationName);
            count = -1;
        } else {
            count = queue.getMessageCount();
        }
    } else {
        for (Queue topicQueue : getTopicQueues(destinationName)) {
            count += topicQueue.getMessageCount();
        }
    }
    return count;
}
Also used : Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination)

Aggregations

ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)21 Test (org.junit.Test)14 Connection (javax.jms.Connection)6 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 Reference (javax.naming.Reference)4 MessageProducer (javax.jms.MessageProducer)3 Queue (javax.jms.Queue)3 TextMessage (javax.jms.TextMessage)3 Topic (javax.jms.Topic)3 ObjectFactory (javax.naming.spi.ObjectFactory)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 Queue (org.apache.activemq.artemis.core.server.Queue)3 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)3 Destination (javax.jms.Destination)2 JMSException (javax.jms.JMSException)2 Referenceable (javax.naming.Referenceable)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)2 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)2