Search in sources :

Example 1 with DestinationSettings

use of org.apache.activemq.artemis.rest.queue.DestinationSettings in project activemq-artemis by apache.

the class TopicDestinationsResource method findTopic.

@Path("/{topic-name}")
public TopicResource findTopic(@PathParam("topic-name") String name) throws Exception {
    TopicResource topic = topics.get(name);
    if (topic == null) {
        ClientSession session = manager.getSessionFactory().createSession(false, false, false);
        try {
            ClientSession.AddressQuery query = session.addressQuery(new SimpleString(name));
            if (!query.isExists()) {
                System.err.println("Topic '" + name + "' does not exist");
                throw new WebApplicationException(Response.status(404).type("text/plain").entity("Topic '" + name + "' does not exist").build());
            }
            DestinationSettings queueSettings = manager.getDefaultSettings();
            boolean defaultDurable = queueSettings.isDurableSend();
            topic = createTopicResource(name, defaultDurable, queueSettings.getConsumerSessionTimeoutSeconds(), queueSettings.isDuplicatesAllowed());
        } finally {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
    return topic;
}
Also used : DestinationSettings(org.apache.activemq.artemis.rest.queue.DestinationSettings) WebApplicationException(javax.ws.rs.WebApplicationException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Path(javax.ws.rs.Path)

Example 2 with DestinationSettings

use of org.apache.activemq.artemis.rest.queue.DestinationSettings in project activemq-artemis by apache.

the class MessageServiceManager method start.

public void start() throws Exception {
    if (configuration == null || !configSet) {
        if (configResourcePath == null) {
            configuration = new MessageServiceConfiguration();
        } else {
            URL url = getClass().getClassLoader().getResource(configResourcePath);
            if (isOutsideOfClassloader(url)) {
                url = new URL(configResourcePath);
            }
            JAXBContext jaxb = JAXBContext.newInstance(MessageServiceConfiguration.class);
            Reader reader = new InputStreamReader(url.openStream());
            String xml = XMLUtil.readerToString(reader);
            xml = XMLUtil.replaceSystemProps(xml);
            configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
        }
    }
    if (threadPool == null)
        threadPool = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    timeoutTaskInterval = configuration.getTimeoutTaskInterval();
    timeoutTask = new TimeoutTask(timeoutTaskInterval);
    threadPool.execute(timeoutTask);
    DestinationSettings defaultSettings = new DestinationSettings();
    defaultSettings.setConsumerSessionTimeoutSeconds(configuration.getConsumerSessionTimeoutSeconds());
    defaultSettings.setDuplicatesAllowed(configuration.isDupsOk());
    defaultSettings.setDurableSend(configuration.isDefaultDurableSend());
    ServerLocator consumerLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
    if (configuration.getConsumerWindowSize() != -1) {
        consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
    }
    ActiveMQRestLogger.LOGGER.debug("Created ServerLocator: " + consumerLocator);
    consumerSessionFactory = consumerLocator.createSessionFactory();
    ActiveMQRestLogger.LOGGER.debug("Created ClientSessionFactory: " + consumerSessionFactory);
    ServerLocator defaultLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
    ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();
    LinkStrategy linkStrategy;
    if (configuration.isUseLinkHeaders()) {
        linkStrategy = new LinkHeaderLinkStrategy();
    } else {
        linkStrategy = new CustomHeaderLinkStrategy();
    }
    queueManager.setServerLocator(defaultLocator);
    queueManager.setSessionFactory(sessionFactory);
    queueManager.setTimeoutTask(timeoutTask);
    queueManager.setConsumerServerLocator(consumerLocator);
    queueManager.setConsumerSessionFactory(consumerSessionFactory);
    queueManager.setDefaultSettings(defaultSettings);
    queueManager.setPushStoreFile(configuration.getQueuePushStoreDirectory());
    queueManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
    queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
    queueManager.setLinkStrategy(linkStrategy);
    queueManager.setRegistry(registry);
    topicManager.setServerLocator(defaultLocator);
    topicManager.setSessionFactory(sessionFactory);
    topicManager.setTimeoutTask(timeoutTask);
    topicManager.setConsumerServerLocator(consumerLocator);
    topicManager.setConsumerSessionFactory(consumerSessionFactory);
    topicManager.setDefaultSettings(defaultSettings);
    topicManager.setPushStoreFile(configuration.getTopicPushStoreDirectory());
    topicManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
    queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
    topicManager.setLinkStrategy(linkStrategy);
    topicManager.setRegistry(registry);
    queueManager.start();
    topicManager.start();
}
Also used : DestinationSettings(org.apache.activemq.artemis.rest.queue.DestinationSettings) CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) URL(java.net.URL) TimeoutTask(org.apache.activemq.artemis.rest.util.TimeoutTask) CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) LinkStrategy(org.apache.activemq.artemis.rest.util.LinkStrategy) StringReader(java.io.StringReader) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Aggregations

DestinationSettings (org.apache.activemq.artemis.rest.queue.DestinationSettings)2 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JAXBContext (javax.xml.bind.JAXBContext)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 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 CustomHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy)1 LinkHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy)1 LinkStrategy (org.apache.activemq.artemis.rest.util.LinkStrategy)1 TimeoutTask (org.apache.activemq.artemis.rest.util.TimeoutTask)1