Search in sources :

Example 31 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class XmlDataExporter method printBindingsAsXML.

private void printBindingsAsXML() throws XMLStreamException {
    xmlWriter.writeStartElement(XmlDataConstants.BINDINGS_PARENT);
    for (Map.Entry<Long, PersistentAddressBindingEncoding> addressBindingEncodingEntry : addressBindings.entrySet()) {
        PersistentAddressBindingEncoding bindingEncoding = addressBindings.get(addressBindingEncodingEntry.getKey());
        xmlWriter.writeEmptyElement(XmlDataConstants.ADDRESS_BINDINGS_CHILD);
        StringBuilder routingTypes = new StringBuilder();
        for (RoutingType routingType : bindingEncoding.getRoutingTypes()) {
            routingTypes.append(routingType.toString()).append(", ");
        }
        xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_ROUTING_TYPE, routingTypes.toString().substring(0, routingTypes.length() - 2));
        xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_NAME, bindingEncoding.getName().toString());
        xmlWriter.writeAttribute(XmlDataConstants.ADDRESS_BINDING_ID, Long.toString(bindingEncoding.getId()));
        bindingsPrinted++;
    }
    for (Map.Entry<Long, PersistentQueueBindingEncoding> queueBindingEncodingEntry : queueBindings.entrySet()) {
        PersistentQueueBindingEncoding bindingEncoding = queueBindings.get(queueBindingEncodingEntry.getKey());
        xmlWriter.writeEmptyElement(XmlDataConstants.QUEUE_BINDINGS_CHILD);
        xmlWriter.writeAttribute(XmlDataConstants.QUEUE_BINDING_ADDRESS, bindingEncoding.getAddress().toString());
        String filter = "";
        if (bindingEncoding.getFilterString() != null) {
            filter = bindingEncoding.getFilterString().toString();
        }
        xmlWriter.writeAttribute(XmlDataConstants.QUEUE_BINDING_FILTER_STRING, filter);
        xmlWriter.writeAttribute(XmlDataConstants.QUEUE_BINDING_NAME, bindingEncoding.getQueueName().toString());
        xmlWriter.writeAttribute(XmlDataConstants.QUEUE_BINDING_ID, Long.toString(bindingEncoding.getId()));
        xmlWriter.writeAttribute(XmlDataConstants.QUEUE_BINDING_ROUTING_TYPE, RoutingType.getType(bindingEncoding.getRoutingType()).toString());
        bindingsPrinted++;
    }
    // end BINDINGS_PARENT
    xmlWriter.writeEndElement();
}
Also used : PersistentAddressBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentAddressBindingEncoding) PersistentQueueBindingEncoding(org.apache.activemq.artemis.core.persistence.impl.journal.codec.PersistentQueueBindingEncoding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 32 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class XmlDataImporter method bindAddress.

private void bindAddress() throws Exception {
    String addressName = "";
    String routingTypes = "";
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attributeName = reader.getAttributeLocalName(i);
        switch(attributeName) {
            case XmlDataConstants.ADDRESS_BINDING_NAME:
                addressName = reader.getAttributeValue(i);
                break;
            case XmlDataConstants.ADDRESS_BINDING_ROUTING_TYPE:
                routingTypes = reader.getAttributeValue(i);
                break;
        }
    }
    ClientSession.AddressQuery addressQuery = session.addressQuery(new SimpleString(addressName));
    if (!addressQuery.isExists()) {
        EnumSet<RoutingType> set = EnumSet.noneOf(RoutingType.class);
        for (String routingType : ListUtil.toList(routingTypes)) {
            set.add(RoutingType.valueOf(routingType));
        }
        session.createAddress(SimpleString.toSimpleString(addressName), set, false);
        if (logger.isDebugEnabled()) {
            logger.debug("Binding address(name=" + addressName + ", routingTypes=" + routingTypes + ")");
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Binding " + addressName + " already exists so won't re-bind.");
        }
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 33 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class XmlDataImporter method oldBinding.

private void oldBinding() throws Exception {
    String queueName = "";
    String address = "";
    String filter = "";
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String attributeName = reader.getAttributeLocalName(i);
        switch(attributeName) {
            case XmlDataConstants.OLD_ADDRESS:
                address = reader.getAttributeValue(i);
                break;
            case XmlDataConstants.OLD_QUEUE:
                queueName = reader.getAttributeValue(i);
                break;
            case XmlDataConstants.OLD_FILTER:
                filter = reader.getAttributeValue(i);
                break;
        }
    }
    if (queueName == null || address == null || filter == null) {
        // not expected to happen unless someone manually changed the format
        throw new IllegalStateException("invalid format, missing queue, address or filter");
    }
    RoutingType routingType = RoutingType.MULTICAST;
    if (address.startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())) {
        routingType = RoutingType.ANYCAST;
        if (!legacyPrefixes) {
            String newaddress = address.substring(PacketImpl.OLD_QUEUE_PREFIX.length());
            address = newaddress;
        }
    } else if (address.startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())) {
        routingType = RoutingType.MULTICAST;
        if (!legacyPrefixes) {
            String newaddress = address.substring(PacketImpl.OLD_TOPIC_PREFIX.length());
            address = newaddress;
        }
    }
    if (queueName.startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())) {
        if (!legacyPrefixes) {
            String newQueueName = queueName.substring(PacketImpl.OLD_QUEUE_PREFIX.length());
            oldPrefixTranslation.put(queueName, newQueueName);
            queueName = newQueueName;
        }
    } else if (queueName.startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())) {
        if (!legacyPrefixes) {
            String newQueueName = queueName.substring(PacketImpl.OLD_TOPIC_PREFIX.length());
            oldPrefixTranslation.put(queueName, newQueueName);
            queueName = newQueueName;
        }
    }
    ClientSession.AddressQuery addressQuery = session.addressQuery(SimpleString.toSimpleString(address));
    if (!addressQuery.isExists()) {
        session.createAddress(SimpleString.toSimpleString(address), routingType, true);
    }
    if (!filter.equals(FilterImpl.GENERIC_IGNORED_FILTER)) {
        ClientSession.QueueQuery queueQuery = session.queueQuery(new SimpleString(queueName));
        if (!queueQuery.isExists()) {
            session.createQueue(address, routingType, queueName, filter, true);
            if (logger.isDebugEnabled()) {
                logger.debug("Binding queue(name=" + queueName + ", address=" + address + ", filter=" + filter + ")");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Binding " + queueName + " already exists so won't re-bind.");
            }
        }
    }
    addressMap.put(queueName, address);
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 34 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class CreateQueueTest method testAddressDoesNotExist.

@Test
public void testAddressDoesNotExist() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
    Set<RoutingType> routingTypes = new HashSet<>();
    routingTypes.add(RoutingType.ANYCAST);
    try {
        sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
        fail("Creating a queue here should fail since the queue's address doesn't exist and auto-create-addresses = false.");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        ActiveMQException ae = (ActiveMQException) e;
        assertEquals(ActiveMQExceptionType.ADDRESS_DOES_NOT_EXIST, ae.getType());
    }
    sendSession.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with RoutingType

use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.

the class RoutingTest method testAmbiguousMessageRouting.

@Test
public void testAmbiguousMessageRouting() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
    sendSession.createAddress(addressA, routingTypes, false);
    sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
    sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);
    sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC);
    sendSession.createQueue(addressA, RoutingType.MULTICAST, queueD);
    ClientProducer p = sendSession.createProducer(addressA);
    ClientMessage message = sendSession.createMessage(false);
    p.send(message);
    sendSession.close();
    assertTrue(Wait.waitFor(() -> server.locateQueue(queueA).getMessageCount() + server.locateQueue(queueB).getMessageCount() == 1));
    assertTrue(Wait.waitFor(() -> server.locateQueue(queueC).getMessageCount() + server.locateQueue(queueD).getMessageCount() == 2));
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) Test(org.junit.Test)

Aggregations

RoutingType (org.apache.activemq.artemis.api.core.RoutingType)45 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)31 Test (org.junit.Test)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)11 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)11 HashSet (java.util.HashSet)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)8 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)7 OperationContext (org.apache.activemq.artemis.core.persistence.OperationContext)6 ServerSession (org.apache.activemq.artemis.core.server.ServerSession)6 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 Pair (org.apache.activemq.artemis.api.core.Pair)4 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)4 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)4 Filter (org.apache.activemq.artemis.core.filter.Filter)4 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)4