Search in sources :

Example 1 with ActiveMQDestination

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

the class EmbeddedJMSResource method getTopicQueues.

/**
 * Get the Queues corresponding to a JMS Topic.
 * <p>
 * The full name of the JMS Topic including the prefix should be provided - i.e. topic://myTopic.  If the destination type prefix
 * is not included in the destination name, a prefix of "topic://" is assumed.
 *
 * @param topicName the full name of the JMS Destination
 * @return the number of messages in the JMS Destination
 */
public List<Queue> getTopicQueues(String topicName) {
    List<Queue> queues = new LinkedList<>();
    ActiveMQDestination destination = ActiveMQDestination.createDestination(topicName, ActiveMQDestination.TYPE.TOPIC);
    if (!destination.isQueue()) {
        BindingQueryResult bindingQueryResult = null;
        try {
            bindingQueryResult = jmsServer.getActiveMQServer().bindingQuery(destination.getSimpleAddress());
        } catch (Exception ex) {
            log.error(String.format("getTopicQueues( %s ) - bindingQuery for %s failed", topicName, destination.getAddress()), ex);
            return queues;
        }
        if (bindingQueryResult.isExists()) {
            ActiveMQServer activeMQServer = jmsServer.getActiveMQServer();
            for (SimpleString queueName : bindingQueryResult.getQueueNames()) {
                queues.add(activeMQServer.locateQueue(queueName));
            }
        }
    }
    return queues;
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) LinkedList(java.util.LinkedList) JMSException(javax.jms.JMSException) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination)

Example 2 with ActiveMQDestination

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

the class EmbeddedJMSResource method pushMessage.

public void pushMessage(String destinationName, Message message) {
    if (destinationName == null) {
        throw new IllegalArgumentException("sendMessage failure - destination name is required");
    } else if (message == null) {
        throw new IllegalArgumentException("sendMessage failure - a Message is required");
    }
    ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, ActiveMQDestination.TYPE.QUEUE);
    getInternalClient().pushMessage(destination, message);
}
Also used : ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination)

Example 3 with ActiveMQDestination

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

the class ActiveMQDestinationTest method testFromAddressWithQueueAddressPrefix.

@Test
public void testFromAddressWithQueueAddressPrefix() throws Exception {
    String destinationName = RandomUtil.randomString();
    String address = QUEUE_QUALIFIED_PREFIX + destinationName;
    ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
    Assert.assertTrue(destination instanceof Queue);
    Assert.assertEquals(destinationName, ((Queue) destination).getQueueName());
}
Also used : Queue(javax.jms.Queue) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 4 with ActiveMQDestination

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

the class ActiveMQDestinationTest method testFromAddressWithInvalidPrefix.

@Test
public void testFromAddressWithInvalidPrefix() throws Exception {
    String invalidPrefix = "junk";
    String destinationName = RandomUtil.randomString();
    String address = invalidPrefix + destinationName;
    ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
    Assert.assertTrue(destination instanceof Destination);
}
Also used : Destination(javax.jms.Destination) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

Example 5 with ActiveMQDestination

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

the class ActiveMQDestinationTest method testFromAddressWithTopicAddressPrefix.

@Test
public void testFromAddressWithTopicAddressPrefix() throws Exception {
    String destinationName = RandomUtil.randomString();
    String address = TOPIC_QUALIFIED_PREFIX + destinationName;
    ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address);
    Assert.assertTrue(destination instanceof Topic);
    Assert.assertEquals(destinationName, ((Topic) destination).getTopicName());
}
Also used : Topic(javax.jms.Topic) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Test(org.junit.Test)

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