private RoutingType getRoutingType(Symbol[] symbols, SimpleString address) { if (symbols != null) { for (Symbol symbol : symbols) { if (AmqpSupport.TEMP_TOPIC_CAPABILITY.equals(symbol) || AmqpSupport.TOPIC_CAPABILITY.equals(symbol)) { return RoutingType.MULTICAST; } else if (AmqpSupport.TEMP_QUEUE_CAPABILITY.equals(symbol) || AmqpSupport.QUEUE_CAPABILITY.equals(symbol)) { return RoutingType.ANYCAST; } } } final AddressInfo addressInfo = sessionSPI.getAddress(address); if (addressInfo != null && !addressInfo.getRoutingTypes().isEmpty()) { if (addressInfo.getRoutingTypes().size() == 1 && addressInfo.getRoutingType() == RoutingType.MULTICAST) { return RoutingType.MULTICAST; } } RoutingType defaultRoutingType = sessionSPI.getDefaultRoutingType(address); defaultRoutingType = defaultRoutingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : defaultRoutingType; return defaultRoutingType; }
private void sendAddressNotification(AddressInfo addressInfo, final CoreNotificationType type) { final ManagementService managementService = getManagementService(); if (managementService != null && sendAddressNotifications) { try { final TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, addressInfo.getName()); props.putByteProperty(ManagementHelper.HDR_ROUTING_TYPE, addressInfo.getRoutingType().getType()); managementService.sendNotification(new Notification(null, type, props)); } catch (Exception e) { logger.warn("Error sending notification: " + type, e.getMessage(), e); } } }
private RoutingType getRoutingType(Symbol[] symbols, SimpleString address) { if (symbols != null) { for (Symbol symbol : symbols) { if (AmqpSupport.TEMP_TOPIC_CAPABILITY.equals(symbol) || AmqpSupport.TOPIC_CAPABILITY.equals(symbol)) { return RoutingType.MULTICAST; } else if (AmqpSupport.TEMP_QUEUE_CAPABILITY.equals(symbol) || AmqpSupport.QUEUE_CAPABILITY.equals(symbol)) { return RoutingType.ANYCAST; } } } final AddressInfo addressInfo = sessionSPI.getAddress(address); if (addressInfo != null && !addressInfo.getRoutingTypes().isEmpty()) { if (addressInfo.getRoutingTypes().size() == 1 && addressInfo.getRoutingType() == RoutingType.MULTICAST) { return RoutingType.MULTICAST; } } RoutingType defaultRoutingType = sessionSPI.getDefaultRoutingType(address); defaultRoutingType = defaultRoutingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : defaultRoutingType; return defaultRoutingType; }
private RoutingType getRoutingType(String typeHeader, String destination) throws Exception { // null is valid to return here so we know when the user didn't provide any routing info RoutingType routingType; if (typeHeader != null) { routingType = RoutingType.valueOf(typeHeader); } else { routingType = connection.getSession().getCoreSession().getAddressAndRoutingType(new AddressInfo(new SimpleString(destination))).getRoutingType(); } return routingType; }
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); }
private RoutingType getRoutingType(String typeHeader, String destination) throws ActiveMQStompException { // null is valid to return here so we know when the user didn't provide any routing info RoutingType routingType; if (typeHeader != null) { routingType = RoutingType.valueOf(typeHeader); } else { routingType = connection.getSession().getCoreSession().getAddressAndRoutingType(new AddressInfo(new SimpleString(destination))).getRoutingType(); } return routingType; }
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); }
routingContext.setRoutingType(art.getRoutingType());
private void deployAddressesFromConfiguration(Configuration configuration) throws Exception { for (CoreAddressConfiguration config : configuration.getAddressConfigurations()) { try { ActiveMQServerLogger.LOGGER.deployAddress(config.getName(), config.getRoutingTypes().toString()); SimpleString address = SimpleString.toSimpleString(config.getName()); AddressInfo tobe = new AddressInfo(address, config.getRoutingTypes()); //During this stage until all queues re-configured we combine the current (if exists) with to-be routing types to allow changes in queues AddressInfo current = getAddressInfo(address); AddressInfo merged = new AddressInfo(address, tobe.getRoutingType()); if (current != null) { merged.getRoutingTypes().addAll(current.getRoutingTypes()); } addOrUpdateAddressInfo(merged); deployQueuesFromListCoreQueueConfiguration(config.getQueueConfigurations()); //Now all queues updated we apply the actual address info expected tobe. addOrUpdateAddressInfo(tobe); } catch (Exception e) { ActiveMQServerLogger.LOGGER.problemDeployingAddress(config.getName(), e.getMessage()); } } }
@Test public void testAutoCreateMulticastAddress() throws Throwable { if (!isNetty()) { // no need to run the test, there's no AMQP support return; } assertNull(server.getAddressInfo(SimpleString.toSimpleString("topic"))); ConnectionFactory factorySend = createFactory(2); Connection connection = factorySend.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Topic topic = session.createTopic("topic"); MessageProducer producer = session.createProducer(topic); producer.setDeliveryMode(DeliveryMode.PERSISTENT); TextMessage msg = session.createTextMessage("hello"); msg.setIntProperty("mycount", 0); producer.send(msg); } finally { connection.close(); } assertNotNull(server.getAddressInfo(SimpleString.toSimpleString("topic"))); assertEquals(RoutingType.MULTICAST, server.getAddressInfo(SimpleString.toSimpleString("topic")).getRoutingType()); assertEquals(0, server.getTotalMessageCount()); }
routingType = addressInfo.getRoutingTypes().size() == 1 ? addressInfo.getRoutingType() : getAddressSettingsRepository().getMatch(address.toString()).getDefaultQueueRoutingType(); if (routingType == null) {
assertEquals(RoutingType.MULTICAST, server.getAddressInfo(simpleTopicName).getRoutingType()); assertTrue(server.getAddressInfo(simpleTopicName).isAutoCreated()); assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
RoutingType routingType = addrInfo == null ? null : addrInfo.getRoutingType(); RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType); if (autoCreateAddress || temporary) {
queueNameToUse = CompositeAddress.extractQueueName(queueName); if (bindingQuery.getAddressInfo() != null) { routingTypeToUse = bindingQuery.getAddressInfo().getRoutingType(); } else { AddressSettings as = server.getAddressSettingsRepository().getMatch(addressToUse.toString());
assertEquals(RoutingType.MULTICAST, server.getAddressInfo(simpleTopicName).getRoutingType()); assertTrue(server.getAddressInfo(simpleTopicName).isAutoCreated()); assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
configuration.setAddressConfigurations(addressConfigurations); server.start(); assertEquals(RoutingType.MULTICAST, server.getAddressInfo(SimpleString.toSimpleString("myAddress")).getRoutingType()); assertEquals(RoutingType.MULTICAST, server.locateQueue(SimpleString.toSimpleString("myQueue")).getRoutingType());