Search in sources :

Example 36 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ConsumersResource method createSubscription.

@POST
public Response createSubscription(@FormParam("autoAck") @DefaultValue("true") boolean autoAck, @FormParam("selector") String selector, @Context UriInfo uriInfo) {
    ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
    try {
        QueueConsumer consumer = null;
        int attributes = 0;
        if (selector != null) {
            attributes = attributes | SELECTOR_SET;
        }
        if (autoAck) {
            consumer = createConsumer(selector);
        } else {
            attributes |= ACKNOWLEDGED;
            consumer = createAcknowledgedConsumer(selector);
        }
        String attributesSegment = "attributes-" + attributes;
        UriBuilder location = uriInfo.getAbsolutePathBuilder();
        location.path(attributesSegment);
        location.path(consumer.getId());
        Response.ResponseBuilder builder = Response.created(location.build());
        if (autoAck) {
            QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1");
        } else {
            AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(0) + "/" + attributesSegment + "/" + consumer.getId(), "-1");
        }
        return builder.build();
    } catch (ActiveMQException e) {
        throw new RuntimeException(e);
    } finally {
    }
}
Also used : Response(javax.ws.rs.core.Response) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST)

Example 37 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class PostMessage method publish.

public void publish(HttpHeaders headers, byte[] body, String dup, boolean durable, Long ttl, Long expiration, Integer priority) throws Exception {
    Pooled pooled = getPooled();
    try {
        ClientProducer producer = pooled.producer;
        ClientMessage message = createActiveMQMessage(headers, body, durable, ttl, expiration, priority, pooled.session);
        message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), dup);
        producer.send(message);
        ActiveMQRestLogger.LOGGER.debug("Sent message: " + message);
        pool.add(pooled);
    } catch (Exception ex) {
        try {
            pooled.session.close();
        } catch (ActiveMQException e) {
        }
        addPooled();
        throw ex;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 38 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class QueueDestinationsResource method findQueue.

@Path("/{queue-name}")
public synchronized QueueResource findQueue(@PathParam("queue-name") String name) throws Exception {
    QueueResource queue = queues.get(name);
    if (queue == null) {
        String queueName = name;
        ClientSession session = manager.getSessionFactory().createSession(false, false, false);
        try {
            ClientSession.QueueQuery query = session.queueQuery(new SimpleString(queueName));
            if (!query.isExists()) {
                throw new WebApplicationException(Response.status(404).type("text/plain").entity("Queue '" + name + "' does not exist").build());
            }
            DestinationSettings queueSettings = manager.getDefaultSettings();
            boolean defaultDurable = queueSettings.isDurableSend() || query.isDurable();
            queue = createQueueResource(queueName, defaultDurable, queueSettings.getConsumerSessionTimeoutSeconds(), queueSettings.isDuplicatesAllowed());
        } finally {
            try {
                session.close();
            } catch (ActiveMQException e) {
            }
        }
    }
    return queue;
}
Also used : 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Path(javax.ws.rs.Path)

Example 39 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class AcknowledgedQueueConsumer method unacknowledge.

protected void unacknowledge() {
    // we close current session so that message is redelivered
    // for temporary queues/topics, create a new session before closing old so we don't lose the temporary topic/queue
    ClientConsumer old = consumer;
    ClientSession oldSession = session;
    try {
        createSession();
    } catch (Exception e) {
        shutdown();
        throw new RuntimeException(e);
    } finally {
        try {
            old.close();
        } catch (ActiveMQException e) {
        }
        try {
            oldSession.close();
        } catch (ActiveMQException e) {
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 40 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ActiveMQSession method internalCreateSharedConsumer.

/**
 * This is an internal method for shared consumers
 */
private ActiveMQMessageConsumer internalCreateSharedConsumer(final ActiveMQDestination dest, final String subscriptionName, String selectorString, ConsumerDurability durability) throws JMSException {
    try {
        if (dest.isQueue()) {
            // createSharedConsumer only accepts Topics by declaration
            throw new RuntimeException("Internal error: createSharedConsumer is only meant for Topics");
        }
        if (subscriptionName == null) {
            throw ActiveMQJMSClientBundle.BUNDLE.invalidSubscriptionName();
        }
        selectorString = "".equals(selectorString) ? null : selectorString;
        SimpleString coreFilterString = null;
        if (selectorString != null) {
            coreFilterString = new SimpleString(SelectorTranslator.convertToActiveMQFilterString(selectorString));
        }
        ClientConsumer consumer;
        SimpleString autoDeleteQueueName = null;
        AddressQuery response = session.addressQuery(dest.getSimpleAddress());
        if (!response.isExists() && !response.isAutoCreateAddresses()) {
            throw ActiveMQJMSClientBundle.BUNDLE.destinationDoesNotExist(dest.getSimpleAddress());
        }
        SimpleString queueName;
        if (dest.isTemporary() && durability == ConsumerDurability.DURABLE) {
            throw new InvalidDestinationException("Cannot create a durable subscription on a temporary topic");
        }
        queueName = ActiveMQDestination.createQueueNameForSubscription(durability == ConsumerDurability.DURABLE, connection.getClientID(), subscriptionName);
        try {
            if (durability == ConsumerDurability.DURABLE) {
                createSharedQueue(dest, RoutingType.MULTICAST, queueName, coreFilterString, true, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue());
            } else {
                createSharedQueue(dest, RoutingType.MULTICAST, queueName, coreFilterString, false, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue());
            }
        } catch (ActiveMQQueueExistsException ignored) {
        // We ignore this because querying and then creating the queue wouldn't be idempotent
        // we could also add a parameter to ignore existence what would require a bigger work around to avoid
        // compatibility.
        }
        consumer = session.createConsumer(queueName, null, false);
        ActiveMQMessageConsumer jbc = new ActiveMQMessageConsumer(options, connection, this, consumer, false, dest, selectorString, autoDeleteQueueName);
        consumers.add(jbc);
        return jbc;
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : AddressQuery(org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)139 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15