Search in sources :

Example 1 with JMSQueueConfiguration

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

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

the class QueueDestinationsResource method createJmsQueue.

@POST
@Consumes("application/activemq.jms.queue+xml")
public Response createJmsQueue(@Context UriInfo uriInfo, Document document) {
    ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
    try {
        JMSQueueConfiguration queue = FileJMSConfiguration.parseQueueConfiguration(document.getDocumentElement());
        ActiveMQQueue activeMQQueue = ActiveMQDestination.createQueue(queue.getName());
        String queueName = activeMQQueue.getAddress();
        ClientSession session = manager.getSessionFactory().createSession(false, false, false);
        try {
            ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
            if (!query.isExists()) {
                if (queue.getSelector() != null) {
                    session.createQueue(queueName, queueName, queue.getSelector(), queue.isDurable());
                } else {
                    session.createQueue(queueName, queueName, queue.isDurable());
                }
            } 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(queueName).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 : JMSQueueConfiguration(org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration) WebApplicationException(javax.ws.rs.WebApplicationException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 3 with JMSQueueConfiguration

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

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

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

JMSQueueConfiguration (org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration)6 TopicConfiguration (org.apache.activemq.artemis.jms.server.config.TopicConfiguration)4 ArrayList (java.util.ArrayList)2 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)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 URI (java.net.URI)1 List (java.util.List)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 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 CoreAddressConfiguration (org.apache.activemq.artemis.core.config.CoreAddressConfiguration)1 CoreQueueConfiguration (org.apache.activemq.artemis.core.config.CoreQueueConfiguration)1 ConfigurationImpl (org.apache.activemq.artemis.core.config.impl.ConfigurationImpl)1 FileConfiguration (org.apache.activemq.artemis.core.config.impl.FileConfiguration)1