use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class RoutingTest method testAnycastMessageRoutingExclusivity.
@Test
public void testAnycastMessageRoutingExclusivity() 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);
ClientProducer p = sendSession.createProducer(addressA);
ClientMessage message = sendSession.createMessage(false);
message.setRoutingType(RoutingType.ANYCAST);
p.send(message);
sendSession.close();
assertTrue(Wait.waitFor(() -> server.locateQueue(queueA).getMessageCount() + server.locateQueue(queueB).getMessageCount() == 1));
assertTrue(Wait.waitFor(() -> server.locateQueue(queueC).getMessageCount() == 0));
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class MQTTSubscriptionManager method findOrCreateQueue.
private Queue findOrCreateQueue(BindingQueryResult bindingQueryResult, AddressInfo addressInfo, SimpleString queue, int qos) throws Exception {
if (addressInfo.getRoutingTypes().contains(RoutingType.MULTICAST)) {
return session.getServerSession().createQueue(addressInfo.getName(), queue, RoutingType.MULTICAST, managementFilter, false, MQTTUtil.DURABLE_MESSAGES && qos >= 0, false);
}
if (addressInfo.getRoutingTypes().contains(RoutingType.ANYCAST)) {
if (!bindingQueryResult.getQueueNames().isEmpty()) {
SimpleString name = null;
for (SimpleString qName : bindingQueryResult.getQueueNames()) {
if (name == null) {
name = qName;
} else if (qName.equals(addressInfo.getName())) {
name = qName;
}
}
return session.getServer().locateQueue(name);
} else {
try {
return session.getServerSession().createQueue(addressInfo.getName(), addressInfo.getName(), RoutingType.ANYCAST, managementFilter, false, MQTTUtil.DURABLE_MESSAGES && qos >= 0, false);
} catch (ActiveMQQueueExistsException e) {
return session.getServer().locateQueue(addressInfo.getName());
}
}
}
Set<RoutingType> routingTypeSet = new HashSet();
routingTypeSet.add(RoutingType.MULTICAST);
routingTypeSet.add(RoutingType.ANYCAST);
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(addressInfo.getRoutingType(), addressInfo.getName().toString(), routingTypeSet);
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class AMQSession method checkAutoCreateQueue.
private boolean checkAutoCreateQueue(SimpleString queueName, boolean isTemporary) throws Exception {
boolean hasQueue = true;
if (!connection.containsKnownDestination(queueName)) {
BindingQueryResult bindingQuery = server.bindingQuery(queueName);
QueueQueryResult queueBinding = server.queueQuery(queueName);
try {
if (!queueBinding.isExists()) {
if (bindingQuery.isAutoCreateQueues()) {
SimpleString queueNameToUse = queueName;
SimpleString addressToUse = queueName;
RoutingType routingTypeToUse = RoutingType.ANYCAST;
if (CompositeAddress.isFullyQualified(queueName.toString())) {
CompositeAddress compositeAddress = CompositeAddress.getQueueName(queueName.toString());
addressToUse = new SimpleString(compositeAddress.getAddress());
queueNameToUse = new SimpleString(compositeAddress.getQueueName());
if (bindingQuery.getAddressInfo() != null) {
routingTypeToUse = bindingQuery.getAddressInfo().getRoutingType();
} else {
AddressSettings as = server.getAddressSettingsRepository().getMatch(addressToUse.toString());
routingTypeToUse = as.getDefaultAddressRoutingType();
}
}
coreSession.createQueue(addressToUse, queueNameToUse, routingTypeToUse, null, isTemporary, true);
connection.addKnownDestination(queueName);
} else {
hasQueue = false;
}
}
} catch (ActiveMQQueueExistsException e) {
// In case another thread created the queue before us but after we did the binding query
hasQueue = true;
}
}
return hasQueue;
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class VersionedStompFrameHandler method onSend.
public StompFrame onSend(StompFrame frame) {
StompFrame response = null;
try {
connection.validate();
String destination = getDestination(frame);
RoutingType routingType = getRoutingType(frame.getHeader(Headers.Send.DESTINATION_TYPE), frame.getHeader(Headers.Send.DESTINATION));
connection.autoCreateDestinationIfPossible(destination, routingType);
connection.checkDestination(destination);
connection.checkRoutingSemantics(destination, routingType);
String txID = frame.getHeader(Stomp.Headers.TRANSACTION);
long timestamp = System.currentTimeMillis();
CoreMessage message = connection.createServerMessage();
if (routingType != null) {
message.setRoutingType(routingType);
}
message.setTimestamp(timestamp);
message.setAddress(SimpleString.toSimpleString(destination));
StompUtils.copyStandardHeadersFromFrameToMessage(frame, message);
if (frame.hasHeader(Stomp.Headers.CONTENT_LENGTH)) {
message.setType(Message.BYTES_TYPE);
message.getBodyBuffer().writeBytes(frame.getBodyAsBytes());
} else {
message.setType(Message.TEXT_TYPE);
String text = frame.getBody();
message.getBodyBuffer().writeNullableSimpleString(SimpleString.toSimpleString(text));
}
connection.sendServerMessage(message, txID);
} catch (ActiveMQStompException e) {
response = e.getFrame();
} catch (Exception e) {
ActiveMQStompException error = BUNDLE.errorHandleSend(e).setHandler(this);
response = error.getFrame();
}
return response;
}
use of org.apache.activemq.artemis.api.core.RoutingType in project activemq-artemis by apache.
the class StompConnection method autoCreateDestinationIfPossible.
public void autoCreateDestinationIfPossible(String queue, RoutingType routingType) throws ActiveMQStompException {
ServerSession session = getSession().getCoreSession();
try {
SimpleString simpleQueue = SimpleString.toSimpleString(queue);
if (manager.getServer().getAddressInfo(simpleQueue) == null) {
AddressSettings addressSettings = manager.getServer().getAddressSettingsRepository().getMatch(queue);
RoutingType effectiveAddressRoutingType = routingType == null ? addressSettings.getDefaultAddressRoutingType() : routingType;
if (addressSettings.isAutoCreateAddresses()) {
session.createAddress(simpleQueue, effectiveAddressRoutingType, true);
}
// only auto create the queue if the address is ANYCAST
if (effectiveAddressRoutingType == RoutingType.ANYCAST && addressSettings.isAutoCreateQueues()) {
session.createQueue(simpleQueue, simpleQueue, routingType == null ? addressSettings.getDefaultQueueRoutingType() : routingType, null, false, true, true);
}
}
} catch (ActiveMQQueueExistsException e) {
// ignore
} catch (Exception e) {
throw new ActiveMQStompException(e.getMessage(), e).setHandler(frameHandler);
}
}
Aggregations