Search in sources :

Example 1 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue 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 2 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.

the class JMSServerManagerImpl method addQueueToBindingRegistry.

@Override
public boolean addQueueToBindingRegistry(final String queueName, final String registryBinding) throws Exception {
    checkInitialised();
    checkBindings(registryBinding);
    ActiveMQQueue destination = queues.get(queueName);
    if (destination == null) {
        throw new IllegalArgumentException("Queue does not exist");
    }
    if (destination.getQueueName() == null) {
        throw new IllegalArgumentException(queueName + " is not a queue");
    }
    boolean added = bindToBindings(registryBinding, destination);
    if (added) {
        addToBindings(queueBindings, queueName, registryBinding);
        storage.addBindings(PersistedType.Queue, queueName, registryBinding);
    }
    return added;
}
Also used : ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue)

Example 3 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.

the class QueueAutoCreationTest method createQueue.

protected Queue createQueue(final String queueName) throws Exception {
    SimpleString address = SimpleString.toSimpleString(queueName);
    clientSession.createAddress(address, RoutingType.ANYCAST, false);
    return new ActiveMQQueue(queueName);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue)

Example 4 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.

the class StringRefAddrReferenceTest method testActiveMQQueueFromPropertiesJNDI.

@Test(timeout = 10000)
public void testActiveMQQueueFromPropertiesJNDI() throws Exception {
    Properties properties = new Properties();
    properties.setProperty(TYPE, ActiveMQQueue.class.getName());
    properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName());
    String address = "foo.bar.queue";
    properties.setProperty("address", address);
    Reference reference = from(properties);
    ActiveMQQueue object = getObject(reference, ActiveMQQueue.class);
    assertEquals(address, object.getAddress());
}
Also used : Reference(javax.naming.Reference) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) JNDIReferenceFactory(org.apache.activemq.artemis.jndi.JNDIReferenceFactory) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with ActiveMQQueue

use of org.apache.activemq.artemis.jms.client.ActiveMQQueue in project activemq-artemis by apache.

the class LargeMessageQueueAutoCreationTest method createCoreQueue.

protected Queue createCoreQueue(final String queueName) throws Exception {
    SimpleString address = SimpleString.toSimpleString(queueName);
    clientSession.createAddress(address, RoutingType.ANYCAST, false);
    return new ActiveMQQueue(queueName);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue)

Aggregations

ActiveMQQueue (org.apache.activemq.artemis.jms.client.ActiveMQQueue)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 Test (org.junit.Test)3 Connection (javax.jms.Connection)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 Queue (javax.jms.Queue)2 Session (javax.jms.Session)2 TextMessage (javax.jms.TextMessage)2 Reference (javax.naming.Reference)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)2 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)2 ActiveMQTopic (org.apache.activemq.artemis.jms.client.ActiveMQTopic)2 BaseMessages.getString (org.pentaho.di.i18n.BaseMessages.getString)2 URI (java.net.URI)1 Properties (java.util.Properties)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Referenceable (javax.naming.Referenceable)1 ObjectFactory (javax.naming.spi.ObjectFactory)1 Consumes (javax.ws.rs.Consumes)1