Search in sources :

Example 1 with AddressFullMessagePolicy

use of org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy in project activemq-artemis by apache.

the class FileConfigurationParser method parseAddressSettings.

/**
 * @param node
 * @return
 */
protected Pair<String, AddressSettings> parseAddressSettings(final Node node) {
    String match = getAttributeValue(node, "match");
    NodeList children = node.getChildNodes();
    AddressSettings addressSettings = new AddressSettings();
    Pair<String, AddressSettings> setting = new Pair<>(match, addressSettings);
    for (int i = 0; i < children.getLength(); i++) {
        final Node child = children.item(i);
        final String name = child.getNodeName();
        if (DEAD_LETTER_ADDRESS_NODE_NAME.equalsIgnoreCase(name)) {
            SimpleString queueName = new SimpleString(getTrimmedTextContent(child));
            addressSettings.setDeadLetterAddress(queueName);
        } else if (EXPIRY_ADDRESS_NODE_NAME.equalsIgnoreCase(name)) {
            SimpleString queueName = new SimpleString(getTrimmedTextContent(child));
            addressSettings.setExpiryAddress(queueName);
        } else if (EXPIRY_DELAY_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setExpiryDelay(XMLUtil.parseLong(child));
        } else if (REDELIVERY_DELAY_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setRedeliveryDelay(XMLUtil.parseLong(child));
        } else if (REDELIVERY_DELAY_MULTIPLIER_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setRedeliveryMultiplier(XMLUtil.parseDouble(child));
        } else if (MAX_REDELIVERY_DELAY_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setMaxRedeliveryDelay(XMLUtil.parseLong(child));
        } else if (MAX_SIZE_BYTES_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setMaxSizeBytes(ByteUtil.convertTextBytes(getTrimmedTextContent(child)));
        } else if (PAGE_SIZE_BYTES_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setPageSizeBytes(ByteUtil.convertTextBytes(getTrimmedTextContent(child)));
        } else if (PAGE_MAX_CACHE_SIZE_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setPageCacheMaxSize(XMLUtil.parseInt(child));
        } else if (MESSAGE_COUNTER_HISTORY_DAY_LIMIT_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setMessageCounterHistoryDayLimit(XMLUtil.parseInt(child));
        } else if (ADDRESS_FULL_MESSAGE_POLICY_NODE_NAME.equalsIgnoreCase(name)) {
            String value = getTrimmedTextContent(child);
            Validators.ADDRESS_FULL_MESSAGE_POLICY_TYPE.validate(ADDRESS_FULL_MESSAGE_POLICY_NODE_NAME, value);
            AddressFullMessagePolicy policy = Enum.valueOf(AddressFullMessagePolicy.class, value);
            addressSettings.setAddressFullMessagePolicy(policy);
        } else if (LVQ_NODE_NAME.equalsIgnoreCase(name) || DEFAULT_LVQ_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setDefaultLastValueQueue(XMLUtil.parseBoolean(child));
        } else if (DEFAULT_EXCLUSIVE_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setDefaultExclusiveQueue(XMLUtil.parseBoolean(child));
        } else if (MAX_DELIVERY_ATTEMPTS.equalsIgnoreCase(name)) {
            addressSettings.setMaxDeliveryAttempts(XMLUtil.parseInt(child));
        } else if (REDISTRIBUTION_DELAY_NODE_NAME.equalsIgnoreCase(name)) {
            addressSettings.setRedistributionDelay(XMLUtil.parseLong(child));
        } else if (SEND_TO_DLA_ON_NO_ROUTE.equalsIgnoreCase(name)) {
            addressSettings.setSendToDLAOnNoRoute(XMLUtil.parseBoolean(child));
        } else if (SLOW_CONSUMER_THRESHOLD_NODE_NAME.equalsIgnoreCase(name)) {
            long slowConsumerThreshold = XMLUtil.parseLong(child);
            Validators.MINUS_ONE_OR_GT_ZERO.validate(SLOW_CONSUMER_THRESHOLD_NODE_NAME, slowConsumerThreshold);
            addressSettings.setSlowConsumerThreshold(slowConsumerThreshold);
        } else if (SLOW_CONSUMER_CHECK_PERIOD_NODE_NAME.equalsIgnoreCase(name)) {
            long slowConsumerCheckPeriod = XMLUtil.parseLong(child);
            Validators.GT_ZERO.validate(SLOW_CONSUMER_CHECK_PERIOD_NODE_NAME, slowConsumerCheckPeriod);
            addressSettings.setSlowConsumerCheckPeriod(slowConsumerCheckPeriod);
        } else if (SLOW_CONSUMER_POLICY_NODE_NAME.equalsIgnoreCase(name)) {
            String value = getTrimmedTextContent(child);
            Validators.SLOW_CONSUMER_POLICY_TYPE.validate(SLOW_CONSUMER_POLICY_NODE_NAME, value);
            SlowConsumerPolicy policy = Enum.valueOf(SlowConsumerPolicy.class, value);
            addressSettings.setSlowConsumerPolicy(policy);
        } else if (AUTO_CREATE_JMS_QUEUES.equalsIgnoreCase(name)) {
            addressSettings.setAutoCreateJmsQueues(XMLUtil.parseBoolean(child));
        } else if (AUTO_DELETE_JMS_QUEUES.equalsIgnoreCase(name)) {
            addressSettings.setAutoDeleteJmsQueues(XMLUtil.parseBoolean(child));
        } else if (AUTO_CREATE_JMS_TOPICS.equalsIgnoreCase(name)) {
            addressSettings.setAutoCreateJmsTopics(XMLUtil.parseBoolean(child));
        } else if (AUTO_DELETE_JMS_TOPICS.equalsIgnoreCase(name)) {
            addressSettings.setAutoDeleteJmsTopics(XMLUtil.parseBoolean(child));
        } else if (AUTO_CREATE_QUEUES.equalsIgnoreCase(name)) {
            addressSettings.setAutoCreateQueues(XMLUtil.parseBoolean(child));
        } else if (AUTO_DELETE_QUEUES.equalsIgnoreCase(name)) {
            addressSettings.setAutoDeleteQueues(XMLUtil.parseBoolean(child));
        } else if (CONFIG_DELETE_QUEUES.equalsIgnoreCase(name)) {
            String value = getTrimmedTextContent(child);
            Validators.DELETION_POLICY_TYPE.validate(CONFIG_DELETE_QUEUES, value);
            DeletionPolicy policy = Enum.valueOf(DeletionPolicy.class, value);
            addressSettings.setConfigDeleteQueues(policy);
        } else if (AUTO_CREATE_ADDRESSES.equalsIgnoreCase(name)) {
            addressSettings.setAutoCreateAddresses(XMLUtil.parseBoolean(child));
        } else if (AUTO_DELETE_ADDRESSES.equalsIgnoreCase(name)) {
            addressSettings.setAutoDeleteAddresses(XMLUtil.parseBoolean(child));
        } else if (CONFIG_DELETE_ADDRESSES.equalsIgnoreCase(name)) {
            String value = getTrimmedTextContent(child);
            Validators.DELETION_POLICY_TYPE.validate(CONFIG_DELETE_ADDRESSES, value);
            DeletionPolicy policy = Enum.valueOf(DeletionPolicy.class, value);
            addressSettings.setConfigDeleteAddresses(policy);
        } else if (MANAGEMENT_BROWSE_PAGE_SIZE.equalsIgnoreCase(name)) {
            addressSettings.setManagementBrowsePageSize(XMLUtil.parseInt(child));
        } else if (DEFAULT_PURGE_ON_NO_CONSUMERS.equalsIgnoreCase(name)) {
            addressSettings.setDefaultPurgeOnNoConsumers(XMLUtil.parseBoolean(child));
        } else if (DEFAULT_MAX_CONSUMERS.equalsIgnoreCase(name)) {
            addressSettings.setDefaultMaxConsumers(XMLUtil.parseInt(child));
        } else if (DEFAULT_QUEUE_ROUTING_TYPE.equalsIgnoreCase(name)) {
            String value = getTrimmedTextContent(child);
            Validators.ROUTING_TYPE.validate(DEFAULT_QUEUE_ROUTING_TYPE, value);
            RoutingType routingType = RoutingType.valueOf(value);
            addressSettings.setDefaultQueueRoutingType(routingType);
        } else if (DEFAULT_ADDRESS_ROUTING_TYPE.equalsIgnoreCase(name)) {
            String value = getTrimmedTextContent(child);
            Validators.ROUTING_TYPE.validate(DEFAULT_ADDRESS_ROUTING_TYPE, value);
            RoutingType routingType = RoutingType.valueOf(value);
            addressSettings.setDefaultAddressRoutingType(routingType);
        }
    }
    return setting;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DeletionPolicy(org.apache.activemq.artemis.core.settings.impl.DeletionPolicy) AddressFullMessagePolicy(org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SlowConsumerPolicy(org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy) Pair(org.apache.activemq.artemis.api.core.Pair) DivertConfigurationRoutingType(org.apache.activemq.artemis.core.server.DivertConfigurationRoutingType) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 2 with AddressFullMessagePolicy

use of org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy in project candlepin by candlepin.

the class ActiveMQContextListener method contextInitialized.

public void contextInitialized(Injector injector) {
    org.candlepin.common.config.Configuration candlepinConfig = injector.getInstance(org.candlepin.common.config.Configuration.class);
    if (activeMQServer == null) {
        Configuration config = new ConfigurationImpl();
        HashSet<TransportConfiguration> transports = new HashSet<>();
        transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
        config.setAcceptorConfigurations(transports);
        // alter the default pass to silence log output
        config.setClusterUser(null);
        config.setClusterPassword(null);
        // in vm, who needs security?
        config.setSecurityEnabled(false);
        config.setJournalType(JournalType.NIO);
        config.setCreateBindingsDir(true);
        config.setCreateJournalDir(true);
        String baseDir = candlepinConfig.getString(ConfigProperties.ACTIVEMQ_BASE_DIR);
        config.setBindingsDirectory(new File(baseDir, "bindings").toString());
        config.setJournalDirectory(new File(baseDir, "journal").toString());
        config.setLargeMessagesDirectory(new File(baseDir, "largemsgs").toString());
        config.setPagingDirectory(new File(baseDir, "paging").toString());
        Map<String, AddressSettings> settings = new HashMap<>();
        AddressSettings pagingConfig = new AddressSettings();
        String addressPolicyString = candlepinConfig.getString(ConfigProperties.ACTIVEMQ_ADDRESS_FULL_POLICY);
        long maxQueueSizeInMb = candlepinConfig.getInt(ConfigProperties.ACTIVEMQ_MAX_QUEUE_SIZE);
        long maxPageSizeInMb = candlepinConfig.getInt(ConfigProperties.ACTIVEMQ_MAX_PAGE_SIZE);
        AddressFullMessagePolicy addressPolicy = null;
        if (addressPolicyString.equals("PAGE")) {
            addressPolicy = AddressFullMessagePolicy.PAGE;
        } else if (addressPolicyString.equals("BLOCK")) {
            addressPolicy = AddressFullMessagePolicy.BLOCK;
        } else {
            throw new IllegalArgumentException("Unknown ACTIVEMQ_ADDRESS_FULL_POLICY: " + addressPolicyString + " . Please use one of: PAGE, BLOCK");
        }
        // Paging sizes need to be converted to bytes
        pagingConfig.setMaxSizeBytes(maxQueueSizeInMb * FileUtils.ONE_MB);
        if (addressPolicy == AddressFullMessagePolicy.PAGE) {
            pagingConfig.setPageSizeBytes(maxPageSizeInMb * FileUtils.ONE_MB);
        }
        pagingConfig.setAddressFullMessagePolicy(addressPolicy);
        // Enable for all the queues
        settings.put("#", pagingConfig);
        config.setAddressesSettings(settings);
        int maxScheduledThreads = candlepinConfig.getInt(ConfigProperties.ACTIVEMQ_MAX_SCHEDULED_THREADS);
        int maxThreads = candlepinConfig.getInt(ConfigProperties.ACTIVEMQ_MAX_THREADS);
        if (maxThreads != -1) {
            config.setThreadPoolMaxSize(maxThreads);
        }
        if (maxScheduledThreads != -1) {
            config.setScheduledThreadPoolMaxSize(maxScheduledThreads);
        }
        /**
         * Anything up to size of LARGE_MSG_SIZE may be needed to be written to the Journal,
         * so we must set buffer size accordingly.
         *
         * If buffer size would be < LARGE_MSG_SIZE we may get exceptions such as this:
         * Can't write records bigger than the bufferSize(XXXYYY) on the journal
         */
        int largeMsgSize = candlepinConfig.getInt(ConfigProperties.ACTIVEMQ_LARGE_MSG_SIZE);
        config.setJournalBufferSize_AIO(largeMsgSize);
        config.setJournalBufferSize_NIO(largeMsgSize);
        activeMQServer = new EmbeddedActiveMQ();
        activeMQServer.setConfiguration(config);
    }
    try {
        activeMQServer.start();
        log.info("ActiveMQ server started");
    } catch (Exception e) {
        log.error("Failed to start ActiveMQ message server:", e);
        throw new RuntimeException(e);
    }
    setupAmqp(injector, candlepinConfig);
    cleanupOldQueues();
    List<String> listeners = getActiveMQListeners(candlepinConfig);
    eventSource = injector.getInstance(EventSource.class);
    for (int i = 0; i < listeners.size(); i++) {
        try {
            Class<?> clazz = this.getClass().getClassLoader().loadClass(listeners.get(i));
            eventSource.registerListener((EventListener) injector.getInstance(clazz));
        } catch (Exception e) {
            log.warn("Unable to register listener " + listeners.get(i), e);
        }
    }
    // Initialize the Event sink AFTER the internal server has been
    // created and started.
    EventSink sink = injector.getInstance(EventSink.class);
    try {
        sink.initialize();
    } catch (Exception e) {
        log.error("Failed to initialize EventSink:", e);
        throw new RuntimeException(e);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Configuration(org.apache.activemq.artemis.core.config.Configuration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) AddressFullMessagePolicy(org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy) HashMap(java.util.HashMap) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ConfigurationImpl(org.apache.activemq.artemis.core.config.impl.ConfigurationImpl) File(java.io.File) HashSet(java.util.HashSet) EmbeddedActiveMQ(org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ)

Example 3 with AddressFullMessagePolicy

use of org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy in project wildfly by wildfly.

the class AddressSettingAdd method createSettings.

/**
 * Create a setting.
 *
 * @param context the operation context
 * @param config the detyped config
 * @return the address settings
 *
 * @throws OperationFailedException if the model is invalid
 */
static AddressSettings createSettings(final OperationContext context, final ModelNode config) throws OperationFailedException {
    final AddressSettings settings = new AddressSettings();
    if (config.hasDefined(AddressSettingDefinition.ADDRESS_FULL_MESSAGE_POLICY.getName())) {
        final AddressFullMessagePolicy addressPolicy = AddressFullMessagePolicy.valueOf(AddressSettingDefinition.ADDRESS_FULL_MESSAGE_POLICY.resolveModelAttribute(context, config).asString());
        settings.setAddressFullMessagePolicy(addressPolicy);
    }
    if (config.hasDefined(DEAD_LETTER_ADDRESS.getName())) {
        settings.setDeadLetterAddress(asSimpleString(DEAD_LETTER_ADDRESS.resolveModelAttribute(context, config), null));
    }
    if (config.hasDefined(AddressSettingDefinition.LAST_VALUE_QUEUE.getName())) {
        settings.setDefaultLastValueQueue(AddressSettingDefinition.LAST_VALUE_QUEUE.resolveModelAttribute(context, config).asBoolean());
    }
    if (config.hasDefined(AddressSettingDefinition.MAX_DELIVERY_ATTEMPTS.getName())) {
        settings.setMaxDeliveryAttempts(AddressSettingDefinition.MAX_DELIVERY_ATTEMPTS.resolveModelAttribute(context, config).asInt());
    }
    if (config.hasDefined(AddressSettingDefinition.MAX_SIZE_BYTES.getName())) {
        settings.setMaxSizeBytes(AddressSettingDefinition.MAX_SIZE_BYTES.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.MESSAGE_COUNTER_HISTORY_DAY_LIMIT.getName())) {
        settings.setMessageCounterHistoryDayLimit(AddressSettingDefinition.MESSAGE_COUNTER_HISTORY_DAY_LIMIT.resolveModelAttribute(context, config).asInt());
    }
    if (config.hasDefined(CommonAttributes.EXPIRY_ADDRESS.getName())) {
        settings.setExpiryAddress(asSimpleString(EXPIRY_ADDRESS.resolveModelAttribute(context, config), null));
    }
    if (config.hasDefined(AddressSettingDefinition.EXPIRY_DELAY.getName())) {
        settings.setExpiryDelay(AddressSettingDefinition.EXPIRY_DELAY.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.REDELIVERY_DELAY.getName())) {
        settings.setRedeliveryDelay(AddressSettingDefinition.REDELIVERY_DELAY.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.REDELIVERY_MULTIPLIER.getName())) {
        settings.setRedeliveryMultiplier(AddressSettingDefinition.REDELIVERY_MULTIPLIER.resolveModelAttribute(context, config).asDouble());
    }
    if (config.hasDefined(AddressSettingDefinition.MAX_REDELIVERY_DELAY.getName())) {
        settings.setMaxRedeliveryDelay(AddressSettingDefinition.MAX_REDELIVERY_DELAY.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.REDISTRIBUTION_DELAY.getName())) {
        settings.setRedistributionDelay(AddressSettingDefinition.REDISTRIBUTION_DELAY.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.PAGE_SIZE_BYTES.getName())) {
        settings.setPageSizeBytes(AddressSettingDefinition.PAGE_SIZE_BYTES.resolveModelAttribute(context, config).asInt());
    }
    if (config.hasDefined(AddressSettingDefinition.PAGE_MAX_CACHE_SIZE.getName())) {
        settings.setPageCacheMaxSize(AddressSettingDefinition.PAGE_MAX_CACHE_SIZE.resolveModelAttribute(context, config).asInt());
    }
    if (config.hasDefined(AddressSettingDefinition.SEND_TO_DLA_ON_NO_ROUTE.getName())) {
        settings.setSendToDLAOnNoRoute(AddressSettingDefinition.SEND_TO_DLA_ON_NO_ROUTE.resolveModelAttribute(context, config).asBoolean());
    }
    if (config.hasDefined(AddressSettingDefinition.SLOW_CONSUMER_CHECK_PERIOD.getName())) {
        settings.setSlowConsumerCheckPeriod(AddressSettingDefinition.SLOW_CONSUMER_CHECK_PERIOD.resolveModelAttribute(context, config).asLong());
    }
    if (config.hasDefined(AddressSettingDefinition.SLOW_CONSUMER_POLICY.getName())) {
        final SlowConsumerPolicy slowConsumerPolicy = SlowConsumerPolicy.valueOf(AddressSettingDefinition.SLOW_CONSUMER_POLICY.resolveModelAttribute(context, config).asString());
        settings.setSlowConsumerPolicy(slowConsumerPolicy);
    }
    if (config.hasDefined(AddressSettingDefinition.SLOW_CONSUMER_THRESHOLD.getName())) {
        settings.setSlowConsumerThreshold(AddressSettingDefinition.SLOW_CONSUMER_THRESHOLD.resolveModelAttribute(context, config).asLong());
    }
    // always set the auto-create|delete-jms-queues attributes as their default attribute values differ from Artemis defaults.
    settings.setAutoCreateJmsQueues(AddressSettingDefinition.AUTO_CREATE_JMS_QUEUES.resolveModelAttribute(context, config).asBoolean());
    settings.setAutoDeleteJmsQueues(AddressSettingDefinition.AUTO_DELETE_JMS_QUEUES.resolveModelAttribute(context, config).asBoolean());
    settings.setAutoCreateQueues(AddressSettingDefinition.AUTO_CREATE_QUEUES.resolveModelAttribute(context, config).asBoolean());
    settings.setAutoDeleteQueues(AddressSettingDefinition.AUTO_DELETE_QUEUES.resolveModelAttribute(context, config).asBoolean());
    settings.setAutoCreateAddresses(AddressSettingDefinition.AUTO_CREATE_ADDRESSES.resolveModelAttribute(context, config).asBoolean());
    settings.setAutoDeleteAddresses(AddressSettingDefinition.AUTO_DELETE_ADDRESSES.resolveModelAttribute(context, config).asBoolean());
    return settings;
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) AddressFullMessagePolicy(org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy) SlowConsumerPolicy(org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy)

Aggregations

AddressFullMessagePolicy (org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy)3 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 SlowConsumerPolicy (org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Pair (org.apache.activemq.artemis.api.core.Pair)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 ConfigurationImpl (org.apache.activemq.artemis.core.config.impl.ConfigurationImpl)1 DivertConfigurationRoutingType (org.apache.activemq.artemis.core.server.DivertConfigurationRoutingType)1 EmbeddedActiveMQ (org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ)1 DeletionPolicy (org.apache.activemq.artemis.core.settings.impl.DeletionPolicy)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1