Search in sources :

Example 21 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class ConfigurationTest method testStartWithDuplicateQueues.

@Test
public void testStartWithDuplicateQueues() throws Exception {
    ActiveMQServer server = getActiveMQServer("duplicate-queues.xml");
    try {
        server.start();
        Bindings mytopic_1 = server.getPostOffice().getBindingsForAddress(new SimpleString("mytopic_1"));
        assertEquals(mytopic_1.getBindings().size(), 0);
        Bindings mytopic_2 = server.getPostOffice().getBindingsForAddress(new SimpleString("mytopic_2"));
        assertEquals(mytopic_2.getBindings().size(), 3);
    } finally {
        try {
            server.stop();
        } catch (Exception e) {
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Test(org.junit.Test)

Example 22 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class ActiveMQTestBase method printBindings.

public void printBindings(ActiveMQServer server, String address) throws Exception {
    PostOffice po = server.getPostOffice();
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    System.err.println("=======================================================================");
    System.err.println("Binding information for address = " + address + " for server " + server);
    for (Binding binding : bindings.getBindings()) {
        QueueBinding qBinding = (QueueBinding) binding;
        System.err.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 23 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class AmqpFullyQualifiedNameTest method testTopic.

@Test(timeout = 60000)
public // however we can test query functionality
void testTopic() throws Exception {
    SimpleString queueName = new SimpleString("someAddress");
    server.createQueue(multicastAddress, RoutingType.MULTICAST, queueName, null, false, false);
    Connection connection = createConnection(false);
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic fqqn = session.createTopic(multicastAddress.toString() + "::" + queueName);
        MessageConsumer consumer1 = session.createConsumer(fqqn);
        MessageConsumer consumer2 = session.createConsumer(fqqn);
        Topic topic = session.createTopic(multicastAddress.toString());
        MessageProducer producer = session.createProducer(topic);
        producer.send(session.createMessage());
        // each consumer receives one
        Message m = consumer1.receive(2000);
        assertNotNull(m);
        // Subscribing to FQQN is akin to shared subscription
        m = consumer2.receive(2000);
        assertNull(m);
        Bindings bindings = server.getPostOffice().getBindingsForAddress(multicastAddress);
        for (Binding b : bindings.getBindings()) {
            System.out.println("checking binidng " + b.getUniqueName() + " " + ((LocalQueueBinding) b).getQueue().getDeliveringMessages());
            SimpleString qName = b.getUniqueName();
            // do FQQN query
            QueueQueryResult result = server.queueQuery(CompositeAddress.toFullQN(multicastAddress, qName));
            assertTrue(result.isExists());
            assertEquals(result.getName(), CompositeAddress.toFullQN(multicastAddress, qName));
            // do qname query
            result = server.queueQuery(qName);
            assertTrue(result.isExists());
            assertEquals(result.getName(), qName);
        }
    } finally {
        connection.close();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Topic(javax.jms.Topic) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 24 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class ActiveMQTestBase method waitForBindings.

/**
 * @param server                the server where's being checked
 * @param address               the name of the address being checked
 * @param local                 if true we are looking for local bindings, false we are looking for remoting servers
 * @param expectedBindingCount  the expected number of counts
 * @param expectedConsumerCount the expected number of consumers
 * @param timeout               the timeout used on the check
 * @return
 * @throws Exception
 * @throws InterruptedException
 */
protected boolean waitForBindings(final ActiveMQServer server, final String address, final boolean local, final int expectedBindingCount, final int expectedConsumerCount, long timeout) throws Exception {
    final PostOffice po = server.getPostOffice();
    long start = System.currentTimeMillis();
    int bindingCount = 0;
    int totConsumers = 0;
    do {
        bindingCount = 0;
        totConsumers = 0;
        Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
        for (Binding binding : bindings.getBindings()) {
            if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
                QueueBinding qBinding = (QueueBinding) binding;
                bindingCount++;
                totConsumers += qBinding.consumerCount();
            }
        }
        if (bindingCount == expectedBindingCount && totConsumers == expectedConsumerCount) {
            return true;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < timeout);
    String msg = "Timed out waiting for bindings (bindingCount = " + bindingCount + " (expecting " + expectedBindingCount + ") " + ", totConsumers = " + totConsumers + " (expecting " + expectedConsumerCount + ")" + ")";
    log.error(msg);
    return false;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

Example 25 with Bindings

use of org.apache.activemq.artemis.core.postoffice.Bindings in project activemq-artemis by apache.

the class ActiveMQTestBase method getLocalQueueBindings.

private List<QueueBinding> getLocalQueueBindings(final PostOffice postOffice, final String address) throws Exception {
    ArrayList<QueueBinding> bindingsFound = new ArrayList<>();
    Bindings bindings = postOffice.getBindingsForAddress(new SimpleString(address));
    for (Binding binding : bindings.getBindings()) {
        if (binding instanceof LocalQueueBinding) {
            bindingsFound.add((QueueBinding) binding);
        }
    }
    return bindingsFound;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Aggregations

Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)35 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)24 Binding (org.apache.activemq.artemis.core.postoffice.Binding)22 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)15 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)12 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7 Test (org.junit.Test)7 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Queue (org.apache.activemq.artemis.core.server.Queue)6 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)6 ArrayList (java.util.ArrayList)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 Connection (javax.jms.Connection)4 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)4 Address (org.apache.activemq.artemis.core.postoffice.Address)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)4 IOException (java.io.IOException)3 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 MessageConsumer (javax.jms.MessageConsumer)3