Skip to content

Commit

Permalink
ARTEMIS-3113 - Artemis AMQP shouldn't depend on JMS.
Browse files Browse the repository at this point in the history
* removing the  JMS dependency on AMQP module
* fixing destinations usage.
* refactoring to remove some JMS usage and make exceptions a bit better

Jira: https://issues.apache.org/jira/browse/ARTEMIS-3113
  • Loading branch information
clebertsuconic committed Feb 11, 2021
1 parent 3cd5efd commit e7e3c71
Show file tree
Hide file tree
Showing 24 changed files with 1,310 additions and 1,452 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.utils;

import org.apache.activemq.artemis.api.core.SimpleString;

public class DestinationUtil {

public static final String QUEUE_QUALIFIED_PREFIX = "queue://";
public static final String TOPIC_QUALIFIED_PREFIX = "topic://";
public static final String TEMP_QUEUE_QUALIFED_PREFIX = "temp-queue://";
public static final String TEMP_TOPIC_QUALIFED_PREFIX = "temp-topic://";

public static final char SEPARATOR = '.';

private static String escape(final String input) {
if (input == null) {
return "";
}
return input.replace("\\", "\\\\").replace(".", "\\.");
}

public static String createQueueNameForSharedSubscription(final boolean isDurable,
final String clientID,
final String subscriptionName) {
if (clientID != null) {
return (isDurable ? "Durable" : "nonDurable") + SEPARATOR +
escape(clientID) + SEPARATOR +
escape(subscriptionName);
} else {
return (isDurable ? "Durable" : "nonDurable") + SEPARATOR +
escape(subscriptionName);
}
}

public static SimpleString createQueueNameForSubscription(final boolean isDurable,
final String clientID,
final String subscriptionName) {
final String queueName;
if (clientID != null) {
if (isDurable) {
queueName = escape(clientID) + SEPARATOR +
escape(subscriptionName);
} else {
queueName = "nonDurable" + SEPARATOR +
escape(clientID) + SEPARATOR +
escape(subscriptionName);
}
} else {
if (isDurable) {
queueName = escape(subscriptionName);
} else {
queueName = "nonDurable" + SEPARATOR +
escape(subscriptionName);
}
}
return SimpleString.toSimpleString(queueName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
import org.apache.activemq.artemis.jndi.JNDIStorable;
import org.apache.activemq.artemis.utils.DestinationUtil;

/**
* ActiveMQ Artemis implementation of a JMS Destination.
Expand All @@ -42,19 +43,10 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se

private static final long serialVersionUID = 5027962425462382883L;

public static final String QUEUE_QUALIFIED_PREFIX = "queue://";
public static final String TOPIC_QUALIFIED_PREFIX = "topic://";
public static final String TEMP_QUEUE_QUALIFED_PREFIX = "temp-queue://";
public static final String TEMP_TOPIC_QUALIFED_PREFIX = "temp-topic://";

private static final char SEPARATOR = '.';

private static String escape(final String input) {
if (input == null) {
return "";
}
return input.replace("\\", "\\\\").replace(".", "\\.");
}
public static final String QUEUE_QUALIFIED_PREFIX = DestinationUtil.QUEUE_QUALIFIED_PREFIX;
public static final String TOPIC_QUALIFIED_PREFIX = DestinationUtil.TOPIC_QUALIFIED_PREFIX;
public static final String TEMP_QUEUE_QUALIFED_PREFIX = DestinationUtil.TEMP_QUEUE_QUALIFED_PREFIX;
public static final String TEMP_TOPIC_QUALIFED_PREFIX = DestinationUtil.TEMP_TOPIC_QUALIFED_PREFIX;

/** createQueue and createTopic from {@link ActiveMQSession} may change the name
* in case Prefix usage */
Expand Down Expand Up @@ -167,38 +159,13 @@ public static Destination fromPrefixed1XName(final String addr, final String nam
public static SimpleString createQueueNameForSubscription(final boolean isDurable,
final String clientID,
final String subscriptionName) {
final String queueName;
if (clientID != null) {
if (isDurable) {
queueName = ActiveMQDestination.escape(clientID) + SEPARATOR +
ActiveMQDestination.escape(subscriptionName);
} else {
queueName = "nonDurable" + SEPARATOR +
ActiveMQDestination.escape(clientID) + SEPARATOR +
ActiveMQDestination.escape(subscriptionName);
}
} else {
if (isDurable) {
queueName = ActiveMQDestination.escape(subscriptionName);
} else {
queueName = "nonDurable" + SEPARATOR +
ActiveMQDestination.escape(subscriptionName);
}
}
return SimpleString.toSimpleString(queueName);
return DestinationUtil.createQueueNameForSubscription(isDurable, clientID, subscriptionName);
}

public static String createQueueNameForSharedSubscription(final boolean isDurable,
final String clientID,
final String subscriptionName) {
if (clientID != null) {
return (isDurable ? "Durable" : "nonDurable") + SEPARATOR +
ActiveMQDestination.escape(clientID) + SEPARATOR +
ActiveMQDestination.escape(subscriptionName);
} else {
return (isDurable ? "Durable" : "nonDurable") + SEPARATOR +
ActiveMQDestination.escape(subscriptionName);
}
return DestinationUtil.createQueueNameForSharedSubscription(isDurable, clientID, subscriptionName);
}

public static Pair<String, String> decomposeQueueNameForDurableSubscription(final String queueName) {
Expand All @@ -213,7 +180,7 @@ public static Pair<String, String> decomposeQueueNameForDurableSubscription(fina
char ch = queueName.charAt(pos);
pos++;

if (ch == SEPARATOR) {
if (ch == DestinationUtil.SEPARATOR) {
currentPart++;
if (currentPart >= parts.length) {
throw new JMSRuntimeException("Invalid message queue name: " + queueName);
Expand Down
12 changes: 3 additions & 9 deletions artemis-protocols/artemis-amqp-protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,19 @@
</properties>

<dependencies>
<!-- JMS Client because of some conversions that are done -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<artifactId>artemis-selector</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-selector</artifactId>
<artifactId>artemis-core-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-core-client</artifactId>
<artifactId>artemis-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -110,11 +109,6 @@
<artifactId>commons-collections</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.management.Notification;
import org.apache.activemq.artemis.core.server.management.NotificationListener;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
import org.apache.activemq.artemis.protocol.amqp.client.ProtonClientProtocolManager;
import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext;
import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConstants;
Expand All @@ -47,6 +46,7 @@
import org.apache.activemq.artemis.spi.core.remoting.Connection;

import io.netty.channel.ChannelPipeline;
import org.apache.activemq.artemis.utils.DestinationUtil;
import org.jboss.logging.Logger;

/**
Expand Down Expand Up @@ -101,8 +101,7 @@ public class ProtonProtocolManager extends AbstractProtocolManager<AMQPMessage,
* used when you want to treat senders as a subscription on an address rather than consuming from the actual queue for
* the address. This can be changed on the acceptor.
* */
// TODO fix this
private String pubSubPrefix = ActiveMQDestination.TOPIC_QUALIFIED_PREFIX;
private String pubSubPrefix = DestinationUtil.TOPIC_QUALIFIED_PREFIX;

private int maxFrameSize = AmqpSupport.MAX_FRAME_SIZE_DEFAULT;

Expand Down
Loading

0 comments on commit e7e3c71

Please sign in to comment.