Search in sources :

Example 6 with LocalQueueBinding

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

the class PostOfficeJournalLoader method initQueues.

@Override
public void initQueues(Map<Long, QueueBindingInfo> queueBindingInfosMap, List<QueueBindingInfo> queueBindingInfos) throws Exception {
    int duplicateID = 0;
    for (final QueueBindingInfo queueBindingInfo : queueBindingInfos) {
        queueBindingInfosMap.put(queueBindingInfo.getId(), queueBindingInfo);
        final Filter filter = FilterImpl.createFilter(queueBindingInfo.getFilterString());
        final boolean isTopicIdentification = FilterUtils.isTopicIdentification(filter);
        if (postOffice.getBinding(queueBindingInfo.getQueueName()) != null) {
            if (isTopicIdentification) {
                final long tx = storageManager.generateID();
                storageManager.deleteQueueBinding(tx, queueBindingInfo.getId());
                storageManager.commitBindings(tx);
                continue;
            } else {
                final SimpleString newName = queueBindingInfo.getQueueName().concat("-" + (duplicateID++));
                ActiveMQServerLogger.LOGGER.queueDuplicatedRenaming(queueBindingInfo.getQueueName().toString(), newName.toString());
                queueBindingInfo.replaceQueueName(newName);
            }
        }
        final QueueConfig.Builder queueConfigBuilder;
        if (queueBindingInfo.getAddress() == null) {
            queueConfigBuilder = QueueConfig.builderWith(queueBindingInfo.getId(), queueBindingInfo.getQueueName());
        } else {
            queueConfigBuilder = QueueConfig.builderWith(queueBindingInfo.getId(), queueBindingInfo.getQueueName(), queueBindingInfo.getAddress());
        }
        queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(queueBindingInfo.getUser()).durable(true).temporary(false).autoCreated(queueBindingInfo.isAutoCreated()).purgeOnNoConsumers(queueBindingInfo.isPurgeOnNoConsumers()).maxConsumers(queueBindingInfo.getMaxConsumers()).exclusive(queueBindingInfo.isExclusive()).lastValue(queueBindingInfo.isLastValue()).routingType(RoutingType.getType(queueBindingInfo.getRoutingType()));
        final Queue queue = queueFactory.createQueueWith(queueConfigBuilder.build());
        queue.setConsumersRefCount(new QueueManagerImpl(((PostOfficeImpl) postOffice).getServer(), queueBindingInfo.getQueueName()));
        if (queueBindingInfo.getQueueStatusEncodings() != null) {
            for (QueueStatusEncoding encoding : queueBindingInfo.getQueueStatusEncodings()) {
                if (encoding.getStatus() == QueueStatus.PAUSED)
                    queue.reloadPause(encoding.getId());
            }
        }
        final Binding binding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
        queues.put(queue.getID(), queue);
        postOffice.addBinding(binding);
        managementService.registerQueue(queue, queue.getAddress(), storageManager);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) GroupBinding(org.apache.activemq.artemis.core.server.group.impl.GroupBinding) QueueConfig(org.apache.activemq.artemis.core.server.QueueConfig) QueueStatusEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.QueueStatusEncoding) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Filter(org.apache.activemq.artemis.core.filter.Filter) Queue(org.apache.activemq.artemis.core.server.Queue) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)

Example 7 with LocalQueueBinding

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

the class ScaleDownHandler method scaleDownMessages.

public long scaleDownMessages(ClientSessionFactory sessionFactory, SimpleString nodeId, String user, String password) throws Exception {
    long messageCount = 0;
    targetNodeId = nodeId != null ? nodeId.toString() : getTargetNodeId(sessionFactory);
    try (ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, 0)) {
        ClientProducer producer = session.createProducer();
        // perform a loop per address
        for (SimpleString address : postOffice.getAddresses()) {
            logger.debug("Scaling down address " + address);
            Bindings bindings = postOffice.getBindingsForAddress(address);
            // It will get a list of queues on this address, ordered by the number of messages
            Set<Queue> queues = new TreeSet<>(new OrderQueueByNumberOfReferencesComparator());
            for (Binding binding : bindings.getBindings()) {
                if (binding instanceof LocalQueueBinding) {
                    Queue queue = ((LocalQueueBinding) binding).getQueue();
                    // as part of scale down we will cancel any scheduled message and pass it to theWhile we scan for the queues we will also cancel any scheduled messages and deliver them right away
                    queue.deliverScheduledMessages();
                    queues.add(queue);
                }
            }
            String sfPrefix = ((PostOfficeImpl) postOffice).getServer().getInternalNamingPrefix() + "sf.";
            if (address.toString().startsWith(sfPrefix)) {
                messageCount += scaleDownSNF(address, queues, producer);
            } else {
                messageCount += scaleDownRegularMessages(address, queues, session, producer);
            }
        }
    }
    return messageCount;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) TreeSet(java.util.TreeSet) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) PostOfficeImpl(org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)

Example 8 with LocalQueueBinding

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

the class SimpleOpenWireTest method checkQueueEmpty.

private void checkQueueEmpty(String qName) {
    PostOffice po = server.getPostOffice();
    LocalQueueBinding binding = (LocalQueueBinding) po.getBinding(SimpleString.toSimpleString(qName));
    try {
        // waiting for last ack to finish
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    assertEquals(0L, binding.getQueue().getMessageCount());
}
Also used : LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)

Example 9 with LocalQueueBinding

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

the class QueueControlTest method testRetryMultipleMessages.

/**
 * Test retry multiple messages from  DLQ to original queue.
 */
@Test
public void testRetryMultipleMessages() throws Exception {
    final SimpleString dla = new SimpleString("DLA");
    final SimpleString qName = new SimpleString("q1");
    final SimpleString adName = new SimpleString("ad1");
    final SimpleString dlq = new SimpleString("DLQ1");
    final String sampleText = "Put me on DLQ";
    final int numMessagesToTest = 10;
    AddressSettings addressSettings = new AddressSettings().setMaxDeliveryAttempts(1).setDeadLetterAddress(dla);
    server.getAddressSettingsRepository().addMatch(adName.toString(), addressSettings);
    session.createQueue(dla, RoutingType.MULTICAST, dlq, null, durable);
    session.createQueue(adName, RoutingType.MULTICAST, qName, null, durable);
    // Send message to queue.
    ClientProducer producer = session.createProducer(adName);
    for (int i = 0; i < numMessagesToTest; i++) {
        producer.send(createTextMessage(session, sampleText));
    }
    session.start();
    final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(qName);
    Queue q = binding.getQueue();
    final LocalQueueBinding binding2 = (LocalQueueBinding) server.getPostOffice().getBinding(dlq);
    Queue q2 = binding2.getQueue();
    Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
    queueMemorySizeField.setAccessible(true);
    // Get memory size counters to verify
    AtomicInteger queueMemorySize1 = (AtomicInteger) queueMemorySizeField.get(q);
    AtomicInteger queueMemorySize2 = (AtomicInteger) queueMemorySizeField.get(q2);
    // Verify that original queue has a memory size greater than 0 and DLQ is 0
    assertTrue(queueMemorySize1.get() > 0);
    assertTrue(queueMemorySize2.get() == 0);
    // Read and rollback all messages to DLQ
    ClientConsumer clientConsumer = session.createConsumer(qName);
    for (int i = 0; i < numMessagesToTest; i++) {
        ClientMessage clientMessage = clientConsumer.receive(500);
        clientMessage.acknowledge();
        Assert.assertNotNull(clientMessage);
        Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
        session.rollback();
    }
    Assert.assertNull(clientConsumer.receiveImmediate());
    // Verify that original queue has a memory size of 0 and DLQ is greater than 0 after rollback
    assertTrue(queueMemorySize1.get() == 0);
    assertTrue(queueMemorySize2.get() > 0);
    QueueControl dlqQueueControl = createManagementControl(dla, dlq);
    assertMessageMetrics(dlqQueueControl, numMessagesToTest, durable);
    // Retry all messages - i.e. they should go from DLQ to original Queue.
    Assert.assertEquals(numMessagesToTest, dlqQueueControl.retryMessages());
    // Assert DLQ is empty...
    assertMessageMetrics(dlqQueueControl, 0, durable);
    // Verify that original queue has a memory size of greater than 0 and DLQ is 0 after move
    assertTrue(queueMemorySize1.get() > 0);
    assertTrue(queueMemorySize2.get() == 0);
    // .. and that the messages is now on the original queue once more.
    for (int i = 0; i < numMessagesToTest; i++) {
        ClientMessage clientMessage = clientConsumer.receive(500);
        clientMessage.acknowledge();
        Assert.assertNotNull(clientMessage);
        Assert.assertEquals(clientMessage.getBodyBuffer().readString(), sampleText);
    }
    clientConsumer.close();
    // Verify that original queue and DLQ have a memory size of 0
    assertTrue(queueMemorySize1.get() == 0);
    assertTrue(queueMemorySize2.get() == 0);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Field(java.lang.reflect.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 10 with LocalQueueBinding

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

the class ClusterTestBase method waitForBindings.

protected void waitForBindings(final int node, final String address, final int expectedBindingCount, final int expectedConsumerCount, final boolean local) throws Exception {
    log.debug("waiting for bindings on node " + node + " address " + address + " expectedBindingCount " + expectedBindingCount + " consumerCount " + expectedConsumerCount + " local " + local);
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalArgumentException("No server at " + node);
    }
    long timeout = ActiveMQTestBase.WAIT_TIMEOUT;
    if (waitForBindings(server, address, local, expectedBindingCount, expectedConsumerCount, timeout)) {
        return;
    }
    PostOffice po = server.getPostOffice();
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    System.out.println("=======================================================================");
    System.out.println("Binding information for address = " + address + " on node " + node);
    for (Binding binding : bindings.getBindings()) {
        if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
            QueueBinding qBinding = (QueueBinding) binding;
            System.out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
        }
    }
    StringWriter writer = new StringWriter();
    PrintWriter out = new PrintWriter(writer);
    try {
        for (ActiveMQServer activeMQServer : servers) {
            if (activeMQServer != null) {
                out.println(clusterDescription(activeMQServer));
                out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
            }
        }
        for (ActiveMQServer activeMQServer : servers) {
            out.println("Management bindings on " + activeMQServer);
            if (activeMQServer != null) {
                out.println(debugBindings(activeMQServer, activeMQServer.getConfiguration().getManagementNotificationAddress().toString()));
            }
        }
    } catch (Throwable dontCare) {
    }
    logAndSystemOut(writer.toString());
    throw new IllegalStateException("Didn't get the expected number of bindings, look at the logging for more information");
}
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) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) StringWriter(java.io.StringWriter) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PrintWriter(java.io.PrintWriter)

Aggregations

LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)31 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)22 Binding (org.apache.activemq.artemis.core.postoffice.Binding)19 Test (org.junit.Test)18 Queue (org.apache.activemq.artemis.core.server.Queue)14 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)8 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)8 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 PostOfficeImpl (org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl)4 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3