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();
}
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.");
}
}
}
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);
}
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();
}
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));
}
Aggregations