From dcfa11df9462a49d8baf9500a8b3d8a3ce5d979f Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Fri, 16 Jul 2010 23:50:13 +0000 Subject: QPID-2736 The session.createQueue and session.createTopic methods will behave as follows. session.createQueue =================== 1. If just a queue name is passed, 1.1 If the destination syntax is BURL, a queue by that name will be created and bound to the amq.direct exchange using the queue name as the binding key. If published using this destination, then the message will be sent to amq.direct with routing key set to the queue name. 1.2 If destination syntax is ADDR, a queue is created by that name. If published using this exchange then the message will be sent to the defualt exchange (nameless exchange) with routing key set to the queue name. 2. If an address string or binding url is passed, it will be passed accordingly. session.createTopic =================== 1. If just a topic name is passed, 1.1 If destination syntax is ADDR, a temp queue is created and bound to the amq.topic with the topic name as binding key. If published using this destination, then the message will be sent to amq.topic with the topic name set to routing key. The topic name will also be set as "qpid.subject" in the outgoing message. 1.2 Same as above except there will be no subject set. 2. If an address string or binding url is passed, it will be passed accordingly. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@964984 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/client/AMQAnyDestination.java | 10 ++- .../org/apache/qpid/client/AMQDestination.java | 60 +++++++++++------ .../java/org/apache/qpid/client/AMQSession.java | 77 ++++++++++++++-------- 3 files changed, 100 insertions(+), 47 deletions(-) (limited to 'java/client/src') diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java index b6e433f532..a201f7d61e 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQAnyDestination.java @@ -22,6 +22,10 @@ package org.apache.qpid.client; import java.net.URISyntaxException; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Topic; + import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.messaging.Address; import org.apache.qpid.url.BindingURL; @@ -35,7 +39,7 @@ import org.apache.qpid.url.BindingURL; * The abstract class AMQDestination has most of the functionality * to support any destination defined in AMQP 0-10 spec. */ -public class AMQAnyDestination extends AMQDestination +public class AMQAnyDestination extends AMQDestination implements Queue, Topic { public AMQAnyDestination(BindingURL binding) { @@ -66,4 +70,8 @@ public class AMQAnyDestination extends AMQDestination return getAMQQueueName() == null; } + public String getTopicName() throws JMSException + { + return super.getRoutingKey().toString(); + } } diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java index 55812f8e01..4e8c5836e0 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQDestination.java @@ -151,6 +151,11 @@ public abstract class AMQDestination implements Destination, Referenceable } + public static DestSyntax getDefaultDestSyntax() + { + return defaultDestSyntax; + } + protected AMQDestination(Address address) throws Exception { this._address = address; @@ -159,21 +164,41 @@ public abstract class AMQDestination implements Destination, Referenceable _logger.debug("Based on " + address + " the selected destination syntax is " + _destSyntax); } - protected AMQDestination(String str) throws URISyntaxException + public static DestSyntax getDestType(String str) { if (str.startsWith("BURL:") || - (!str.startsWith("ADDR:") && defaultDestSyntax == DestSyntax.BURL)) + (!str.startsWith("ADDR:") && defaultDestSyntax == DestSyntax.BURL)) + { + return DestSyntax.BURL; + } + else + { + return DestSyntax.ADDR; + } + } + + public static String stripSyntaxPrefix(String str) + { + if (str.startsWith("BURL:") || str.startsWith("ADDR:")) + { + return str.substring(5,str.length()); + } + else + { + return str; + } + } + + protected AMQDestination(String str) throws URISyntaxException + { + _destSyntax = getDestType(str); + str = stripSyntaxPrefix(str); + if (_destSyntax == DestSyntax.BURL) { - if (str.startsWith("BURL:")) - { - str = str.substring(5,str.length()); - } - _destSyntax = DestSyntax.BURL; getInfoFromBindingURL(new AMQBindingURL(str)); } else { - _destSyntax = DestSyntax.ADDR; this._address = createAddressFromString(str); try { @@ -654,13 +679,10 @@ public abstract class AMQDestination implements Destination, Referenceable public static Destination createDestination(String str) throws Exception { - if (str.startsWith("BURL:") || - (!str.startsWith("ADDR:") && defaultDestSyntax == DestSyntax.BURL)) + DestSyntax syntax = getDestType(str); + str = stripSyntaxPrefix(str); + if (syntax == DestSyntax.BURL) { - if (str.startsWith("BURL:")) - { - str = str.substring(5,str.length()); - } return createDestination(new AMQBindingURL(str)); } else @@ -738,6 +760,10 @@ public abstract class AMQDestination implements Destination, Referenceable public AddressOption getCreate() { return _create; } + + public void setCreate(AddressOption option) { + _create = option; + } public AddressOption getAssert() { return _assert; @@ -794,11 +820,7 @@ public abstract class AMQDestination implements Destination, Referenceable private static Address createAddressFromString(String str) { - if (str.startsWith("ADDR:")) - { - str = str.substring(5,str.length()); - } - return Address.parse(str); + return Address.parse(str); } private void getInfoFromAddress() throws Exception diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java index 10ee8a8a0d..55b56444de 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession.java @@ -1081,26 +1081,38 @@ public abstract class AMQSession