Search in sources :

Example 11 with Destination

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

the class DurableUnsubscribeTest method testDestroy.

public void testDestroy() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId2");
    session.close();
    connection.close();
    connection = null;
    Thread.sleep(1000);
    Destination d = broker.getDestination(topic);
    assertEquals("Subscription is missing.", 1, d.getConsumers().size());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName[] subNames = broker.getAdminView().getInactiveDurableTopicSubscribers();
    mbs.invoke(subNames[0], "destroy", new Object[0], new String[0]);
    assertEquals("Subscription exists.", 0, d.getConsumers().size());
}
Also used : Destination(org.apache.activemq.broker.region.Destination) Session(javax.jms.Session) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 12 with Destination

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

the class MemoryLimitTest method testCursorBatch.

@Test(timeout = 120000)
public void testCursorBatch() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?jms.prefetchPolicy.all=10");
    factory.setOptimizeAcknowledge(true);
    Connection conn = factory.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = sess.createQueue("STORE");
    final ProducerThread producer = new ProducerThread(sess, queue) {

        @Override
        protected Message createMessage(int i) throws Exception {
            BytesMessage bytesMessage = sess.createBytesMessage();
            bytesMessage.writeBytes(payload);
            return bytesMessage;
        }
    };
    producer.setMessageCount(2000);
    producer.start();
    producer.join();
    Thread.sleep(1000);
    // assert we didn't break high watermark (70%) usage
    final Destination dest = broker.getDestination((ActiveMQQueue) queue);
    LOG.info("Destination usage: " + dest.getMemoryUsage());
    int percentUsage = dest.getMemoryUsage().getPercentUsage();
    assertTrue("Should be less than 70% of limit but was: " + percentUsage, percentUsage <= 71);
    LOG.info("Broker usage: " + broker.getSystemUsage().getMemoryUsage());
    assertTrue(broker.getSystemUsage().getMemoryUsage().getPercentUsage() <= 71);
    // consume one message
    MessageConsumer consumer = sess.createConsumer(queue);
    Message msg = consumer.receive(5000);
    msg.acknowledge();
    // this should free some space and allow us to get new batch of messages in the memory
    // exceeding the limit
    assertTrue("Limit is exceeded", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("Destination usage: " + dest.getMemoryUsage());
            return dest.getMemoryUsage().getPercentUsage() >= 200;
        }
    }));
    LOG.info("Broker usage: " + broker.getSystemUsage().getMemoryUsage());
    assertTrue(broker.getSystemUsage().getMemoryUsage().getPercentUsage() >= 200);
    // let's make sure we can consume all messages
    for (int i = 1; i < 2000; i++) {
        msg = consumer.receive(5000);
        if (msg == null) {
            dumpAllThreads("NoMessage");
        }
        assertNotNull("Didn't receive message " + i, msg);
        msg.acknowledge();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(org.apache.activemq.broker.region.Destination) MessageConsumer(javax.jms.MessageConsumer) ProducerThread(org.apache.activemq.util.ProducerThread) Message(javax.jms.Message) BytesMessage(javax.jms.BytesMessage) Connection(javax.jms.Connection) BytesMessage(javax.jms.BytesMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 13 with Destination

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

the class ActiveMqMessagingService method removeQueue.

@Override
public void removeQueue(String queueName) {
    try {
        ActiveMQQueue destination = new ActiveMQQueue(queueName);
        ConnectionContext connectionContext = BrokerSupport.getConnectionContext(broker.getBroker());
        Destination brokerDestination = broker.getDestination(destination);
        List<Subscription> consumers = brokerDestination.getConsumers();
        for (Subscription consumer : consumers) {
            consumer.remove(connectionContext, brokerDestination);
            brokerDestination.removeSubscription(connectionContext, consumer, 0);
        }
        broker.getBroker().removeDestination(connectionContext, destination, 1000);
        broker.removeDestination(destination);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : Destination(org.apache.activemq.broker.region.Destination) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Subscription(org.apache.activemq.broker.region.Subscription)

Example 14 with Destination

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

the class NetworkRemovesSubscriptionsTest method testWithoutSessionAndSubsciberClose.

public void testWithoutSessionAndSubsciberClose() throws Exception {
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();
    for (int i = 0; i < 100; i++) {
        TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
        assertNotNull(subscriber);
    }
    connection.close();
    Thread.sleep(1000);
    Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
    assertNotNull(dest);
    assertTrue(dest.getConsumers().isEmpty());
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) Destination(org.apache.activemq.broker.region.Destination) TopicSession(javax.jms.TopicSession) TopicConnection(javax.jms.TopicConnection)

Example 15 with Destination

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

the class NetworkRemovesSubscriptionsTest method testWithoutSessionAndSubsciberClosePlayAround.

/**
 * Running this test you can produce a leak of only 2 ConsumerInfo on BE
 * broker, NOT 200 as in other cases!
 */
public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception {
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();
    for (int i = 0; i < 100; i++) {
        TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
        DummyMessageListener listener = new DummyMessageListener();
        subscriber.setMessageListener(listener);
        if (i != 50) {
            subscriber.close();
            subscriberSession.close();
        }
    }
    connection.close();
    Thread.sleep(1000);
    Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
    assertNotNull(dest);
    assertTrue(dest.getConsumers().isEmpty());
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) Destination(org.apache.activemq.broker.region.Destination) TopicSession(javax.jms.TopicSession) TopicConnection(javax.jms.TopicConnection)

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