}
else
{
subscriptionName = generateSubscriptionName();
}
ClientSession session = null;
try
{
// if this is not a reconnect, create the subscription queue
if (!subscriptionExists(subscriptionName))
{
session = sessionFactory.createSession();
if (durable)
{
session.createQueue(destination, subscriptionName, true);
}
else
{
session.createTemporaryQueue(destination, subscriptionName);
}
}
QueueConsumer consumer = createConsumer(durable, autoAck, subscriptionName, selector, timeout, deleteWhenIdle);
queueConsumers.put(consumer.getId(), consumer);
serviceManager.getTimeoutTask().add(this, consumer.getId());
UriBuilder location = uriInfo.getAbsolutePathBuilder();
if (autoAck) location.path("auto-ack");
else location.path("acknowledged");
location.path(consumer.getId());
Response.ResponseBuilder builder = Response.created(location.build());
if (autoAck)
{
QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/auto-ack/" + consumer.getId(), "-1");
}
else
{
AcknowledgedQueueConsumer.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId(), "-1");
}
return builder.build();
}
catch (HornetQException e)
{
throw new RuntimeException(e);
}
finally
{
if (session != null)
{
try
{
session.close();
}
catch (HornetQException e)
{
}
}