You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/07/27 16:56:49 UTC
svn commit: r426094 - in /incubator/activemq/trunk/activemq-core/src:
main/java/org/apache/activemq/broker/region/virtual/
test/java/org/apache/activemq/ test/java/org/apache/activemq/broker/virtual/
test/resources/org/apache/activemq/broker/virtual/
Author: jstrachan
Date: Thu Jul 27 07:56:48 2006
New Revision: 426094
URL: http://svn.apache.org/viewvc?rev=426094&view=rev
Log:
added test cases for composite destinations (which are kinds of virtual destinations) - see http://incubator.apache.org/activemq/virtual-destinations.html
Added:
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java (with props)
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java (with props)
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml (with props)
incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml (with props)
Modified:
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestination.java
incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestinationInterceptor.java
incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java
Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestination.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestination.java?rev=426094&r1=426093&r2=426094&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestination.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestination.java Thu Jul 27 07:56:48 2006
@@ -27,11 +27,12 @@
public abstract class CompositeDestination implements VirtualDestination {
private String name;
- private Collection forwardDestinations;
+ private Collection forwardTo;
private boolean forwardOnly = true;
+ private boolean copyMessage = true;
public Destination intercept(Destination destination) {
- return new CompositeDestinationInterceptor(destination, getForwardDestinations(), isForwardOnly());
+ return new CompositeDestinationInterceptor(destination, getForwardTo(), isForwardOnly(), isCopyMessage());
}
public String getName() {
@@ -45,15 +46,15 @@
this.name = name;
}
- public Collection getForwardDestinations() {
- return forwardDestinations;
+ public Collection getForwardTo() {
+ return forwardTo;
}
/**
* Sets the list of destinations to forward to
*/
- public void setForwardDestinations(Collection forwardDestinations) {
- this.forwardDestinations = forwardDestinations;
+ public void setForwardTo(Collection forwardDestinations) {
+ this.forwardTo = forwardDestinations;
}
public boolean isForwardOnly() {
@@ -68,4 +69,18 @@
public void setForwardOnly(boolean forwardOnly) {
this.forwardOnly = forwardOnly;
}
+
+ public boolean isCopyMessage() {
+ return copyMessage;
+ }
+
+ /**
+ * Sets whether a copy of the message will be sent to each destination.
+ * Defaults to true so that the forward destination is set as the
+ * destination of the message
+ */
+ public void setCopyMessage(boolean copyMessage) {
+ this.copyMessage = copyMessage;
+ }
+
}
Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestinationInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestinationInterceptor.java?rev=426094&r1=426093&r2=426094&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestinationInterceptor.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/virtual/CompositeDestinationInterceptor.java Thu Jul 27 07:56:48 2006
@@ -35,16 +35,24 @@
private Collection forwardDestinations;
private boolean forwardOnly;
+ private boolean copyMessage;
- public CompositeDestinationInterceptor(Destination next, Collection forwardDestinations, boolean forwardOnly) {
+ public CompositeDestinationInterceptor(Destination next, Collection forwardDestinations, boolean forwardOnly, boolean copyMessage) {
super(next);
this.forwardDestinations = forwardDestinations;
this.forwardOnly = forwardOnly;
+ this.copyMessage = copyMessage;
}
public void send(ConnectionContext context, Message message) throws Exception {
for (Iterator iter = forwardDestinations.iterator(); iter.hasNext();) {
ActiveMQDestination destination = (ActiveMQDestination) iter.next();
+
+ if (copyMessage) {
+ message = message.copy();
+ message.setDestination(destination);
+ }
+
send(context, message, destination);
}
if (!forwardOnly) {
Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java?rev=426094&r1=426093&r2=426094&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java (original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java Thu Jul 27 07:56:48 2006
@@ -35,7 +35,7 @@
*
* @version $Revision: 1.1 $
*/
-public class EmbeddedBrokerTestSupport extends TestCase {
+public abstract class EmbeddedBrokerTestSupport extends TestCase {
protected static final Log log = LogFactory.getLog(EmbeddedBrokerTestSupport.class);
Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java?rev=426094&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java Thu Jul 27 07:56:48 2006
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.broker.virtual;
+
+import org.apache.activemq.EmbeddedBrokerTestSupport;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.spring.ConsumerBean;
+import org.apache.activemq.xbean.XBeanBrokerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import java.net.URI;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class CompositeQueueTest extends EmbeddedBrokerTestSupport {
+
+ private static final Log log = LogFactory.getLog(CompositeQueueTest.class);
+
+ private Connection connection;
+
+ public void testVirtualTopicCreation() throws Exception {
+ if (connection == null) {
+ connection = createConnection();
+ }
+ connection.start();
+
+ ConsumerBean messageList1 = new ConsumerBean();
+ ConsumerBean messageList2 = new ConsumerBean();
+ messageList1.setVerbose(true);
+ messageList2.setVerbose(true);
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ Destination producerDestination = getProducerDestination();
+ Destination destination1 = getConsumer1Dsetination();
+ Destination destination2 = getConsumer2Dsetination();
+
+ log.info("Sending to: " + producerDestination);
+ log.info("Consuming from: " + destination1 + " and " + destination2);
+
+ MessageConsumer c1 = session.createConsumer(destination1);
+ MessageConsumer c2 = session.createConsumer(destination2);
+
+ c1.setMessageListener(messageList1);
+ c2.setMessageListener(messageList2);
+
+ // create topic producer
+ MessageProducer producer = session.createProducer(producerDestination);
+ assertNotNull(producer);
+
+ int total = 10;
+ for (int i = 0; i < total; i++) {
+ producer.send(session.createTextMessage("message: " + i));
+ }
+
+ messageList1.assertMessagesArrived(total);
+ messageList2.assertMessagesArrived(total);
+ }
+
+ protected Destination getConsumer1Dsetination() {
+ return new ActiveMQQueue("FOO");
+ }
+
+ protected Destination getConsumer2Dsetination() {
+ return new ActiveMQTopic("BAR");
+ }
+
+ protected Destination getProducerDestination() {
+ return new ActiveMQQueue("MY.QUEUE");
+ }
+
+ protected void tearDown() throws Exception {
+ if (connection != null) {
+ connection.close();
+ }
+ super.tearDown();
+ }
+
+ protected BrokerService createBroker() throws Exception {
+ XBeanBrokerFactory factory = new XBeanBrokerFactory();
+ BrokerService answer = factory.createBroker(new URI(getBrokerConfigUri()));
+
+ // lets disable persistence as we are a test
+ answer.setPersistent(false);
+
+ return answer;
+ }
+
+ protected String getBrokerConfigUri() {
+ return "org/apache/activemq/broker/virtual/composite-queue.xml";
+ }
+}
\ No newline at end of file
Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeQueueTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java?rev=426094&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java Thu Jul 27 07:56:48 2006
@@ -0,0 +1,45 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed 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.broker.virtual;
+
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+
+import javax.jms.Destination;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class CompositeTopicTest extends CompositeQueueTest {
+
+ protected Destination getConsumer1Dsetination() {
+ return new ActiveMQQueue("FOO");
+ }
+
+ protected Destination getConsumer2Dsetination() {
+ return new ActiveMQTopic("BAR");
+ }
+
+ protected Destination getProducerDestination() {
+ return new ActiveMQTopic("MY.TOPIC");
+ }
+
+ protected String getBrokerConfigUri() {
+ return "org/apache/activemq/broker/virtual/composite-topic.xml";
+ }
+}
Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/virtual/CompositeTopicTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml?rev=426094&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml (added)
+++ incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml Thu Jul 27 07:56:48 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2005-2006 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!-- this file can only be parsed using the xbean-spring library -->
+<!-- START SNIPPET: xbean -->
+<beans>
+
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <broker xmlns="http://activemq.org/config/1.0">
+ <destinationInterceptors>
+ <virtualDestinationInterceptor>
+ <virtualDestinations>
+ <compositeQueue name="MY.QUEUE">
+ <forwardTo>
+ <queue physicalName="FOO"/>
+ <topic physicalName="BAR"/>
+ </forwardTo>
+ </compositeQueue>
+ </virtualDestinations>
+ </virtualDestinationInterceptor>
+ </destinationInterceptors>
+
+ </broker>
+
+</beans>
+<!-- END SNIPPET: xbean -->
Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-queue.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml?rev=426094&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml (added)
+++ incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml Thu Jul 27 07:56:48 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2005-2006 The Apache Software Foundation
+
+ Licensed 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.
+-->
+
+<!-- this file can only be parsed using the xbean-spring library -->
+<!-- START SNIPPET: xbean -->
+<beans>
+
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <broker xmlns="http://activemq.org/config/1.0">
+ <destinationInterceptors>
+ <virtualDestinationInterceptor>
+ <virtualDestinations>
+ <compositeTopic name="MY.TOPIC">
+ <forwardTo>
+ <queue physicalName="FOO"/>
+ <topic physicalName="BAR"/>
+ </forwardTo>
+ </compositeTopic>
+ </virtualDestinations>
+ </virtualDestinationInterceptor>
+ </destinationInterceptors>
+
+ </broker>
+
+</beans>
+<!-- END SNIPPET: xbean -->
Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/broker/virtual/composite-topic.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml