Search in sources :

Example 61 with BrokerService

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

the class ThreeBrokerQueueNetworkTest method testNoDuplicateQueueSubs.

public void testNoDuplicateQueueSubs() throws Exception {
    bridgeAllBrokers("default", 3, true);
    startAllBrokers();
    waitForBridgeFormation();
    // Setup destination
    Destination dest = createDestination("TEST.FOO", false);
    // Setup consumers
    String brokerName = "BrokerA";
    MessageConsumer consumer = createConsumer(brokerName, dest);
    // wait for advisories
    Thread.sleep(2000);
    // verify there is one consumer on each broker, no cycles
    Collection<BrokerItem> brokerList = brokers.values();
    for (Iterator<BrokerItem> i = brokerList.iterator(); i.hasNext(); ) {
        BrokerService broker = i.next().broker;
        verifyConsumerCount(broker, 1, dest);
    }
    consumer.close();
    // wait for advisories
    Thread.sleep(2000);
    // verify there is no more consumers
    for (Iterator<BrokerItem> i = brokerList.iterator(); i.hasNext(); ) {
        BrokerService broker = i.next().broker;
        verifyConsumerCount(broker, 0, dest);
    }
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) BrokerService(org.apache.activemq.broker.BrokerService)

Example 62 with BrokerService

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

the class ThreeBrokerQueueNetworkTest method testNoDuplicateQueueSubsHasLowestPriority.

public void testNoDuplicateQueueSubsHasLowestPriority() throws Exception {
    boolean suppressQueueDuplicateSubscriptions = true;
    boolean decreaseNetworkConsumerPriority = true;
    bridgeAllBrokers("default", 3, suppressQueueDuplicateSubscriptions, decreaseNetworkConsumerPriority);
    // Setup destination
    final Destination dest = createDestination("TEST.FOO", false);
    // delay the advisory messages so that one can percolate fully (cyclically) before the other
    BrokerItem brokerB = brokers.get("BrokerA");
    brokerB.broker.setPlugins(new BrokerPlugin[] { new BrokerPlugin() {

        @Override
        public Broker installPlugin(Broker broker) throws Exception {
            return new BrokerFilter(broker) {

                final AtomicInteger count = new AtomicInteger();

                @Override
                public void preProcessDispatch(MessageDispatch messageDispatch) {
                    if (messageDispatch.getDestination().getPhysicalName().contains("ActiveMQ.Advisory.Consumer")) {
                        // lets delay the first advisory
                        if (count.getAndIncrement() == 0) {
                            LOG.info("Sleeping on first advisory: " + messageDispatch);
                            try {
                                Thread.sleep(2000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                    super.postProcessDispatch(messageDispatch);
                }
            };
        }
    } });
    startAllBrokers();
    waitForBridgeFormation();
    // Setup consumers
    String brokerName = "BrokerA";
    createConsumer(brokerName, dest);
    // wait for advisories
    Thread.sleep(5000);
    // verify there is one consumer on each broker, no cycles
    Collection<BrokerItem> brokerList = brokers.values();
    for (Iterator<BrokerItem> i = brokerList.iterator(); i.hasNext(); ) {
        BrokerService broker = i.next().broker;
        verifyConsumerCount(broker, 1, dest);
        if (!brokerName.equals(broker.getBrokerName())) {
            verifyConsumePriority(broker, ConsumerInfo.NETWORK_CONSUMER_PRIORITY, dest);
        }
    }
}
Also used : ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) Destination(javax.jms.Destination) Broker(org.apache.activemq.broker.Broker) RegionBroker(org.apache.activemq.broker.region.RegionBroker) BrokerPlugin(org.apache.activemq.broker.BrokerPlugin) BrokerFilter(org.apache.activemq.broker.BrokerFilter) MessageDispatch(org.apache.activemq.command.MessageDispatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BrokerService(org.apache.activemq.broker.BrokerService)

Example 63 with BrokerService

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

the class ThreeBrokerStompTemporaryQueueTest method testStompTemporaryQueue.

public void testStompTemporaryQueue() throws Exception {
    // Setup broker networks
    bridgeAndConfigureBrokers("BrokerA", "BrokerB");
    bridgeAndConfigureBrokers("BrokerA", "BrokerC");
    bridgeAndConfigureBrokers("BrokerB", "BrokerA");
    bridgeAndConfigureBrokers("BrokerB", "BrokerC");
    bridgeAndConfigureBrokers("BrokerC", "BrokerA");
    bridgeAndConfigureBrokers("BrokerC", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();
    Thread.sleep(1000);
    stompConnection = new StompConnection();
    stompConnection.open("localhost", 61614);
    // Creating a temp queue
    stompConnection.sendFrame("CONNECT\n" + "login:system\n" + "passcode:manager\n\n" + Stomp.NULL);
    StompFrame frame = stompConnection.receive();
    assertTrue(frame.toString().startsWith("CONNECTED"));
    stompConnection.subscribe("/temp-queue/meaningless", "auto");
    stompConnection.send("/temp-queue/meaningless", "Hello World");
    frame = stompConnection.receive(3000);
    assertEquals("Hello World", frame.getBody());
    Thread.sleep(1000);
    assertEquals("Destination", 1, brokers.get("BrokerA").broker.getAdminView().getTemporaryQueues().length);
    assertEquals("Destination", 1, brokers.get("BrokerB").broker.getAdminView().getTemporaryQueues().length);
    assertEquals("Destination", 1, brokers.get("BrokerC").broker.getAdminView().getTemporaryQueues().length);
    int advisoryTopicsForTempQueues;
    advisoryTopicsForTempQueues = countTopicsByName("BrokerA", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should be present", 1, advisoryTopicsForTempQueues);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerB", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should be present", 1, advisoryTopicsForTempQueues);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should be present", 1, advisoryTopicsForTempQueues);
    stompConnection.disconnect();
    Thread.sleep(1000);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerA", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerB", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
    LOG.info("Restarting brokerA");
    BrokerItem brokerItem = brokers.remove("BrokerA");
    if (brokerItem != null) {
        brokerItem.destroy();
    }
    BrokerService restartedBroker = createAndConfigureBroker(new URI("broker:(tcp://localhost:61616,stomp://localhost:61613)/BrokerA"));
    bridgeAndConfigureBrokers("BrokerA", "BrokerB");
    bridgeAndConfigureBrokers("BrokerA", "BrokerC");
    restartedBroker.start();
    waitForBridgeFormation();
    Thread.sleep(3000);
    assertEquals("Destination", 0, brokers.get("BrokerA").broker.getAdminView().getTemporaryQueues().length);
    assertEquals("Destination", 0, brokers.get("BrokerB").broker.getAdminView().getTemporaryQueues().length);
    assertEquals("Destination", 0, brokers.get("BrokerC").broker.getAdminView().getTemporaryQueues().length);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerA", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerB", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
    advisoryTopicsForTempQueues = countTopicsByName("BrokerC", "ActiveMQ.Advisory.Consumer.Queue.ID");
    assertEquals("Advisory topic should have been deleted", 0, advisoryTopicsForTempQueues);
}
Also used : StompConnection(org.apache.activemq.transport.stomp.StompConnection) StompFrame(org.apache.activemq.transport.stomp.StompFrame) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 64 with BrokerService

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

the class ThreeBrokerStompTemporaryQueueTest method createAndConfigureBroker.

private BrokerService createAndConfigureBroker(URI uri) throws Exception {
    BrokerService broker = createBroker(uri);
    configurePersistenceAdapter(broker);
    return broker;
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService)

Example 65 with BrokerService

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

the class QueueMemoryFullMultiBrokersTest method setUp.

@Override
public void setUp() throws Exception {
    super.setAutoFail(true);
    super.setUp();
    messageSize = 1024;
    // Setup n brokers
    for (int i = 1; i <= BROKER_COUNT; i++) {
        createBroker(new URI("broker:()/Broker" + i + "?persistent=false&useJmx=false"));
    }
    BrokerService broker2 = brokers.get("Broker2").broker;
    applyMemoryLimitPolicy(broker2);
}
Also used : URI(java.net.URI) BrokerService(org.apache.activemq.broker.BrokerService)

Aggregations

BrokerService (org.apache.activemq.broker.BrokerService)349 URI (java.net.URI)53 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)45 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)45 Test (org.junit.Test)43 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)32 TransportConnector (org.apache.activemq.broker.TransportConnector)31 Before (org.junit.Before)22 File (java.io.File)20 MemoryPersistenceAdapter (org.apache.activemq.store.memory.MemoryPersistenceAdapter)17 JMSException (javax.jms.JMSException)16 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)14 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)14 BrokerFactoryBean (org.apache.activemq.xbean.BrokerFactoryBean)14 NetworkConnector (org.apache.activemq.network.NetworkConnector)13 MessageConsumer (javax.jms.MessageConsumer)12 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)12 ArrayList (java.util.ArrayList)11 Destination (javax.jms.Destination)11 ClassPathResource (org.springframework.core.io.ClassPathResource)10