Author: davsclaus
Date: Wed Nov 18 15:41:29 2009
New Revision: 881804
URL: http://svn.apache.org/viewvc?rev=881804&view=rev
Log:
CAMEL-2143: Camel now precents starting if you have mutliple consumers for same
endpoints to prevent copy-paste errors in routes. Some endpoints however do
allow multiple consumers such as jms and mina.
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java
(with props)
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
- copied, changed from r881719,
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectQueueTest.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerStartTwiceTest.java
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
Added:
camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java?rev=881804&view=auto
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java
(added)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java
Wed Nov 18 15:41:29 2009
@@ -0,0 +1,41 @@
+/**
+ * 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.camel;
+
+/**
+ * {...@link org.apache.camel.Endpoint} can optionally implement this
interface to
+ * indicate whether or not it supports multiple consumers or not.
+ * <p/>
+ * By default endpoints is assumed <b>not</b> to support multiple consumers.
+ * <p/>
+ * A rare few endpoint does in fact support multiple consumers and thus the
purpose of this interface.
+ * For example JMS endpoints which has topics that can be consumed by multiple
consumers.
+ * <p/>
+ * The purpose of this is to check on startup that we do not have multiple
consumers
+ * for the <b>same</b> endpoints. This prevent starting up when there was a
copy/paste mistakes in the Camel routes.
+ *
+ * @version $Revision$
+ */
+public interface MultipleConsumersSupport {
+
+ /**
+ * Is multiple consumers supported?
+ *
+ * @return <tt>true</tt> if multiple consumers is supported
+ */
+ boolean isMultipleConsumersSupported();
+}
Propchange:
camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/main/java/org/apache/camel/MultipleConsumersSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectConsumer.java
Wed Nov 18 15:41:29 2009
@@ -36,11 +36,13 @@
@Override
public void start() throws Exception {
- if (!endpoint.isAllowMultipleConsumers() &&
!endpoint.getConsumers().isEmpty()) {
- throw new IllegalStateException("Endpoint " +
endpoint.getEndpointUri() + " only allows 1 active consumer but you attempted
to start a 2nd consumer.");
+ // only add as consumer if not already registered
+ if (!endpoint.getConsumers().contains(this)) {
+ if (!endpoint.getConsumers().isEmpty()) {
+ throw new IllegalStateException("Endpoint " +
endpoint.getEndpointUri() + " only allows 1 active consumer but you attempted
to start a 2nd consumer.");
+ }
+ endpoint.getConsumers().add(this);
}
-
- endpoint.getConsumers().add(this);
super.start();
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
Wed Nov 18 15:41:29 2009
@@ -32,7 +32,6 @@
* @version $Revision$
*/
public class DirectEndpoint extends DefaultEndpoint {
- private boolean allowMultipleConsumers = true;
private final CopyOnWriteArrayList<DefaultConsumer> consumers = new
CopyOnWriteArrayList<DefaultConsumer>();
public DirectEndpoint() {
@@ -54,14 +53,6 @@
return new DirectConsumer(this, processor);
}
- public boolean isAllowMultipleConsumers() {
- return allowMultipleConsumers;
- }
-
- public void setAllowMultipleConsumers(boolean allowMutlipleConsumers) {
- this.allowMultipleConsumers = allowMutlipleConsumers;
- }
-
public boolean isSingleton() {
return true;
}
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Wed Nov 18 15:41:29 2009
@@ -36,6 +36,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.FailedToStartRouteException;
import org.apache.camel.IsSingleton;
+import org.apache.camel.MultipleConsumersSupport;
import org.apache.camel.NoFactoryAvailableException;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
@@ -891,6 +892,7 @@
// we use a tree map so the routes will be ordered according to
startup order defined on the route
Map<Integer, StartupRouteHolder> inputs = new TreeMap<Integer,
StartupRouteHolder>();
+ // figure out the order in which the routes should be started
for (RouteService routeService : routeServices.values()) {
Boolean autoStart =
routeService.getRouteDefinition().isAutoStartup();
if (autoStart == null || autoStart) {
@@ -943,6 +945,27 @@
}
}
+ // check for clash with multiple consumers of the same endpoints
which is not allowed
+ List<Endpoint> routeInputs = new ArrayList<Endpoint>();
+ for (RouteService routeService : routeServices.values()) {
+ for (Consumer consumer : routeService.getInputs().values()) {
+ Endpoint endpoint = consumer.getEndpoint();
+
+ // is multiple consumers supported
+ boolean multipleConsumersSupported = false;
+ if (endpoint instanceof MultipleConsumersSupport) {
+ multipleConsumersSupported =
((MultipleConsumersSupport) endpoint).isMultipleConsumersSupported();
+ }
+
+ if (!multipleConsumersSupported &&
routeInputs.contains(endpoint)) {
+ throw new
FailedToStartRouteException(routeService.getId(),
+ "Multiple consumers for the same endpoint is now
allowed: " + endpoint);
+ } else {
+ routeInputs.add(endpoint);
+ }
+ }
+ }
+
// now start the inputs for all the route services as we have
prepared Camel
// yeah open the floods so messages can start flow into Camel
for (Map.Entry<Integer, StartupRouteHolder> entry :
inputs.entrySet()) {
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectEndpointTest.java
Wed Nov 18 15:41:29 2009
@@ -54,7 +54,6 @@
public void testDirectEndpointAgain() throws Exception {
final DirectEndpoint de = new DirectEndpoint("direct://foo");
de.setCamelContext(context);
- de.setAllowMultipleConsumers(false);
context.addRoutes(new RouteBuilder() {
@Override
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
Wed Nov 18 15:41:29 2009
@@ -31,9 +31,9 @@
container.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
-
from("direct:in?allowMultipleConsumers=false").to("mock:result");
+ from("direct:in").to("mock:result");
-
from("direct:in?allowMultipleConsumers=false").to("mock:result");
+ from("direct:in").to("mock:result");
}
});
Modified:
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectQueueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectQueueTest.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectQueueTest.java
(original)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/component/direct/DirectQueueTest.java
Wed Nov 18 15:41:29 2009
@@ -30,7 +30,7 @@
mock.expectedBodiesReceivedInAnyOrder("Hello World", "Bye World",
"Bar");
template.sendBody("direct:foo", "Hello World");
- template.sendBody("direct:foo?allowMultipleConsumers=false", "Bye
World");
+ template.sendBody("direct:foo", "Bye World");
template.sendBody("direct:bar", "Bar");
}
@@ -41,7 +41,7 @@
public void configure() throws Exception {
from("direct:foo").to("mock:result");
-
from("direct:bar?allowMultipleConsumers=false").to("mock:result");
+ from("direct:bar").to("mock:result");
}
};
}
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java?rev=881804&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java
Wed Nov 18 15:41:29 2009
@@ -0,0 +1,121 @@
+/**
+ * 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.camel.impl;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToStartRouteException;
+import org.apache.camel.MultipleConsumersSupport;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class MultipleConsumersSupportTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ public void testNotMultipleConsumersSupport() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ MyEndpoint my = new MyEndpoint();
+
+ from(my).to("mock:a");
+
+ from("direct:start").to("mock:result");
+
+ from(my).to("mock:b");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown exception");
+ } catch (FailedToStartRouteException e) {
+ assertTrue(e.getMessage().endsWith("Multiple consumers for the
same endpoint is now allowed: Endpoint[MyEndpoint]"));
+
+ }
+ }
+
+ public void testYesMultipleConsumersSupport() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ MyOtherEndpoint my = new MyOtherEndpoint();
+
+ from(my).to("mock:a");
+ from(my).to("mock:b");
+ }
+ });
+ // this one is allowing multiple consumers on the same endpoint so no
problem starting
+ context.start();
+ context.stop();
+ }
+
+ private class MyEndpoint extends DefaultEndpoint implements
MultipleConsumersSupport {
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public boolean isMultipleConsumersSupported() {
+ return false;
+ }
+
+ public Producer createProducer() throws Exception {
+ return null;
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new DefaultConsumer(this, processor);
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return "MyEndpoint";
+ }
+ }
+
+ private class MyOtherEndpoint extends DefaultEndpoint implements
MultipleConsumersSupport {
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public boolean isMultipleConsumersSupported() {
+ return true;
+ }
+
+ public Producer createProducer() throws Exception {
+ return null;
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new DefaultConsumer(this, processor);
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return "MyOtherEndpoint";
+ }
+ }
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MultipleConsumersSupportTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerStartTwiceTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerStartTwiceTest.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerStartTwiceTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerStartTwiceTest.java
Wed Nov 18 15:41:29 2009
@@ -31,7 +31,6 @@
//add the same route twice...
context.addRoutes(new RouteBuilder() {
public void configure() {
-
from("cxf:http://localhost:7070/test?serviceClass=org.apache.camel.component.cxf.HelloService")
.to("log:POJO");
}
@@ -40,9 +39,7 @@
context.addRoutes(new RouteBuilder() {
public void configure() {
-
- from(
-
"cxf:http://localhost:7070/test?serviceClass=org.apache.camel.component.cxf.HelloService")
+
from("cxf:http://localhost:7070/test?serviceClass=org.apache.camel.component.cxf.HelloService")
.to("log:POJO");
}
});
@@ -51,10 +48,10 @@
context.start();
fail("Expect to catch an exception here");
} catch (Exception ex) {
- assertTrue("Expect the exception message has a Soap errror",
ex.getMessage().equals("Soap 1.1 endpoint already registered on address
http://localhost:7070/test"));
- context.stop();
+ assertTrue(ex.getMessage().endsWith("Multiple consumers for the
same endpoint is now allowed: Endpoint[http://localhost:7070/test]"));
}
+ context.stop();
}
}
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java?rev=881804&view=auto
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java
(added)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java
Wed Nov 18 15:41:29 2009
@@ -0,0 +1,84 @@
+/**
+ * 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.camel.component.cxf;
+
+import org.apache.camel.FailedToStartRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class CxfMultipleConsumersSupportTest extends CamelTestSupport {
+
+ protected static final String SIMPLE_ENDPOINT_ADDRESS =
"http://localhost:28080/test";
+ protected static final String SIMPLE_ENDPOINT_URI = "cxf://" +
SIMPLE_ENDPOINT_ADDRESS
+ + "?serviceClass=org.apache.camel.component.cxf.HelloService";
+
+ protected static final String SIMPLE_OTHER_ADDRESS =
"http://localhost:28081/test";
+ protected static final String SIMPLE_OTHER_URI = "cxf://" +
SIMPLE_OTHER_ADDRESS
+ + "?serviceClass=org.apache.camel.component.cxf.HelloService";
+
+ @Test
+ public void testMultipleConsumersNotAllowed() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(SIMPLE_ENDPOINT_URI).to("mock:a");
+
+ from("direct:start").to("mock:result");
+
+ from(SIMPLE_ENDPOINT_URI).to("mock:b");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown an exception");
+ } catch (FailedToStartRouteException e) {
+ assertTrue(e.getMessage().endsWith("Multiple consumers for the
same endpoint is now allowed: Endpoint[http://localhost:28080/test]"));
+ }
+ }
+
+ @Test
+ public void testNoMultipleConsumers() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(SIMPLE_ENDPOINT_URI).to("mock:a");
+
+ from("direct:start").to("mock:result");
+
+ from(SIMPLE_OTHER_URI).to("mock:b");
+ }
+ });
+
+ // is allowed
+ context.start();
+
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+}
Propchange:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMultipleConsumersSupportTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
(original)
+++
camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsEndpoint.java
Wed Nov 18 15:41:29 2009
@@ -28,6 +28,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.MultipleConsumersSupport;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
import org.apache.camel.component.jms.requestor.Requestor;
@@ -51,7 +52,7 @@
* @version $Revision:520964 $
*/
@ManagedResource(description = "Managed JMS Endpoint")
-public class JmsEndpoint extends DefaultEndpoint implements
HeaderFilterStrategyAware, ManagementAware<JmsEndpoint> {
+public class JmsEndpoint extends DefaultEndpoint implements
HeaderFilterStrategyAware, ManagementAware<JmsEndpoint>,
MultipleConsumersSupport {
private HeaderFilterStrategy headerFilterStrategy;
private boolean pubSubDomain;
private JmsBinding binding;
@@ -205,6 +206,11 @@
return this;
}
+ public boolean isMultipleConsumersSupported() {
+ // only allow multiple consumers for pub sub domain (e.g. topics)
+ return isPubSubDomain();
+ }
+
// Properties
//
-------------------------------------------------------------------------
public HeaderFilterStrategy getHeaderFilterStrategy() {
Modified:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java
Wed Nov 18 15:41:29 2009
@@ -30,7 +30,7 @@
/**
* Tests filtering using Camel Test
- * @version $Revision: 724291 $
+ * @version $Revision: 724291 $
*/
// START SNIPPET: example
public class JmsFilterTest extends CamelTestSupport {
Copied:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
(from r881719,
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java&r1=881719&r2=881804&rev=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsFilterTest.java
(original)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsMultipleConsumersTest.java
Wed Nov 18 15:41:29 2009
@@ -14,71 +14,73 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.jms;
+package org.apache.camel.component.jms;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
+import org.apache.camel.FailedToStartRouteException;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.jms.JmsComponent;
-import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.CamelTestSupport;
/**
- * Tests filtering using Camel Test
- * @version $Revision: 724291 $
+ * @version $Revision$
*/
-// START SNIPPET: example
-public class JmsFilterTest extends CamelTestSupport {
+public class JmsMultipleConsumersTest extends CamelTestSupport {
- @EndpointInject(uri = "mock:result")
- protected MockEndpoint resultEndpoint;
+ public void testMultipleConsumersAllowed() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("jms:topic:foo").to("mock:foo");
- @Produce(uri = "direct:start")
- protected ProducerTemplate template;
+ from("direct:start").to("mock:result");
- public void testSendMatchingMessage() throws Exception {
- String expectedBody = "<matched/>";
+ from("jms:topic:foo").to("mock:bar");
+ }
+ });
+ context.start();
- resultEndpoint.expectedBodiesReceived(expectedBody);
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:bar").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
- template.sendBodyAndHeader(expectedBody, "foo", "bar");
+ template.sendBody("jms:topic:foo", "Hello World");
- resultEndpoint.assertIsSatisfied();
+ assertMockEndpointsSatisfied();
}
- public void testSendNotMatchingMessage() throws Exception {
- resultEndpoint.expectedMessageCount(0);
+ public void testMultipleConsumersNotAllowed() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("jms:queue:foo").to("mock:foo");
- template.sendBodyAndHeader("<notMatched/>", "foo",
"notMatchedHeaderValue");
+ from("direct:start").to("mock:result");
- resultEndpoint.assertIsSatisfied();
+ from("jms:queue:foo").to("mock:bar");
+ }
+ });
+ try {
+ context.start();
+ fail("Should have thrown an exception");
+ } catch (FailedToStartRouteException e) {
+ assertTrue(e.getMessage().endsWith("Multiple consumers for the
same endpoint is now allowed: Endpoint[jms://queue:foo]"));
+ }
}
-
+
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
-
- // connect to embedded ActiveMQ JMS broker
- ConnectionFactory connectionFactory =
- new ActiveMQConnectionFactory("vm://localhost");
- camelContext.addComponent("jms",
- JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
+
+ ConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("vm://localhost");
+ camelContext.addComponent("jms",
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
return camelContext;
}
-
+
@Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
- from("direct:start").to("jms:myQueue");
-
from("jms:myQueue").filter(header("foo").isEqualTo("bar")).to("mock:result");
- }
- };
+ public boolean isUseRouteBuilder() {
+ return false;
}
-}
-// END SNIPPET: example
+}
\ No newline at end of file
Modified:
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
(original)
+++
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaComponent.java
Wed Nov 18 15:41:29 2009
@@ -104,7 +104,7 @@
if (protocol != null) {
if (protocol.equals("tcp")) {
return createSocketEndpoint(uri, config);
- } else if (protocol.equals("udp") || protocol.equals("mcast") ||
protocol.equals("multicast")) {
+ } else if (config.isDatagramProtocol()) {
return createDatagramEndpoint(uri, config);
} else if (protocol.equals("vm")) {
return createVmEndpoint(uri, config);
Modified:
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
(original)
+++
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaConfiguration.java
Wed Nov 18 15:41:29 2009
@@ -185,5 +185,9 @@
public void setFilters(List<IoFilter> filters) {
this.filters = filters;
}
+
+ public boolean isDatagramProtocol() {
+ return protocol.equals("udp") || protocol.equals("mcast") ||
protocol.equals("multicast");
+ }
}
Modified:
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java?rev=881804&r1=881803&r2=881804&view=diff
==============================================================================
---
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
(original)
+++
camel/trunk/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaEndpoint.java
Wed Nov 18 15:41:29 2009
@@ -20,6 +20,7 @@
import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
+import org.apache.camel.MultipleConsumersSupport;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
@@ -35,14 +36,14 @@
*
* @version $Revision$
*/
-public class MinaEndpoint extends DefaultEndpoint {
+public class MinaEndpoint extends DefaultEndpoint implements
MultipleConsumersSupport {
+
/** The key of the IoSession which is stored in the message header*/
public static final transient String HEADER_MINA_IOSESSION =
"CamelMinaIoSession";
/** The socket address of local machine that received the message. */
public static final transient String HEADER_LOCAL_ADDRESS =
"CamelMinaLocalAddress";
/** The socket address of the remote machine that send the message. */
public static final transient String HEADER_REMOTE_ADDRESS =
"CamelMinaRemoteAddress";
-
private SocketAddress address;
private IoAcceptor acceptor;
@@ -93,6 +94,11 @@
return true;
}
+ public boolean isMultipleConsumersSupported() {
+ // only datagram should allow multiple consumers
+ return configuration.isDatagramProtocol();
+ }
+
// Properties
//
-------------------------------------------------------------------------
@@ -143,4 +149,5 @@
public void setConnectorConfig(IoConnectorConfig connectorConfig) {
this.connectorConfig = connectorConfig;
}
+
}