Search in sources :

Example 31 with Bindings

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

the class AddressControlImpl method getNumberOfMessages.

@Override
public long getNumberOfMessages() throws Exception {
    clearIO();
    long totalMsgs = 0;
    try {
        Bindings bindings = postOffice.getBindingsForAddress(addressInfo.getName());
        for (Binding binding : bindings.getBindings()) {
            if (binding instanceof QueueBinding) {
                totalMsgs += ((QueueBinding) binding).getQueue().getMessageCount();
            }
        }
        return totalMsgs;
    } catch (Throwable t) {
        throw new IllegalStateException(t.getMessage());
    } finally {
        blockOnIO();
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 32 with Bindings

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

the class PredefinedQueueTest method testDeploySameNames.

@Test
public void testDeploySameNames() throws Exception {
    final String testAddress = "testAddress";
    final String queueName1 = "queue1";
    final String queueName2 = "queue2";
    CoreQueueConfiguration queue1 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName1);
    CoreQueueConfiguration queue2 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName2);
    configuration.addQueueConfiguration(queue1).addQueueConfiguration(queue2);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(configuration, false));
    server.start();
    Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(testAddress));
    Assert.assertEquals(2, bindings.getBindings().size());
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, true, true));
    session.start();
    ClientProducer producer = addClientProducer(session.createProducer(new SimpleString(testAddress)));
    ClientConsumer consumer1 = addClientConsumer(session.createConsumer(queueName1));
    ClientConsumer consumer2 = addClientConsumer(session.createConsumer(queueName2));
    final int numMessages = 10;
    final SimpleString propKey = new SimpleString("testkey");
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(false);
        message.putIntProperty(propKey, i);
        producer.send(message);
    }
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = consumer1.receive(200);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
        message = consumer2.receive(200);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getObjectProperty(propKey));
        message.acknowledge();
    }
    Assert.assertNull(consumer1.receiveImmediate());
    Assert.assertNull(consumer2.receiveImmediate());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 33 with Bindings

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

the class QueueImpl method expire.

private void expire(final Transaction tx, final MessageReference ref) throws Exception {
    SimpleString expiryAddress = addressSettingsRepository.getMatch(address.toString()).getExpiryAddress();
    if (expiryAddress != null) {
        Bindings bindingList = postOffice.getBindingsForAddress(expiryAddress);
        if (bindingList.getBindings().isEmpty()) {
            ActiveMQServerLogger.LOGGER.errorExpiringReferencesNoBindings(expiryAddress);
            acknowledge(tx, ref, AckReason.EXPIRED);
        } else {
            move(expiryAddress, tx, ref, true, true);
        }
    } else {
        if (!printErrorExpiring) {
            printErrorExpiring = true;
            // print this only once
            ActiveMQServerLogger.LOGGER.errorExpiringReferencesNoQueue(name);
        }
        acknowledge(tx, ref, AckReason.EXPIRED);
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 34 with Bindings

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

the class FQQNOpenWireTest method testTopic.

@Test
public // however we can test query functionality
void testTopic() throws Exception {
    Connection connection = factory.createConnection();
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(multicastAddress.toString());
        MessageConsumer consumer1 = session.createConsumer(topic);
        MessageConsumer consumer2 = session.createConsumer(topic);
        MessageConsumer consumer3 = session.createConsumer(topic);
        MessageProducer producer = session.createProducer(topic);
        producer.send(session.createMessage());
        // each consumer receives one
        Message m = consumer1.receive(2000);
        assertNotNull(m);
        m = consumer2.receive(2000);
        assertNotNull(m);
        m = consumer3.receive(2000);
        assertNotNull(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) TextMessage(javax.jms.TextMessage) 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 35 with Bindings

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

the class PagingOrderTest method testPageCounter.

@Test
public void testPageCounter() throws Throwable {
    boolean persistentMessages = true;
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    ActiveMQServer server = createServer(true, config, PAGE_SIZE, PAGE_MAX, new HashMap<String, AddressSettings>());
    server.start();
    final int messageSize = 1024;
    final int numberOfMessages = 500;
    ServerLocator locator = createInVMNonHALocator().setClientFailureCheckPeriod(1000).setConnectionTTL(2000).setReconnectAttempts(0).setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true).setConsumerWindowSize(1024 * 1024);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, false, false);
    server.addAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST));
    Queue q1 = server.createQueue(ADDRESS, RoutingType.MULTICAST, ADDRESS, null, true, false);
    Queue q2 = server.createQueue(ADDRESS, RoutingType.MULTICAST, new SimpleString("inactive"), null, true, false);
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    byte[] body = new byte[messageSize];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= messageSize; j++) {
        bb.put(getSamplebyte(j));
    }
    final AtomicInteger errors = new AtomicInteger(0);
    Thread t1 = new Thread() {

        @Override
        public void run() {
            try {
                ServerLocator sl = createInVMNonHALocator();
                ClientSessionFactory sf = sl.createSessionFactory();
                ClientSession sess = sf.createSession(true, true, 0);
                sess.start();
                ClientConsumer cons = sess.createConsumer(ADDRESS);
                for (int i = 0; i < numberOfMessages; i++) {
                    ClientMessage msg = cons.receive(5000);
                    assertNotNull(msg);
                    assertEquals(i, msg.getIntProperty("id").intValue());
                    msg.acknowledge();
                }
                assertNull(cons.receiveImmediate());
                sess.close();
                sl.close();
            } catch (Throwable e) {
                e.printStackTrace();
                errors.incrementAndGet();
            }
        }
    };
    t1.start();
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(persistentMessages);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty(new SimpleString("id"), i);
        producer.send(message);
        if (i % 20 == 0) {
            session.commit();
        }
    }
    session.commit();
    t1.join();
    assertEquals(0, errors.get());
    assertEquals(numberOfMessages, getMessageCount(q2));
    assertEquals(numberOfMessages, getMessagesAdded(q2));
    assertEquals(0, getMessageCount(q1));
    assertEquals(numberOfMessages, getMessagesAdded(q1));
    session.close();
    sf.close();
    locator.close();
    server.stop();
    server.start();
    Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);
    q1 = null;
    q2 = null;
    for (Binding bind : bindings.getBindings()) {
        if (bind instanceof LocalQueueBinding) {
            LocalQueueBinding qb = (LocalQueueBinding) bind;
            if (qb.getQueue().getName().equals(ADDRESS)) {
                q1 = qb.getQueue();
            }
            if (qb.getQueue().getName().equals(new SimpleString("inactive"))) {
                q2 = qb.getQueue();
            }
        }
    }
    assertNotNull(q1);
    assertNotNull(q2);
    assertEquals("q2 msg count", numberOfMessages, getMessageCount(q2));
    assertEquals("q2 msgs added", numberOfMessages, getMessagesAdded(q2));
    assertEquals("q1 msg count", 0, getMessageCount(q1));
    // 0, since nothing was sent to the queue after the server was restarted
    assertEquals("q1 msgs added", 0, getMessagesAdded(q1));
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

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