use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class AMQSession method createConsumer.
public List<AMQConsumer> createConsumer(ConsumerInfo info, SlowConsumerDetectionListener slowConsumerDetectionListener) throws Exception {
// check destination
ActiveMQDestination dest = info.getDestination();
ActiveMQDestination[] dests = null;
if (dest.isComposite()) {
dests = dest.getCompositeDestinations();
} else {
dests = new ActiveMQDestination[] { dest };
}
List<AMQConsumer> consumersList = new java.util.LinkedList<>();
for (ActiveMQDestination openWireDest : dests) {
boolean isInternalAddress = false;
if (AdvisorySupport.isAdvisoryTopic(dest)) {
if (!connection.isSuppportAdvisory()) {
continue;
}
isInternalAddress = connection.isSuppressInternalManagementObjects();
}
if (openWireDest.isQueue()) {
openWireDest = protocolManager.virtualTopicConsumerToFQQN(openWireDest);
SimpleString queueName = new SimpleString(convertWildcard(openWireDest.getPhysicalName()));
if (!checkAutoCreateQueue(queueName, openWireDest.isTemporary())) {
throw new InvalidDestinationException("Destination doesn't exist: " + queueName);
}
}
AMQConsumer consumer = new AMQConsumer(this, openWireDest, info, scheduledPool, isInternalAddress);
long nativeID = consumerIDGenerator.generateID();
consumer.init(slowConsumerDetectionListener, nativeID);
consumersList.add(consumer);
}
return consumersList;
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class ActiveMQSession method unsubscribe.
@Override
public void unsubscribe(final String name) throws JMSException {
// As per spec. section 4.11
if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
}
SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), name);
try {
QueueQuery response = session.queueQuery(queueName);
if (!response.isExists()) {
throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name + " does not exist");
}
if (response.getConsumerCount() != 0) {
throw new IllegalStateException("Cannot unsubscribe durable subscription " + name + " since it has active subscribers");
}
session.deleteQueue(queueName);
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class ActiveMQSession method createProducer.
@Override
public MessageProducer createProducer(final Destination destination) throws JMSException {
if (destination != null && !(destination instanceof ActiveMQDestination)) {
throw new InvalidDestinationException("Not an ActiveMQ Artemis Destination:" + destination);
}
try {
ActiveMQDestination jbd = (ActiveMQDestination) destination;
if (jbd != null) {
ClientSession.AddressQuery response = session.addressQuery(jbd.getSimpleAddress());
if (!response.isExists()) {
try {
if (jbd.isQueue() && response.isAutoCreateQueues()) {
// perhaps just relying on the broker to do it is simplest (i.e. purgeOnNoConsumers)
session.createAddress(jbd.getSimpleAddress(), RoutingType.ANYCAST, true);
createQueue(jbd, RoutingType.ANYCAST, jbd.getSimpleAddress(), null, true, true, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue());
} else if (!jbd.isQueue() && response.isAutoCreateAddresses()) {
session.createAddress(jbd.getSimpleAddress(), RoutingType.MULTICAST, true);
} else {
throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
}
} catch (ActiveMQQueueExistsException e) {
// Queue was created between our query and create queue request. Ignore.
}
}
}
ClientProducer producer = session.createProducer(jbd == null ? null : jbd.getSimpleAddress());
return new ActiveMQMessageProducer(connection, producer, jbd, session, options);
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class ActiveMQSession method deleteTemporaryQueue.
public void deleteTemporaryQueue(final ActiveMQDestination tempQueue) throws JMSException {
if (!tempQueue.isTemporary()) {
throw new InvalidDestinationException("Not a temporary queue " + tempQueue);
}
try {
QueueQuery response = session.queueQuery(tempQueue.getSimpleAddress());
if (!response.isExists()) {
throw new InvalidDestinationException("Cannot delete temporary queue " + tempQueue.getName() + " does not exist");
}
if (response.getConsumerCount() > 0) {
throw new IllegalStateException("Cannot delete temporary queue " + tempQueue.getName() + " since it has subscribers");
}
SimpleString address = tempQueue.getSimpleAddress();
session.deleteQueue(address);
connection.removeTemporaryQueue(address);
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class FQQNOpenWireTest method testSpecialFQQNCase.
@Test
public void testSpecialFQQNCase() throws Exception {
Connection exConn = null;
SimpleString durableQueue = new SimpleString("myqueue");
this.server.createQueue(durableQueue, RoutingType.ANYCAST, durableQueue, null, true, false, -1, false, true);
try {
ActiveMQConnectionFactory exFact = new ActiveMQConnectionFactory();
exConn = exFact.createConnection();
exConn.start();
Session session = exConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(durableQueue.toString());
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage("This is a text message");
producer.send(message);
// this should work as if only queue names is given
Destination destinationFQN = session.createQueue(CompositeAddress.SEPARATOR + durableQueue);
MessageConsumer messageConsumer = session.createConsumer(destinationFQN);
TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
assertEquals("This is a text message", messageReceived.getText());
messageConsumer.close();
destinationFQN = session.createQueue(durableQueue + CompositeAddress.SEPARATOR);
try {
session.createConsumer(destinationFQN);
fail("should get exception");
} catch (InvalidDestinationException e) {
// expected.
}
destinationFQN = session.createQueue(CompositeAddress.SEPARATOR);
try {
session.createConsumer(destinationFQN);
fail("should get exception");
} catch (InvalidDestinationException e) {
// expected.
}
} finally {
if (exConn != null) {
exConn.close();
}
}
}
Aggregations