Search in sources :

Example 6 with TopicConfiguration

use of org.apache.activemq.artemis.jms.server.config.TopicConfiguration 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 7 with TopicConfiguration

use of org.apache.activemq.artemis.jms.server.config.TopicConfiguration in project activemq-artemis by apache.

the class JMSConfigurationTest method testSetupJMSConfiguration.

@Test
public void testSetupJMSConfiguration() throws Exception {
    Context context = new InVMNamingContext();
    ActiveMQServer coreServer = new ActiveMQServerImpl(createDefaultInVMConfig());
    JMSConfiguration jmsConfiguration = new JMSConfigurationImpl();
    TransportConfiguration connectorConfig = new TransportConfiguration(InVMConnectorFactory.class.getName());
    List<TransportConfiguration> transportConfigs = new ArrayList<>();
    transportConfigs.add(connectorConfig);
    ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl().setName(RandomUtil.randomString()).setConnectorNames(registerConnectors(coreServer, transportConfigs)).setBindings("/cf/binding1", "/cf/binding2");
    jmsConfiguration.getConnectionFactoryConfigurations().add(cfConfig);
    JMSQueueConfigurationImpl queueConfig = new JMSQueueConfigurationImpl().setName(RandomUtil.randomString()).setDurable(false).setBindings("/queue/binding1", "/queue/binding2");
    jmsConfiguration.getQueueConfigurations().add(queueConfig);
    TopicConfiguration topicConfig = new TopicConfigurationImpl().setName(RandomUtil.randomString()).setBindings("/topic/binding1", "/topic/binding2");
    jmsConfiguration.getTopicConfigurations().add(topicConfig);
    JMSServerManager server = new JMSServerManagerImpl(coreServer, jmsConfiguration);
    server.setRegistry(new JndiBindingRegistry(context));
    server.start();
    for (String binding : cfConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof ConnectionFactory);
        ConnectionFactory cf = (ConnectionFactory) o;
        Connection connection = cf.createConnection();
        connection.close();
    }
    for (String binding : queueConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Queue);
        Queue queue = (Queue) o;
        Assert.assertEquals(queueConfig.getName(), queue.getQueueName());
    }
    for (String binding : topicConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Topic);
        Topic topic = (Topic) o;
        Assert.assertEquals(topicConfig.getName(), topic.getTopicName());
    }
    server.stop();
}
Also used : InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Context(javax.naming.Context) JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) JMSConfiguration(org.apache.activemq.artemis.jms.server.config.JMSConfiguration) ArrayList(java.util.ArrayList) Connection(javax.jms.Connection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JndiBindingRegistry(org.apache.activemq.artemis.core.registry.JndiBindingRegistry) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ConnectionFactory(javax.jms.ConnectionFactory) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ConnectionFactoryConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl) JMSConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl) JMSQueueConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.JMSQueueConfigurationImpl) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) Topic(javax.jms.Topic) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration) Queue(javax.jms.Queue) TopicConfigurationImpl(org.apache.activemq.artemis.jms.server.config.impl.TopicConfigurationImpl) InVMNamingContext(org.apache.activemq.artemis.tests.unit.util.InVMNamingContext) Test(org.junit.Test)

Aggregations

TopicConfiguration (org.apache.activemq.artemis.jms.server.config.TopicConfiguration)7 JMSQueueConfiguration (org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration)5 ArrayList (java.util.ArrayList)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)2 FileDeploymentManager (org.apache.activemq.artemis.core.config.FileDeploymentManager)2 ConnectionFactoryConfiguration (org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)2 FileJMSConfiguration (org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration)2 Test (org.junit.Test)2 URI (java.net.URI)1 List (java.util.List)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Queue (javax.jms.Queue)1 Topic (javax.jms.Topic)1 Context (javax.naming.Context)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1