Search in sources :

Example 1 with TopicConfiguration

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

the class TopicDestinationsResource method createJmsTopic.

@POST
@Consumes("application/activemq.jms.topic+xml")
public Response createJmsTopic(@Context UriInfo uriInfo, Document document) {
    ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
    try {
        TopicConfiguration topic = FileJMSConfiguration.parseTopicConfiguration(document.getDocumentElement());
        ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(topic.getName());
        String topicName = activeMQTopic.getAddress();
        ClientSession session = manager.getSessionFactory().createSession(false, false, false);
        try {
            ClientSession.AddressQuery query = session.addressQuery(new SimpleString(topicName));
            if (!query.isExists()) {
                session.createAddress(SimpleString.toSimpleString(topicName), RoutingType.MULTICAST, true);
            } else {
                throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build());
            }
        } finally {
            try {
                session.close();
            } catch (Exception ignored) {
            }
        }
        URI uri = uriInfo.getRequestUriBuilder().path(topicName).build();
        return Response.created(uri).build();
    } catch (Exception e) {
        if (e instanceof WebApplicationException)
            throw (WebApplicationException) e;
        throw new WebApplicationException(e, Response.serverError().type("text/plain").entity("Failed to create queue.").build());
    }
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) WebApplicationException(javax.ws.rs.WebApplicationException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) URI(java.net.URI) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with TopicConfiguration

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

the class FileBroker method start.

@Override
public synchronized void start() throws Exception {
    if (started) {
        return;
    }
    // todo if we start to pullout more configs from the main config then we should pull out the configuration objects from factories if available
    FileConfiguration configuration = new FileConfiguration();
    // Keep this as we still want to parse destinations in the <jms> element
    FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration();
    FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(configurationUrl);
    fileDeploymentManager.addDeployable(configuration).addDeployable(jmsConfiguration);
    fileDeploymentManager.readConfiguration();
    createDirectories(configuration);
    /**
     * This is a bit of a hack for backwards config compatibility since we no longer want to start the broker
     * using the JMSServerManager which would normally deploy JMS destinations. Here we take the JMS destination
     * configurations from the parsed JMS configuration and add them to the core configuration.
     *
     * It's also important here that we are adding them to the core ADDRESS configurations as those will be
     * deployed first and therefore their configuration will take precedence over other legacy queue configurations
     * which are deployed later. This is so we can maintain support for configurations like those found in the
     * bridge and divert examples where there are JMS and core queues with the same name (which was itself a bit
     * of a hack).
     *
     * This should be removed when support for the old "jms" configuation element is also removed.
     */
    {
        for (JMSQueueConfiguration jmsQueueConfig : jmsConfiguration.getQueueConfigurations()) {
            List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
            coreAddressConfigurations.add(new CoreAddressConfiguration().setName(jmsQueueConfig.getName()).addRoutingType(RoutingType.ANYCAST).addQueueConfiguration(new CoreQueueConfiguration().setAddress(jmsQueueConfig.getName()).setName(jmsQueueConfig.getName()).setFilterString(jmsQueueConfig.getSelector()).setRoutingType(RoutingType.ANYCAST)));
        }
        for (TopicConfiguration topicConfig : jmsConfiguration.getTopicConfigurations()) {
            List<CoreAddressConfiguration> coreAddressConfigurations = configuration.getAddressConfigurations();
            coreAddressConfigurations.add(new CoreAddressConfiguration().setName(topicConfig.getName()).addRoutingType(RoutingType.MULTICAST));
        }
    }
    components = fileDeploymentManager.buildService(securityManager, ManagementFactory.getPlatformMBeanServer());
    ArrayList<ActiveMQComponent> componentsByStartOrder = getComponentsByStartOrder(components);
    ActiveMQBootstrapLogger.LOGGER.serverStarting();
    for (ActiveMQComponent component : componentsByStartOrder) {
        component.start();
    }
    started = true;
}
Also used : FileConfiguration(org.apache.activemq.artemis.core.config.impl.FileConfiguration) JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) FileJMSConfiguration(org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration) CoreAddressConfiguration(org.apache.activemq.artemis.core.config.CoreAddressConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) CoreQueueConfiguration(org.apache.activemq.artemis.core.config.CoreQueueConfiguration) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager)

Example 3 with TopicConfiguration

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

the class JMSServerManagerImpl method deploy.

private void deploy() throws Exception {
    if (config == null) {
        return;
    }
    List<ConnectionFactoryConfiguration> connectionFactoryConfigurations = config.getConnectionFactoryConfigurations();
    for (ConnectionFactoryConfiguration cfConfig : connectionFactoryConfigurations) {
        createConnectionFactory(false, cfConfig, cfConfig.getBindings());
    }
    List<JMSQueueConfiguration> queueConfigs = config.getQueueConfigurations();
    for (JMSQueueConfiguration qConfig : queueConfigs) {
        createQueue(false, qConfig.getName(), qConfig.getSelector(), qConfig.isDurable(), qConfig.getBindings());
    }
    List<TopicConfiguration> topicConfigs = config.getTopicConfigurations();
    for (TopicConfiguration tConfig : topicConfigs) {
        createTopic(false, tConfig.getName(), tConfig.getBindings());
    }
}
Also used : JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) ConnectionFactoryConfiguration(org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration)

Example 4 with TopicConfiguration

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

the class FileJMSConfiguration method parseConfiguration.

/**
 * Parse the JMS Configuration XML
 */
public void parseConfiguration(final Node rootnode) throws Exception {
    ArrayList<JMSQueueConfiguration> queues = new ArrayList<>();
    ArrayList<TopicConfiguration> topics = new ArrayList<>();
    Element e = (Element) rootnode;
    String[] elements = new String[] { QUEUE_NODE_NAME, TOPIC_NODE_NAME };
    for (String element : elements) {
        NodeList children = e.getElementsByTagName(element);
        for (int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            Node keyNode = node.getAttributes().getNamedItem(NAME_ATTR);
            if (keyNode == null) {
                ActiveMQJMSServerLogger.LOGGER.jmsConfigMissingKey(node);
                continue;
            }
            if (node.getNodeName().equals(TOPIC_NODE_NAME)) {
                topics.add(parseTopicConfiguration(node));
            } else if (node.getNodeName().equals(QUEUE_NODE_NAME)) {
                queues.add(parseQueueConfiguration(node));
            }
        }
    }
    String domain = XMLConfigurationUtil.getString(e, JMX_DOMAIN_NAME, ActiveMQDefaultConfiguration.getDefaultJmxDomain(), Validators.NO_CHECK);
    newConfig(queues, topics, domain);
}
Also used : JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration)

Example 5 with TopicConfiguration

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

the class JMSServerConfigParserTest method testParsing.

// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testParsing() throws Exception {
    Configuration config = createDefaultInVMConfig().addConnectorConfiguration("netty", new TransportConfiguration());
    String conf = "activemq-jms-for-JMSServerDeployerTest.xml";
    FileJMSConfiguration jmsconfig = new FileJMSConfiguration();
    FileDeploymentManager deploymentManager = new FileDeploymentManager(conf);
    deploymentManager.addDeployable(jmsconfig);
    deploymentManager.readConfiguration();
    assertEquals(1, jmsconfig.getQueueConfigurations().size());
    JMSQueueConfiguration queueConfig = jmsconfig.getQueueConfigurations().get(0);
    assertEquals("fullConfigurationQueue", queueConfig.getName());
    assertEquals(1, jmsconfig.getTopicConfigurations().size());
    TopicConfiguration topicConfig = jmsconfig.getTopicConfigurations().get(0);
    assertEquals("fullConfigurationTopic", topicConfig.getName());
}
Also used : JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) FileJMSConfiguration(org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration) FileJMSConfiguration(org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) FileDeploymentManager(org.apache.activemq.artemis.core.config.FileDeploymentManager) 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