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 {
}
}
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;
}
}
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;
}
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) {
}
}
}
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);
}
}
Aggregations