[
https://issues.apache.org/jira/browse/CAMEL-12542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16503488#comment-16503488
]
ASF GitHub Bot commented on CAMEL-12542:
----------------------------------------
ramu11 closed pull request #2359: CAMEL-12542:seda - Have a default queue size
limit
URL: https://github.com/apache/camel/pull/2359
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/camel-core/src/main/docs/seda-component.adoc
b/camel-core/src/main/docs/seda-component.adoc
index bb2ff0dd8de..8e7fbfa1658 100644
--- a/camel-core/src/main/docs/seda-component.adoc
+++ b/camel-core/src/main/docs/seda-component.adoc
@@ -46,7 +46,7 @@ The SEDA component supports 5 options which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
-| *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue
(i.e., the number of messages it can hold). | | int
+| *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue
(i.e., the number of messages it can hold). | 1000 | int
| *concurrentConsumers* (consumer) | Sets the default number of concurrent
threads processing exchanges. | 1 | int
| *defaultQueueFactory* (advanced) | Sets the default queue factory. | |
Exchange>
| *defaultBlockWhenFull* (producer) | Whether a thread that sends messages to
a full SEDA queue will block until the queue's capacity is no longer exhausted.
By default, an exception will be thrown stating that the queue is full. By
enabling this option, the calling thread will instead block and wait until the
message can be accepted. | false | boolean
diff --git a/camel-core/src/main/docs/stub-component.adoc
b/camel-core/src/main/docs/stub-component.adoc
index 99232743cbb..b7bcc8ced40 100644
--- a/camel-core/src/main/docs/stub-component.adoc
+++ b/camel-core/src/main/docs/stub-component.adoc
@@ -36,7 +36,7 @@ The Stub component supports 5 options which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
-| *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue
(i.e., the number of messages it can hold). | | int
+| *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue
(i.e., the number of messages it can hold). | 1000 | int
| *concurrentConsumers* (consumer) | Sets the default number of concurrent
threads processing exchanges. | 1 | int
| *defaultQueueFactory* (advanced) | Sets the default queue factory. | |
Exchange>
| *defaultBlockWhenFull* (producer) | Whether a thread that sends messages to
a full SEDA queue will block until the queue's capacity is no longer exhausted.
By default, an exception will be thrown stating that the queue is full. By
enabling this option, the calling thread will instead block and wait until the
message can be accepted. | false | boolean
diff --git a/camel-core/src/main/docs/vm-component.adoc
b/camel-core/src/main/docs/vm-component.adoc
index 3a043688666..e7da8df85a3 100644
--- a/camel-core/src/main/docs/vm-component.adoc
+++ b/camel-core/src/main/docs/vm-component.adoc
@@ -66,7 +66,7 @@ The VM component supports 5 options which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
-| *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue
(i.e., the number of messages it can hold). | | int
+| *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue
(i.e., the number of messages it can hold). | 1000 | int
| *concurrentConsumers* (consumer) | Sets the default number of concurrent
threads processing exchanges. | 1 | int
| *defaultQueueFactory* (advanced) | Sets the default queue factory. | |
Exchange>
| *defaultBlockWhenFull* (producer) | Whether a thread that sends messages to
a full SEDA queue will block until the queue's capacity is no longer exhausted.
By default, an exception will be thrown stating that the queue is full. By
enabling this option, the calling thread will instead block and wait until the
message can be accepted. | false | boolean
diff --git
a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
b/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
index fdb52ef6a43..3acc28500c1 100644
---
a/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
+++
b/camel-core/src/main/java/org/apache/camel/component/seda/SedaComponent.java
@@ -25,6 +25,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.impl.UriEndpointComponent;
import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.SedaConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,12 +36,12 @@
*/
public class SedaComponent extends UriEndpointComponent {
protected final Logger log = LoggerFactory.getLogger(getClass());
- protected final int maxConcurrentConsumers = 500;
+ protected final int maxConcurrentConsumers =
SedaConstants.MAX_CONCURRENT_CONSUMERS;
- @Metadata(label = "consumer", defaultValue = "1")
- protected int concurrentConsumers = 1;
- @Metadata(label = "advanced")
- protected int queueSize;
+ @Metadata(label = "consumer", defaultValue =
""+SedaConstants.CONCURRENT_CONSUMERS)
+ protected int concurrentConsumers = SedaConstants.CONCURRENT_CONSUMERS;
+ @Metadata(label = "advanced", defaultValue = ""+SedaConstants.QUEUE_SIZE )
+ protected int queueSize = SedaConstants.QUEUE_SIZE;
@Metadata(label = "advanced")
protected BlockingQueueFactory<Exchange> defaultQueueFactory = new
LinkedBlockingQueueFactory<>();
@Metadata(label = "producer")
@@ -128,7 +129,7 @@ public synchronized QueueReference
getOrCreateQueue(SedaEndpoint endpoint, Integ
if (size != null && !size.equals(ref.getSize())) {
// there is already a queue, so make sure the size matches
throw new IllegalArgumentException("Cannot use existing queue
" + key + " as the existing queue size "
- + (ref.getSize() != null ? ref.getSize() :
Integer.MAX_VALUE) + " does not match given queue size " + size);
+ + (ref.getSize() != null ? ref.getSize() :
SedaConstants.QUEUE_SIZE) + " does not match given queue size " + size);
}
// add the reference before returning queue
ref.addReference(endpoint);
diff --git a/camel-core/src/main/java/org/apache/camel/util/SedaConstants.java
b/camel-core/src/main/java/org/apache/camel/util/SedaConstants.java
new file mode 100644
index 00000000000..b6de163fd91
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/util/SedaConstants.java
@@ -0,0 +1,27 @@
+/**
+ * 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.util;
+
+public final class SedaConstants {
+
+ public static final int MAX_CONCURRENT_CONSUMERS = 500;
+ public static final int CONCURRENT_CONSUMERS = 1;
+ public static final int QUEUE_SIZE = 1000;
+ private SedaConstants() {
+ }
+
+}
diff --git
a/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
index 7aa0d817f40..9a8045b0ae0 100644
---
a/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
+++
b/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
@@ -20,12 +20,14 @@
import org.apache.camel.ContextTestSupport;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.SedaConstants;
/**
*
*/
public class SameSedaQueueSizeAndNoSizeTest extends ContextTestSupport {
-
+
+
public void testSameQueue() throws Exception {
for (int i = 0; i < 100; i++) {
template.sendBody("seda:foo", "" + i);
@@ -58,7 +60,7 @@ public void testSameQueueDifferentSizeBar() throws Exception {
fail("Should fail");
} catch (ResolveEndpointFailedException e) {
IllegalArgumentException ise =
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("Cannot use existing queue seda://bar as the existing
queue size " + Integer.MAX_VALUE + " does not match given queue size 200",
ise.getMessage());
+ assertEquals("Cannot use existing queue seda://bar as the existing
queue size " + SedaConstants.QUEUE_SIZE + " does not match given queue size
200", ise.getMessage());
}
}
diff --git
a/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java
index 80fa0900339..c14114e6173 100644
---
a/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java
+++
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaConfigureTest.java
@@ -21,11 +21,13 @@
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
+import org.apache.camel.util.SedaConstants;
/**
* @version
*/
public class SedaConfigureTest extends ContextTestSupport {
+
@SuppressWarnings("unchecked")
public void testBlockingQueueConfigured() throws Exception {
@@ -50,7 +52,7 @@ public void testDefaults() {
SedaEndpoint endpoint = resolveMandatoryEndpoint("seda:foo",
SedaEndpoint.class);
assertFalse("blockWhenFull: wrong default",
endpoint.isBlockWhenFull());
assertEquals("concurrentConsumers: wrong default", 1,
endpoint.getConcurrentConsumers());
- assertEquals("size (remainingCapacity): wrong default",
Integer.MAX_VALUE, endpoint.getSize());
+ assertEquals("size (remainingCapacity): wrong default",
SedaConstants.QUEUE_SIZE, endpoint.getSize());
assertEquals("timeout: wrong default", 30000L, endpoint.getTimeout());
}
}
diff --git
a/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
index 679e37223de..54a059ad715 100644
---
a/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
+++
b/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
@@ -27,11 +27,11 @@ public void testSedaDefaultUnboundedQueueSize() throws
Exception {
SedaEndpoint seda = context.getEndpoint("seda:foo",
SedaEndpoint.class);
assertEquals(0, seda.getQueue().size());
- for (int i = 0; i < 1200; i++) {
+ for (int i = 0; i < 1000; i++) {
template.sendBody("seda:foo", "Message " + i);
}
- assertEquals(1200, seda.getQueue().size());
+ assertEquals(1000, seda.getQueue().size());
}
public void testSedaDefaultBoundedQueueSize() throws Exception {
diff --git
a/camel-core/src/test/java/org/apache/camel/component/vm/SameVmQueueSizeAndNoSizeTest.java
b/camel-core/src/test/java/org/apache/camel/component/vm/SameVmQueueSizeAndNoSizeTest.java
index b2c2d01e886..3f9952f7088 100644
---
a/camel-core/src/test/java/org/apache/camel/component/vm/SameVmQueueSizeAndNoSizeTest.java
+++
b/camel-core/src/test/java/org/apache/camel/component/vm/SameVmQueueSizeAndNoSizeTest.java
@@ -20,11 +20,13 @@
import org.apache.camel.ContextTestSupport;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.SedaConstants;
/**
*
*/
public class SameVmQueueSizeAndNoSizeTest extends ContextTestSupport {
+
public void testSameQueue() throws Exception {
for (int i = 0; i < 100; i++) {
@@ -58,7 +60,7 @@ public void testSameQueueDifferentSizeBar() throws Exception {
fail("Should fail");
} catch (ResolveEndpointFailedException e) {
IllegalArgumentException ise =
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("Cannot use existing queue vm://bar as the existing
queue size " + Integer.MAX_VALUE + " does not match given queue size 200",
ise.getMessage());
+ assertEquals("Cannot use existing queue vm://bar as the existing
queue size " + SedaConstants.QUEUE_SIZE + " does not match given queue size
200", ise.getMessage());
}
}
diff --git
a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/seda/springboot/SedaComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/seda/springboot/SedaComponentConfiguration.java
index 286d69307c2..f45a518b6bf 100644
---
a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/seda/springboot/SedaComponentConfiguration.java
+++
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/seda/springboot/SedaComponentConfiguration.java
@@ -39,7 +39,7 @@
* Sets the default maximum capacity of the SEDA queue (i.e., the number of
* messages it can hold).
*/
- private Integer queueSize;
+ private Integer queueSize = 1000;
/**
* Sets the default number of concurrent threads processing exchanges.
*/
diff --git
a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/stub/springboot/StubComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/stub/springboot/StubComponentConfiguration.java
index 5efee17bd99..82b5a30b5ef 100644
---
a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/stub/springboot/StubComponentConfiguration.java
+++
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/stub/springboot/StubComponentConfiguration.java
@@ -39,7 +39,7 @@
* Sets the default maximum capacity of the SEDA queue (i.e., the number of
* messages it can hold).
*/
- private Integer queueSize;
+ private Integer queueSize = 1000;
/**
* Sets the default number of concurrent threads processing exchanges.
*/
diff --git
a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/vm/springboot/VmComponentConfiguration.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/vm/springboot/VmComponentConfiguration.java
index b497827885d..17f5b4c88c7 100644
---
a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/vm/springboot/VmComponentConfiguration.java
+++
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/component/vm/springboot/VmComponentConfiguration.java
@@ -39,7 +39,7 @@
* Sets the default maximum capacity of the SEDA queue (i.e., the number of
* messages it can hold).
*/
- private Integer queueSize;
+ private Integer queueSize = 1000;
/**
* Sets the default number of concurrent threads processing exchanges.
*/
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> seda - Have a default queue size limit
> --------------------------------------
>
> Key: CAMEL-12542
> URL: https://issues.apache.org/jira/browse/CAMEL-12542
> Project: Camel
> Issue Type: Improvement
> Components: camel-core
> Reporter: Claus Ibsen
> Assignee: Dmitry Volodin
> Priority: Major
> Fix For: 2.22.0
>
>
> The seda/vm queues are unbounded by default. But some users may fill up
> endless messages into these queues and hit OOME.
> We should possible set a default queue size of some reasonable size so that
> out of the box this wont happen.
> Maybe 1000 messages is a good default. People should not really store a very
> high number of in-flight messages in a JVM / CamelContext. Its not good
> practice.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)