Search in sources :

Example 16 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class DurableSubscriptionActivationTest method testActivateWithExistingTopic.

public void testActivateWithExistingTopic() throws Exception {
    // create durable subscription
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId");
    Destination d = broker.getDestination(topic);
    assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);
    // restart the broker
    restartBroker();
    d = broker.getDestination(topic);
    assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);
    // activate
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId");
    assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);
    // re-activate
    connection.close();
    connection = createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId");
    assertTrue("More than one consumer found: " + d.getConsumers().size(), d.getConsumers().size() == 1);
}
Also used : Destination(org.apache.activemq.broker.region.Destination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Session(javax.jms.Session)

Example 17 with Destination

use of org.apache.activemq.broker.region.Destination in project activemq-artemis by apache.

the class DurableUnsubscribeTest method testUnsubscribe.

public void testUnsubscribe() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId");
    session.close();
    Destination d = broker.getDestination(topic);
    assertEquals("Subscription is missing.", 1, d.getConsumers().size());
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(topic);
    for (int i = 0; i < 1000; i++) {
        producer.send(session.createTextMessage("text"));
    }
    Thread.sleep(1000);
    session.unsubscribe("SubsId");
    session.close();
    assertEquals("Subscription exists.", 0, d.getConsumers().size());
}
Also used : Destination(org.apache.activemq.broker.region.Destination) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 18 with Destination

use of org.apache.activemq.broker.region.Destination in project fabric8 by jboss-fuse.

the class LocalBrokerFacade method purgeQueue.

public void purgeQueue(ActiveMQDestination destination) throws Exception {
    Set destinations = getManagedBroker().getQueueRegion().getDestinations(destination);
    for (Iterator i = destinations.iterator(); i.hasNext(); ) {
        Destination dest = (Destination) i.next();
        if (dest instanceof Queue) {
            Queue regionQueue = (Queue) dest;
            regionQueue.purge();
        }
    }
}
Also used : Destination(org.apache.activemq.broker.region.Destination) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Set(java.util.Set) Iterator(java.util.Iterator) Queue(org.apache.activemq.broker.region.Queue)

Aggregations

Destination (org.apache.activemq.broker.region.Destination)18 MessageConsumer (javax.jms.MessageConsumer)6 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)6 TopicConnection (javax.jms.TopicConnection)5 TopicSession (javax.jms.TopicSession)5 TopicSubscriber (javax.jms.TopicSubscriber)5 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)5 Session (javax.jms.Session)4 MessageProducer (javax.jms.MessageProducer)3 TestSupport.getDestination (org.apache.activemq.TestSupport.getDestination)3 RegionBroker (org.apache.activemq.broker.region.RegionBroker)3 Subscription (org.apache.activemq.broker.region.Subscription)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3 MessageIdList (org.apache.activemq.util.MessageIdList)3 ObjectName (javax.management.ObjectName)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BytesMessage (javax.jms.BytesMessage)1