try { if (dest.isQueue()) { AddressQuery response = session.addressQuery(dest.getSimpleAddress()); throw ActiveMQJMSClientBundle.BUNDLE.destinationDoesNotExist(dest.getSimpleAddress()); 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); if (!(subResponse.isExists() && Objects.equals(subResponse.getAddress(), dest.getSimpleAddress()) && Objects.equals(subResponse.getFilterString(), coreFilterString))) { try { if (durability == ConsumerDurability.DURABLE) {
if (!activeMQDestination.isQueue()) { throw new InvalidDestinationException("Cannot create a browser on a topic"); AddressQuery response = session.addressQuery(new SimpleString(activeMQDestination.getAddress())); if (!response.isExists()) { if (response.isAutoCreateQueues()) { createQueue(activeMQDestination, RoutingType.ANYCAST, activeMQDestination.getSimpleAddress(), null, true, true, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue()); } else { throw new InvalidDestinationException("Destination " + activeMQDestination.getName() + " does not exist");
@Override public Destination getJMSDestination() throws JMSException { if (dest == null) { SimpleString address = message.getAddressSimpleString(); SimpleString name = address; if (address != null & enable1xPrefixes) { dest = ActiveMQDestination.fromPrefixedName(get1xPrefixedName(address.toString())); } else { if (address == null) { dest = null; } else if (RoutingType.ANYCAST.equals(message.getRoutingType())) { dest = ActiveMQDestination.createQueue(address); } else if (RoutingType.MULTICAST.equals(message.getRoutingType())) { dest = ActiveMQDestination.createTopic(address); } else { dest = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address.toString()); } if (name != null) { ((ActiveMQDestination) dest).setName(name.toString()); } } } return dest; }
private void checkTempQueues(Destination destination) throws JMSException { ActiveMQDestination jbdest = (ActiveMQDestination) destination; if (jbdest.isTemporary() && !containsTemporaryQueue(jbdest.getSimpleAddress())) { throw new JMSException("Can not create consumer for temporary destination " + destination + " from another JMS connection"); } }
public void deleteTemporaryTopic(final ActiveMQDestination tempTopic) throws JMSException { if (!tempTopic.isTemporary()) { throw new InvalidDestinationException("Not a temporary topic " + tempTopic); } try { AddressQuery response = session.addressQuery(tempTopic.getSimpleAddress()); if (!response.isExists()) { throw new InvalidDestinationException("Cannot delete temporary topic " + tempTopic.getName() + " does not exist"); } if (response.getQueueNames().size() > 1) { throw new IllegalStateException("Cannot delete temporary topic " + tempTopic.getName() + " since it has subscribers"); } SimpleString address = tempTopic.getSimpleAddress(); session.deleteQueue(address); connection.removeTemporaryQueue(address); } catch (ActiveMQException e) { throw JMSExceptionHelper.convertFromActiveMQException(e); } }
if (addr.startsWith(ActiveMQDestination.QUEUE_QUALIFIED_PREFIX)) { address = addr.substring(ActiveMQDestination.QUEUE_QUALIFIED_PREFIX.length()); destination = createQueue(address); } else if (addr.startsWith(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX)) { address = addr.substring(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX.length()); destination = createTopic(address); } else if (addr.startsWith(ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX)) { address = addr.substring(ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX.length()); destination = new ActiveMQTemporaryTopic(address, null); } else { destination = new ActiveMQDestination(addr, TYPE.DESTINATION, null); unprefixedName = unprefixedName.substring(PacketImpl.OLD_TEMP_TOPIC_PREFIX.length()); destination.setName(unprefixedName);
private void createTemporaryQueue(ActiveMQDestination destination, RoutingType routingType, SimpleString queueName, SimpleString filter, int maxConsumers, boolean purgeOnNoConsumers, Boolean exclusive, Boolean lastValue) throws ActiveMQException { QueueAttributes queueAttributes = destination.getQueueAttributes(); if (queueAttributes == null) { session.createTemporaryQueue(destination.getSimpleAddress(), routingType, queueName, filter, maxConsumers, purgeOnNoConsumers, exclusive, lastValue); } else { session.createTemporaryQueue( destination.getSimpleAddress(), routingType, queueName, filter, queueAttributes.getMaxConsumers() == null ? maxConsumers : queueAttributes.getMaxConsumers(), queueAttributes.getPurgeOnNoConsumers() == null ? purgeOnNoConsumers : queueAttributes.getPurgeOnNoConsumers(), queueAttributes.getExclusive() == null ? exclusive : queueAttributes.getExclusive(), queueAttributes.getLastValue() == null ? lastValue : queueAttributes.getLastValue() ); } }
} else { if (defaultDestination != null) { if (!destination.equals(defaultDestination)) { throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal"); address = destination.getSimpleAddress(); if (destination.isQueue() && query.isAutoCreateQueues()) { clientSession.createAddress(address, RoutingType.ANYCAST, true); if (destination.isTemporary()) { createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue()); } else if (!destination.isQueue() && query.isAutoCreateAddresses()) { clientSession.createAddress(address, RoutingType.MULTICAST, true); } else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) { throw new InvalidDestinationException("Destination " + address + " does not exist"); if (queueQuery.isExists()) { connection.addKnownDestination(address); } else if (destination.isQueue() && query.isAutoCreateQueues()) { if (destination.isTemporary()) { clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address); } else { coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID); coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
@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); } }
public String getName() { return name != null ? name : getAddress(); }
if (defaultDestination != null && !destination.equals(defaultDestination)) { address = destination.getSimpleAddress(); coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID); coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
ClientSession.AddressQuery response = session.addressQuery(jbd.getSimpleAddress()); if (jbd.isQueue() && response.isAutoCreateQueues()) { 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"); ClientProducer producer = session.createProducer(jbd == null ? null : jbd.getSimpleAddress());
private ActiveMQQueue lookupQueue(final String queueName, boolean isTemporary) throws ActiveMQException { String queueNameToUse = queueName; if (enable1xPrefixes) { queueNameToUse = (isTemporary ? PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString() : PacketImpl.OLD_QUEUE_PREFIX.toString()) + queueName; } ActiveMQQueue queue; if (isTemporary) { queue = ActiveMQDestination.createTemporaryQueue(queueNameToUse); } else { queue = ActiveMQDestination.createQueue(queueNameToUse); } QueueQuery response = session.queueQuery(queue.getSimpleAddress()); if (!response.isExists() && !response.isAutoCreateQueues()) { return null; } else { return queue; } }
private ActiveMQTopic lookupTopic(final String topicName, final boolean isTemporary) throws ActiveMQException { String topicNameToUse = topicName; if (enable1xPrefixes) { topicNameToUse = (isTemporary ? PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString() : PacketImpl.OLD_TOPIC_PREFIX.toString()) + topicName; } ActiveMQTopic topic; if (isTemporary) { topic = ActiveMQDestination.createTemporaryTopic(topicNameToUse); } else { topic = ActiveMQDestination.createTopic(topicNameToUse); } AddressQuery query = session.addressQuery(topic.getSimpleAddress()); if (!query.isExists() && !query.isAutoCreateAddresses()) { return null; } else { return topic; } }
public static Destination fromPrefixedName(final String name) { return fromPrefixedName(name, name); }
/** * Creates a client-side representation of a JMS Queue. * * This method is deprecated. Use {@link org.apache.activemq.artemis.jms.client.ActiveMQSession#createQueue(String)} (String)} as that method will know the proper * prefix used at the target server. * * * @param name the name of the queue * @return The Queue */ @Deprecated public static Queue createQueue(final String name) { if (DEFAULT_ENABLE_1X_PREFIXES) { return ActiveMQDestination.createQueue(PacketImpl.OLD_QUEUE_PREFIX + name, name); } else { return ActiveMQDestination.createQueue(name); } }
/** * Creates a client-side representation of a JMS Topic. * * This method is deprecated. Use {@link org.apache.activemq.artemis.jms.client.ActiveMQSession#createTopic(String)} as that method will know the proper * prefix used at the target server. * * @param name the name of the topic * @return The Topic */ @Deprecated public static Topic createTopic(final String name) { if (DEFAULT_ENABLE_1X_PREFIXES) { return ActiveMQDestination.createTopic(PacketImpl.OLD_TOPIC_PREFIX + name, name); } else { return ActiveMQDestination.createTopic(name); } }
@Test public void testEquals() throws Exception { String destinationName = RandomUtil.randomString(); String address = QUEUE_QUALIFIED_PREFIX + destinationName; ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address); ActiveMQDestination sameDestination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address); ActiveMQDestination differentDestination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(address + RandomUtil.randomString()); Assert.assertFalse(destination.equals(null)); Assert.assertTrue(destination.equals(destination)); Assert.assertTrue(destination.equals(sameDestination)); Assert.assertFalse(destination.equals(differentDestination)); }
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); } }