This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 37252db0e679c56b96d4027122592f50ff05f332 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Jan 20 13:54:59 2020 +0100 CAMEL-14418: camel-timer - Add option to turn on/off metadata --- .../camel-timer/src/main/docs/timer-component.adoc | 3 ++- .../camel/component/timer/TimerConsumer.java | 21 +++++++++-------- .../camel/component/timer/TimerEndpoint.java | 16 +++++++++++++ .../endpoint/dsl/TimerEndpointBuilderFactory.java | 26 ++++++++++++++++++++++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/components/camel-timer/src/main/docs/timer-component.adoc b/components/camel-timer/src/main/docs/timer-component.adoc index 67331c0..6d0ba5a 100644 --- a/components/camel-timer/src/main/docs/timer-component.adoc +++ b/components/camel-timer/src/main/docs/timer-component.adoc @@ -80,7 +80,7 @@ with the following path and query parameters: |=== -=== Query Parameters (13 parameters): +=== Query Parameters (14 parameters): [width="100%",cols="2,5,^1,2",options="header"] @@ -89,6 +89,7 @@ with the following path and query parameters: | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | *delay* (consumer) | The number of milliseconds to wait before the first event is generated. Should not be used in conjunction with the time option. The default value is 1000. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | long | *fixedRate* (consumer) | Events take place at approximately regular intervals, separated by the specified period. | false | boolean +| *includeMetadata* (consumer) | Whether to include metadata in the exchange such as fired time, timer name, timer count etc. This information is default included. | true | boolean | *period* (consumer) | If greater than 0, generate periodic events every period milliseconds. The default value is 1000. You can also specify time values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30 seconds), and 1h (1 hour). | 1000 | long | *repeatCount* (consumer) | Specifies a maximum limit of number of fires. So if you set it to 1, the timer will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | | ExceptionHandler diff --git a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java index 695ad11..5170dd9 100644 --- a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java +++ b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerConsumer.java @@ -175,15 +175,18 @@ public class TimerConsumer extends DefaultConsumer implements StartupListener, S protected void sendTimerExchange(long counter) { final Exchange exchange = endpoint.createExchange(); - exchange.setProperty(Exchange.TIMER_COUNTER, counter); - exchange.setProperty(Exchange.TIMER_NAME, endpoint.getTimerName()); - exchange.setProperty(Exchange.TIMER_TIME, endpoint.getTime()); - exchange.setProperty(Exchange.TIMER_PERIOD, endpoint.getPeriod()); - - Date now = new Date(); - exchange.setProperty(Exchange.TIMER_FIRED_TIME, now); - // also set now on in header with same key as quartz to be consistent - exchange.getIn().setHeader("firedTime", now); + + if (endpoint.isIncludeMetadata()) { + exchange.setProperty(Exchange.TIMER_COUNTER, counter); + exchange.setProperty(Exchange.TIMER_NAME, endpoint.getTimerName()); + exchange.setProperty(Exchange.TIMER_TIME, endpoint.getTime()); + exchange.setProperty(Exchange.TIMER_PERIOD, endpoint.getPeriod()); + + Date now = new Date(); + exchange.setProperty(Exchange.TIMER_FIRED_TIME, now); + // also set now on in header with same key as quartz to be consistent + exchange.getIn().setHeader("firedTime", now); + } if (log.isTraceEnabled()) { log.trace("Timer {} is firing #{} count", endpoint.getTimerName(), counter); diff --git a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java index 8cc57f8..e1d9490 100644 --- a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java +++ b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java @@ -61,6 +61,8 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS private String pattern; @UriParam(label = "advanced") private Timer timer; + @UriParam(defaultValue = "true") + private boolean includeMetadata = true; public TimerEndpoint() { } @@ -244,6 +246,20 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS return getComponent().getTimer(consumer); } + @ManagedAttribute(description = "Include metadata") + public boolean isIncludeMetadata() { + return includeMetadata; + } + + /** + * Whether to include metadata in the exchange such as fired time, timer name, timer count etc. + * This information is default included. + */ + @ManagedAttribute(description = "Include metadata") + public void setIncludeMetadata(boolean includeMetadata) { + this.includeMetadata = includeMetadata; + } + public void removeTimer(TimerConsumer consumer) { if (timer == null) { // only remove timer if we are not using a custom timer diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/TimerEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/TimerEndpointBuilderFactory.java index c409216..373a5c6 100644 --- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/TimerEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/TimerEndpointBuilderFactory.java @@ -139,6 +139,32 @@ public interface TimerEndpointBuilderFactory { return this; } /** + * Whether to include metadata in the exchange such as fired time, timer + * name, timer count etc. This information is default included. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: consumer + */ + default TimerEndpointBuilder includeMetadata(boolean includeMetadata) { + doSetProperty("includeMetadata", includeMetadata); + return this; + } + /** + * Whether to include metadata in the exchange such as fired time, timer + * name, timer count etc. This information is default included. + * + * The option will be converted to a <code>boolean</code> type. + * + * Default: true + * Group: consumer + */ + default TimerEndpointBuilder includeMetadata(String includeMetadata) { + doSetProperty("includeMetadata", includeMetadata); + return this; + } + /** * If greater than 0, generate periodic events every period * milliseconds. The default value is 1000. You can also specify time * values using units, such as 60s (60 seconds), 5m30s (5 minutes and 30