Search in sources :

Example 1 with EmbeddedActiveMQ

use of org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ in project spring-boot by spring-projects.

the class ArtemisEmbeddedServerConfiguration method embeddedActiveMq.

@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnMissingBean
EmbeddedActiveMQ embeddedActiveMq(org.apache.activemq.artemis.core.config.Configuration configuration, JMSConfiguration jmsConfiguration, ObjectProvider<ArtemisConfigurationCustomizer> configurationCustomizers) throws Exception {
    for (JMSQueueConfiguration queueConfiguration : jmsConfiguration.getQueueConfigurations()) {
        String queueName = queueConfiguration.getName();
        configuration.addAddressConfiguration(new CoreAddressConfiguration().setName(queueName).addRoutingType(RoutingType.ANYCAST).addQueueConfiguration(new QueueConfiguration(queueName).setAddress(queueName).setFilterString(queueConfiguration.getSelector()).setDurable(queueConfiguration.isDurable()).setRoutingType(RoutingType.ANYCAST)));
    }
    for (TopicConfiguration topicConfiguration : jmsConfiguration.getTopicConfigurations()) {
        configuration.addAddressConfiguration(new CoreAddressConfiguration().setName(topicConfiguration.getName()).addRoutingType(RoutingType.MULTICAST));
    }
    configurationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(configuration));
    EmbeddedActiveMQ embeddedActiveMq = new EmbeddedActiveMQ();
    embeddedActiveMq.setConfiguration(configuration);
    return embeddedActiveMq;
}
Also used : JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) QueueConfiguration(org.apache.activemq.artemis.api.core.QueueConfiguration) JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) CoreAddressConfiguration(org.apache.activemq.artemis.core.config.CoreAddressConfiguration) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) EmbeddedActiveMQ(org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with EmbeddedActiveMQ

use of org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ 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 EmbeddedActiveMQ

use of org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ in project scout.rt by eclipse.

the class ArtemisJmsBrokerTestRule method startArtemisJmsServer.

protected void startArtemisJmsServer() throws Exception {
    prepareArtemisWorkDirectory();
    EmbeddedActiveMQ embeddedArtemisServer = new EmbeddedActiveMQ();
    embeddedArtemisServer.setConfiguration(createArtemisServerConfig());
    embeddedArtemisServer.start();
    m_embeddedArtemisServer = embeddedArtemisServer;
}
Also used : EmbeddedActiveMQ(org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ)

Example 4 with EmbeddedActiveMQ

use of org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ in project midpoint by Evolveum.

the class TestAsyncProvisioningArtemis method startEmbeddedBroker.

private void startEmbeddedBroker() throws Exception {
    embeddedBroker = new EmbeddedActiveMQ();
    embeddedBroker.start();
}
Also used : EmbeddedActiveMQ(org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ)

Example 5 with EmbeddedActiveMQ

use of org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ in project midpoint by Evolveum.

the class TestAsyncProvisioning method startEmbeddedBroker.

private void startEmbeddedBroker() throws Exception {
    embeddedBroker = new EmbeddedActiveMQ();
    embeddedBroker.start();
}
Also used : EmbeddedActiveMQ(org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ)

Aggregations

EmbeddedActiveMQ (org.apache.activemq.artemis.core.server.embedded.EmbeddedActiveMQ)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)2 ConfigurationImpl (org.apache.activemq.artemis.core.config.impl.ConfigurationImpl)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 Bean (org.springframework.context.annotation.Bean)2 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 QueueConfiguration (org.apache.activemq.artemis.api.core.QueueConfiguration)1 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)1 Configuration (org.apache.activemq.artemis.core.config.Configuration)1 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)1 AddressFullMessagePolicy (org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy)1 JMSQueueConfiguration (org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration)1 TopicConfiguration (org.apache.activemq.artemis.jms.server.config.TopicConfiguration)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1