Search in sources :

Example 26 with InvalidDestinationException

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;
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 27 with InvalidDestinationException

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);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Example 28 with InvalidDestinationException

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);
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) InvalidDestinationException(javax.jms.InvalidDestinationException) AddressQuery(org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer)

Example 29 with InvalidDestinationException

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);
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQuery(org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)

Example 30 with InvalidDestinationException

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();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

InvalidDestinationException (javax.jms.InvalidDestinationException)38 Test (org.junit.Test)20 Session (javax.jms.Session)18 Connection (javax.jms.Connection)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 JMSException (javax.jms.JMSException)11 Topic (javax.jms.Topic)11 MessageProducer (javax.jms.MessageProducer)10 Queue (javax.jms.Queue)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 TextMessage (javax.jms.TextMessage)8 TopicSession (javax.jms.TopicSession)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 IllegalStateException (javax.jms.IllegalStateException)5 QueueSession (javax.jms.QueueSession)5 TopicConnection (javax.jms.TopicConnection)5 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 AddressQuery (org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery)4 BytesMessage (javax.jms.BytesMessage)3 MessageConsumer (javax.jms.MessageConsumer)3