This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 16b4401949d9 CAMEL-27025: camel-jpa - the consumer can bound its wait
for the lock of an entity with lockTimeout (#30184)
16b4401949d9 is described below
commit 16b4401949d97d8cc40af56a3a55a1c008044fcd
Author: Federico Mariani <[email protected]>
AuthorDate: Mon Nov 16 14:12:00 2026 +0100
CAMEL-27025: camel-jpa - the consumer can bound its wait for the lock of an
entity with lockTimeout (#30184)
* CAMEL-27025: camel-jpa - the consumer can bound its wait for the lock of
an entity with lockTimeout
The consumer locked each entity without a lock timeout, so on PostgreSQL
(no lock_timeout by default) a poll
waited until the transaction holding the row lock ended. A transaction that
does not end, such as the one of a
connection lost without the database noticing, stopped the consumer, and a
JDBC socket timeout left one more
session waiting for the lock at each poll.
The new consumer option lockTimeout gives the lock the
jakarta.persistence.lock.timeout hint; Hibernate applies it
on PostgreSQL with lock_timeout, so the database cancels the wait. The
default does not change. The documentation
describes the case, lockTimeout, skipLockedEntity, what a failed lock does
on PostgreSQL, and
idle_in_transaction_session_timeout.
* CAMEL-27025: camel-jpa - reject a negative lockTimeout, give the NOWAIT
hint as an Integer, document the entities routed again on PostgreSQL
A negative lockTimeout gave no hint, so the lock waited for ever. The URI
does not guard it: -1, -1s and -PT1S
convert to a negative duration. JpaConsumer.doInit now rejects it with an
IllegalArgumentException, which covers the
URI, the endpoint DSL and both setters.
The skipLockedEntity hint is now the Integer 0, like the lockTimeout hint,
instead of the Long 0L. OpenJPA and
Hibernate take either type, so nothing changes at runtime.
On PostgreSQL a lock that times out rolls back the poll, so the entities
ahead of the locked one are routed again by
every poll for as long as the lock is held. The documentation and the
option description now say so, and the route
must be idempotent; JpaConsumerLockTimeoutIT shows it.
---
.../org/apache/camel/catalog/components/jpa.json | 75 +++----
.../apache/camel/catalog/docs/jpa-component.adoc | 34 +++
components/camel-jpa/pom.xml | 13 ++
.../camel/component/jpa/JpaEndpointConfigurer.java | 6 +
.../camel/component/jpa/JpaEndpointUriFactory.java | 3 +-
.../org/apache/camel/component/jpa/jpa.json | 75 +++----
.../camel-jpa/src/main/docs/jpa-component.adoc | 34 +++
.../apache/camel/component/jpa/JpaConsumer.java | 27 ++-
.../apache/camel/component/jpa/JpaEndpoint.java | 21 ++
.../component/jpa/JpaConsumerLockTimeoutIT.java | 229 +++++++++++++++++++++
.../component/jpa/JpaConsumerLockTimeoutTest.java | 137 ++++++++++++
.../camel/component/jpa/lock-timeout-item-orm.xml | 33 +++
.../endpoint/dsl/JpaEndpointBuilderFactory.java | 54 +++++
13 files changed, 665 insertions(+), 76 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jpa.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jpa.json
index 4750dd92e65d..84c5a6a6ecff 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jpa.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/jpa.json
@@ -60,42 +60,43 @@
"consumeLockEntity": { "index": 10, "kind": "parameter", "displayName":
"Consume Lock Entity", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Specifies whether to set an exclusive lock on each entity bean while
processing the results from polling." },
"deleteHandler": { "index": 11, "kind": "parameter", "displayName":
"Delete Handler", "group": "consumer", "label": "consumer", "required": false,
"type": "object", "javaType":
"org.apache.camel.component.jpa.DeleteHandler<java.lang.Object>", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
DeleteHandler to delete the row after the consumer is done processing the
exchange" },
"lockModeType": { "index": 12, "kind": "parameter", "displayName": "Lock
Mode Type", "group": "consumer", "label": "consumer", "required": false,
"type": "enum", "javaType": "jakarta.persistence.LockModeType", "enum": [
"READ", "WRITE", "OPTIMISTIC", "OPTIMISTIC_FORCE_INCREMENT",
"PESSIMISTIC_READ", "PESSIMISTIC_WRITE", "PESSIMISTIC_FORCE_INCREMENT", "NONE"
], "deprecated": false, "autowired": false, "secret": false, "defaultValue":
"PESSIMISTIC_WRITE", "description": "To configure t [...]
- "maxMessagesPerPoll": { "index": 13, "kind": "parameter", "displayName":
"Max Messages Per Poll", "group": "consumer", "label": "consumer", "required":
false, "type": "integer", "javaType": "int", "deprecated": false, "autowired":
false, "secret": false, "description": "An integer value to define the maximum
number of messages to gather per poll. By default, no maximum is set. It can be
used to avoid polling many thousands of messages when starting up the server.
Set a value of 0 or [...]
- "preDeleteHandler": { "index": 14, "kind": "parameter", "displayName":
"Pre Delete Handler", "group": "consumer", "label": "consumer", "required":
false, "type": "object", "javaType":
"org.apache.camel.component.jpa.DeleteHandler<java.lang.Object>", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
Pre-DeleteHandler to delete the row after the consumer has read the entity." },
- "sendEmptyMessageWhenIdle": { "index": 15, "kind": "parameter",
"displayName": "Send Empty Message When Idle", "group": "consumer", "label":
"consumer", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "description": "If the polling consumer did not poll any files, you can
enable this option to send an empty message (no body) instead." },
- "skipLockedEntity": { "index": 16, "kind": "parameter", "displayName":
"Skip Locked Entity", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description": "To
configure whether to use NOWAIT on lock and silently skip the entity." },
- "transacted": { "index": 17, "kind": "parameter", "displayName":
"Transacted", "group": "consumer", "label": "consumer", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether to run
the consumer in transacted mode, by which all messages will either commit or
rollback, when the entire batch has been processed. The default behavior
(false) is to commit all the previously succ [...]
- "bridgeErrorHandler": { "index": 18, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
- "exceptionHandler": { "index": 19, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By de [...]
- "exchangePattern": { "index": 20, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
- "parameters": { "index": 21, "kind": "parameter", "displayName":
"Parameters", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "parameters.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "This key\/value mapping is used for building the query
parameters. It is expected to be of the generic type java.util.Map wher [...]
- "pollStrategy": { "index": 22, "kind": "parameter", "displayName": "Poll
Strategy", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false,
"autowired": false, "secret": false, "description": "A pluggable
org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your
custom implementation to control error handling usually occurred during the po
[...]
- "findEntity": { "index": 23, "kind": "parameter", "displayName": "Find
Entity", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, then the
producer will find a single entity by using the message body as a key and
entityType as the class type. This can be used instead of a query to find a
single entity." },
- "firstResult": { "index": 24, "kind": "parameter", "displayName": "First
Result", "group": "producer", "label": "producer", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": -1, "description": "Set the position of the
first result to retrieve." },
- "flushOnSend": { "index": 25, "kind": "parameter", "displayName": "Flush
On Send", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": true, "description": "Flushes the
EntityManager after the entity bean has been persisted." },
- "outputTarget": { "index": 26, "kind": "parameter", "displayName": "Output
Target", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "To put the query (or find) result in a
header or property instead of the body. If the value starts with the prefix
property:, put the result into the so named property, otherwise into the
header." },
- "remove": { "index": 27, "kind": "parameter", "displayName": "Remove",
"group": "producer", "label": "producer", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Indicates to use
entityManager.remove(entity)." },
- "singleResult": { "index": 28, "kind": "parameter", "displayName": "Single
Result", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, a query or
a find which would return no results or more than one result, will throw an
exception instead." },
- "useExecuteUpdate": { "index": 29, "kind": "parameter", "displayName":
"Use Execute Update", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure whether to
use executeUpdate() when producer executes a query. When you use INSERT, UPDATE
or a DELETE statement as a named query, you need to specify this option to
'true'." },
- "usePersist": { "index": 30, "kind": "parameter", "displayName": "Use
Persist", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Indicates to use
entityManager.persist(entity) instead of entityManager.merge(entity). Note:
entityManager.persist(entity) doesn't work for detached entities (where the
EntityManager has to execute an UPDATE [...]
- "lazyStartProducer": { "index": 31, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
- "usePassedInEntityManager": { "index": 32, "kind": "parameter",
"displayName": "Use Passed In Entity Manager", "group": "producer (advanced)",
"label": "producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "If set to true, then Camel will use the
EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the
configured entity manager on the component\/ [...]
- "entityManagerProperties": { "index": 33, "kind": "parameter",
"displayName": "Entity Manager Properties", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "emf.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "Additional properties for the entity manager to use. This is a
multi-value option with prefix: emf." },
- "sharedEntityManager": { "index": 34, "kind": "parameter", "displayName":
"Shared Entity Manager", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to use Spring's SharedEntityManager for the consumer\/producer. Note
in most cases, joinTransaction should be set to false as this is not an
EXTENDED EntityManager." },
- "backoffErrorThreshold": { "index": 35, "kind": "parameter",
"displayName": "Backoff Error Threshold", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "integer", "javaType": "int",
"deprecated": false, "autowired": false, "secret": false, "description": "The
number of subsequent error polls (failed due some error) that should happen
before the backoffMultipler should kick-in." },
- "backoffIdleThreshold": { "index": 36, "kind": "parameter", "displayName":
"Backoff Idle Threshold", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "The number of subsequent
idle polls that should happen before the backoffMultipler should kick-in." },
- "backoffMultiplier": { "index": 37, "kind": "parameter", "displayName":
"Backoff Multiplier", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "To let the scheduled
polling consumer backoff if there has been a number of subsequent idles\/errors
in a row. The multiplier is then the number of polls that will be skipped
before the next actual attempt is h [...]
- "delay": { "index": 38, "kind": "parameter", "displayName": "Delay",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 500, "description": "Milliseconds before the
next poll." },
- "greedy": { "index": 39, "kind": "parameter", "displayName": "Greedy",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If greedy is enabled,
then the ScheduledPollConsumer will run immediately again, if the previous run
polled 1 or more messages." },
- "healthCheckMaxPollDuration": { "index": 40, "kind": "parameter",
"displayName": "Health Check Max Poll Duration", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "duration", "javaType":
"long", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "0", "description": "How long a poll may run before the health
check of the consumer reports DOWN. The health check is otherwise based on the
polls that are done, so it stays UP while a p [...]
- "initialDelay": { "index": 41, "kind": "parameter", "displayName":
"Initial Delay", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": 1000, "description":
"Milliseconds before the first poll starts." },
- "repeatCount": { "index": 42, "kind": "parameter", "displayName": "Repeat
Count", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 0, "description": "Specifies a maximum limit
of number of fires. So if you set it to 1, the scheduler 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." },
- "runLoggingLevel": { "index": 43, "kind": "parameter", "displayName": "Run
Logging Level", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "enum", "javaType": "org.apache.camel.LoggingLevel",
"enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "TRACE",
"description": "The consumer logs a start\/complete log line when it polls.
This option allows you to configure the log [...]
- "scheduledExecutorService": { "index": 44, "kind": "parameter",
"displayName": "Scheduled Executor Service", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "object", "javaType":
"java.util.concurrent.ScheduledExecutorService", "deprecated": false,
"autowired": false, "secret": false, "description": "Allows for configuring a
custom\/shared thread pool to use for the consumer. By default each consumer
has its own single threaded thread pool." },
- "scheduler": { "index": 45, "kind": "parameter", "displayName":
"Scheduler", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "object", "javaType": "java.lang.Object", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "none", "description": "To
use a cron scheduler from either camel-spring or camel-quartz component. Use
value spring or quartz for built in scheduler" },
- "schedulerProperties": { "index": 46, "kind": "parameter", "displayName":
"Scheduler Properties", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "scheduler.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "To configure additional properties when using a custom
scheduler or any of the Quartz, Spring based scheduler. This i [...]
- "startScheduler": { "index": 47, "kind": "parameter", "displayName":
"Start Scheduler", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Whether the scheduler should be auto started." },
- "timeUnit": { "index": 48, "kind": "parameter", "displayName": "Time
Unit", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "enum", "javaType": "java.util.concurrent.TimeUnit", "enum": [
"NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS",
"DAYS" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "MILLISECONDS", "description": "Time unit for initialDelay and
delay options." },
- "useFixedDelay": { "index": 49, "kind": "parameter", "displayName": "Use
Fixed Delay", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in
JDK for details." }
+ "lockTimeout": { "index": 13, "kind": "parameter", "displayName": "Lock
Timeout", "group": "consumer", "label": "consumer", "required": false, "type":
"duration", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "0", "description": "How long the consumer
waits for the lock of an entity (see consumeLockEntity) that another
transaction holds. It is given to the JPA provider as the
jakarta.persistence.lock.timeout hint, which the provider app [...]
+ "maxMessagesPerPoll": { "index": 14, "kind": "parameter", "displayName":
"Max Messages Per Poll", "group": "consumer", "label": "consumer", "required":
false, "type": "integer", "javaType": "int", "deprecated": false, "autowired":
false, "secret": false, "description": "An integer value to define the maximum
number of messages to gather per poll. By default, no maximum is set. It can be
used to avoid polling many thousands of messages when starting up the server.
Set a value of 0 or [...]
+ "preDeleteHandler": { "index": 15, "kind": "parameter", "displayName":
"Pre Delete Handler", "group": "consumer", "label": "consumer", "required":
false, "type": "object", "javaType":
"org.apache.camel.component.jpa.DeleteHandler<java.lang.Object>", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
Pre-DeleteHandler to delete the row after the consumer has read the entity." },
+ "sendEmptyMessageWhenIdle": { "index": 16, "kind": "parameter",
"displayName": "Send Empty Message When Idle", "group": "consumer", "label":
"consumer", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "description": "If the polling consumer did not poll any files, you can
enable this option to send an empty message (no body) instead." },
+ "skipLockedEntity": { "index": 17, "kind": "parameter", "displayName":
"Skip Locked Entity", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description": "To
configure whether to use NOWAIT on lock and silently skip the entity." },
+ "transacted": { "index": 18, "kind": "parameter", "displayName":
"Transacted", "group": "consumer", "label": "consumer", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether to run
the consumer in transacted mode, by which all messages will either commit or
rollback, when the entire batch has been processed. The default behavior
(false) is to commit all the previously succ [...]
+ "bridgeErrorHandler": { "index": 19, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
+ "exceptionHandler": { "index": 20, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By de [...]
+ "exchangePattern": { "index": 21, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
+ "parameters": { "index": 22, "kind": "parameter", "displayName":
"Parameters", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "parameters.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "This key\/value mapping is used for building the query
parameters. It is expected to be of the generic type java.util.Map wher [...]
+ "pollStrategy": { "index": 23, "kind": "parameter", "displayName": "Poll
Strategy", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false,
"autowired": false, "secret": false, "description": "A pluggable
org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your
custom implementation to control error handling usually occurred during the po
[...]
+ "findEntity": { "index": 24, "kind": "parameter", "displayName": "Find
Entity", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, then the
producer will find a single entity by using the message body as a key and
entityType as the class type. This can be used instead of a query to find a
single entity." },
+ "firstResult": { "index": 25, "kind": "parameter", "displayName": "First
Result", "group": "producer", "label": "producer", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": -1, "description": "Set the position of the
first result to retrieve." },
+ "flushOnSend": { "index": 26, "kind": "parameter", "displayName": "Flush
On Send", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": true, "description": "Flushes the
EntityManager after the entity bean has been persisted." },
+ "outputTarget": { "index": 27, "kind": "parameter", "displayName": "Output
Target", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "To put the query (or find) result in a
header or property instead of the body. If the value starts with the prefix
property:, put the result into the so named property, otherwise into the
header." },
+ "remove": { "index": 28, "kind": "parameter", "displayName": "Remove",
"group": "producer", "label": "producer", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Indicates to use
entityManager.remove(entity)." },
+ "singleResult": { "index": 29, "kind": "parameter", "displayName": "Single
Result", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, a query or
a find which would return no results or more than one result, will throw an
exception instead." },
+ "useExecuteUpdate": { "index": 30, "kind": "parameter", "displayName":
"Use Execute Update", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure whether to
use executeUpdate() when producer executes a query. When you use INSERT, UPDATE
or a DELETE statement as a named query, you need to specify this option to
'true'." },
+ "usePersist": { "index": 31, "kind": "parameter", "displayName": "Use
Persist", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Indicates to use
entityManager.persist(entity) instead of entityManager.merge(entity). Note:
entityManager.persist(entity) doesn't work for detached entities (where the
EntityManager has to execute an UPDATE [...]
+ "lazyStartProducer": { "index": 32, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
+ "usePassedInEntityManager": { "index": 33, "kind": "parameter",
"displayName": "Use Passed In Entity Manager", "group": "producer (advanced)",
"label": "producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "If set to true, then Camel will use the
EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the
configured entity manager on the component\/ [...]
+ "entityManagerProperties": { "index": 34, "kind": "parameter",
"displayName": "Entity Manager Properties", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "emf.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "Additional properties for the entity manager to use. This is a
multi-value option with prefix: emf." },
+ "sharedEntityManager": { "index": 35, "kind": "parameter", "displayName":
"Shared Entity Manager", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to use Spring's SharedEntityManager for the consumer\/producer. Note
in most cases, joinTransaction should be set to false as this is not an
EXTENDED EntityManager." },
+ "backoffErrorThreshold": { "index": 36, "kind": "parameter",
"displayName": "Backoff Error Threshold", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "integer", "javaType": "int",
"deprecated": false, "autowired": false, "secret": false, "description": "The
number of subsequent error polls (failed due some error) that should happen
before the backoffMultipler should kick-in." },
+ "backoffIdleThreshold": { "index": 37, "kind": "parameter", "displayName":
"Backoff Idle Threshold", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "The number of subsequent
idle polls that should happen before the backoffMultipler should kick-in." },
+ "backoffMultiplier": { "index": 38, "kind": "parameter", "displayName":
"Backoff Multiplier", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "To let the scheduled
polling consumer backoff if there has been a number of subsequent idles\/errors
in a row. The multiplier is then the number of polls that will be skipped
before the next actual attempt is h [...]
+ "delay": { "index": 39, "kind": "parameter", "displayName": "Delay",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 500, "description": "Milliseconds before the
next poll." },
+ "greedy": { "index": 40, "kind": "parameter", "displayName": "Greedy",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If greedy is enabled,
then the ScheduledPollConsumer will run immediately again, if the previous run
polled 1 or more messages." },
+ "healthCheckMaxPollDuration": { "index": 41, "kind": "parameter",
"displayName": "Health Check Max Poll Duration", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "duration", "javaType":
"long", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "0", "description": "How long a poll may run before the health
check of the consumer reports DOWN. The health check is otherwise based on the
polls that are done, so it stays UP while a p [...]
+ "initialDelay": { "index": 42, "kind": "parameter", "displayName":
"Initial Delay", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": 1000, "description":
"Milliseconds before the first poll starts." },
+ "repeatCount": { "index": 43, "kind": "parameter", "displayName": "Repeat
Count", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 0, "description": "Specifies a maximum limit
of number of fires. So if you set it to 1, the scheduler 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." },
+ "runLoggingLevel": { "index": 44, "kind": "parameter", "displayName": "Run
Logging Level", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "enum", "javaType": "org.apache.camel.LoggingLevel",
"enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "TRACE",
"description": "The consumer logs a start\/complete log line when it polls.
This option allows you to configure the log [...]
+ "scheduledExecutorService": { "index": 45, "kind": "parameter",
"displayName": "Scheduled Executor Service", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "object", "javaType":
"java.util.concurrent.ScheduledExecutorService", "deprecated": false,
"autowired": false, "secret": false, "description": "Allows for configuring a
custom\/shared thread pool to use for the consumer. By default each consumer
has its own single threaded thread pool." },
+ "scheduler": { "index": 46, "kind": "parameter", "displayName":
"Scheduler", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "object", "javaType": "java.lang.Object", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "none", "description": "To
use a cron scheduler from either camel-spring or camel-quartz component. Use
value spring or quartz for built in scheduler" },
+ "schedulerProperties": { "index": 47, "kind": "parameter", "displayName":
"Scheduler Properties", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "scheduler.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "To configure additional properties when using a custom
scheduler or any of the Quartz, Spring based scheduler. This i [...]
+ "startScheduler": { "index": 48, "kind": "parameter", "displayName":
"Start Scheduler", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Whether the scheduler should be auto started." },
+ "timeUnit": { "index": 49, "kind": "parameter", "displayName": "Time
Unit", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "enum", "javaType": "java.util.concurrent.TimeUnit", "enum": [
"NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS",
"DAYS" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "MILLISECONDS", "description": "Time unit for initialDelay and
delay options." },
+ "useFixedDelay": { "index": 50, "kind": "parameter", "displayName": "Use
Fixed Delay", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in
JDK for details." }
}
}
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jpa-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jpa-component.adoc
index af156f128bb8..891d1dd8ac65 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jpa-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/jpa-component.adoc
@@ -117,6 +117,40 @@ or select the entity instead.
If you are consuming a lot of rows (100K+) and experience `OutOfMemory`
problems, you should set the `maximumResults` to a sensible value.
+=== Locking the consumed entities
+
+With `consumeLockEntity=true` (the default), the consumer locks each entity
before it routes it, with the
+`lockModeType` (by default `PESSIMISTIC_WRITE`, a `SELECT ... FOR UPDATE` on
most databases), and holds the lock until
+the poll commits. This keeps two consumers from consuming the same entity.
+
+When another transaction holds the lock of an entity, the poll waits for it,
as long as the database lets it.
+PostgreSQL, for one, has no lock timeout by default (`lock_timeout` is 0): the
poll waits until the other transaction
+ends. A transaction that does not end then stops the consumer. This happens
when a client, possibly another consumer,
+loses its connection without the database noticing, after a network failure or
a NAT timeout: PostgreSQL keeps its
+session `idle in transaction`, with its locks, until TCP keepalive gives up on
the client, about two hours with the
+defaults of Linux. A socket timeout of the JDBC driver ends the poll, but not
its wait on the database: each poll leaves
+one more session waiting for the lock.
+
+The consumer waits for at most `lockTimeout`, or not at all with
`skipLockedEntity=true`. The JPA provider applies
+`lockTimeout` if it can with the database: Hibernate 7.4, for one, sets
`lock_timeout` for the lock on PostgreSQL, so the
+database itself cancels the wait.
+
+What happens to a lock that the consumer does not get depends on the database:
+
+* When the transaction can go on, the JPA provider reports a
`LockTimeoutException`: the consumer skips the entity and
+routes the next one.
+* On PostgreSQL, the failed lock aborts the transaction, and the JPA provider
reports a `PessimisticLockException`: the
+consumer routes no more entities in this poll, and the poll is rolled back.
The entities that the poll routed before
+the locked one are not consumed, so the next poll routes them again. This
repeats on every poll for as long as the other
+transaction holds the lock: instead of waiting for the lock, the consumer
routes the entities ahead of the locked one
+again and again. The route must handle these entities being routed again (be
idempotent), or the transaction holding
+the lock must be ended (see `idle_in_transaction_session_timeout` below).
+
+Either way, a later poll consumes the locked entity once its lock is released.
To release the locks of a transaction that
+does not end, set a timeout on the database, such as
`idle_in_transaction_session_timeout` on PostgreSQL, which ends such
+a session. Set it above the time a poll takes to route its entities: while the
route runs, the session of the poll is
+idle in transaction too.
+
=== Configuring EntityManagerFactory
It's strongly advised to configure the JPA component to use a specific
diff --git a/components/camel-jpa/pom.xml b/components/camel-jpa/pom.xml
index acbde35d6534..0f65ed783d52 100644
--- a/components/camel-jpa/pom.xml
+++ b/components/camel-jpa/pom.xml
@@ -132,6 +132,19 @@
<version>${awaitility-version}</version>
<scope>test</scope>
</dependency>
+ <!-- integration tests of the consumer locks against a real PostgreSQL
-->
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>${pgjdbc-driver-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-postgres</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
diff --git
a/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointConfigurer.java
b/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointConfigurer.java
index 9b6bd9e6abce..0031b7152850 100644
---
a/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointConfigurer.java
+++
b/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointConfigurer.java
@@ -64,6 +64,8 @@ public class JpaEndpointConfigurer extends
PropertyConfigurerSupport implements
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
case "lockmodetype":
case "lockModeType": target.setLockModeType(property(camelContext,
jakarta.persistence.LockModeType.class, value)); return true;
+ case "locktimeout":
+ case "lockTimeout": target.setLockTimeout(property(camelContext,
java.time.Duration.class, value).toMillis()); return true;
case "maxmessagesperpoll":
case "maxMessagesPerPoll":
target.setMaxMessagesPerPoll(property(camelContext, int.class, value)); return
true;
case "maximumresults":
@@ -162,6 +164,8 @@ public class JpaEndpointConfigurer extends
PropertyConfigurerSupport implements
case "lazyStartProducer": return boolean.class;
case "lockmodetype":
case "lockModeType": return jakarta.persistence.LockModeType.class;
+ case "locktimeout":
+ case "lockTimeout": return long.class;
case "maxmessagesperpoll":
case "maxMessagesPerPoll": return int.class;
case "maximumresults":
@@ -261,6 +265,8 @@ public class JpaEndpointConfigurer extends
PropertyConfigurerSupport implements
case "lazyStartProducer": return target.isLazyStartProducer();
case "lockmodetype":
case "lockModeType": return target.getLockModeType();
+ case "locktimeout":
+ case "lockTimeout": return target.getLockTimeout();
case "maxmessagesperpoll":
case "maxMessagesPerPoll": return target.getMaxMessagesPerPoll();
case "maximumresults":
diff --git
a/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointUriFactory.java
b/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointUriFactory.java
index f968238865f1..ef8dfc3a8362 100644
---
a/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointUriFactory.java
+++
b/components/camel-jpa/src/generated/java/org/apache/camel/component/jpa/JpaEndpointUriFactory.java
@@ -24,7 +24,7 @@ public class JpaEndpointUriFactory extends
org.apache.camel.support.component.En
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(50);
+ Set<String> props = new HashSet<>(51);
props.add("backoffErrorThreshold");
props.add("backoffIdleThreshold");
props.add("backoffMultiplier");
@@ -47,6 +47,7 @@ public class JpaEndpointUriFactory extends
org.apache.camel.support.component.En
props.add("joinTransaction");
props.add("lazyStartProducer");
props.add("lockModeType");
+ props.add("lockTimeout");
props.add("maxMessagesPerPoll");
props.add("maximumResults");
props.add("namedQuery");
diff --git
a/components/camel-jpa/src/generated/resources/META-INF/org/apache/camel/component/jpa/jpa.json
b/components/camel-jpa/src/generated/resources/META-INF/org/apache/camel/component/jpa/jpa.json
index 4750dd92e65d..84c5a6a6ecff 100644
---
a/components/camel-jpa/src/generated/resources/META-INF/org/apache/camel/component/jpa/jpa.json
+++
b/components/camel-jpa/src/generated/resources/META-INF/org/apache/camel/component/jpa/jpa.json
@@ -60,42 +60,43 @@
"consumeLockEntity": { "index": 10, "kind": "parameter", "displayName":
"Consume Lock Entity", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Specifies whether to set an exclusive lock on each entity bean while
processing the results from polling." },
"deleteHandler": { "index": 11, "kind": "parameter", "displayName":
"Delete Handler", "group": "consumer", "label": "consumer", "required": false,
"type": "object", "javaType":
"org.apache.camel.component.jpa.DeleteHandler<java.lang.Object>", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
DeleteHandler to delete the row after the consumer is done processing the
exchange" },
"lockModeType": { "index": 12, "kind": "parameter", "displayName": "Lock
Mode Type", "group": "consumer", "label": "consumer", "required": false,
"type": "enum", "javaType": "jakarta.persistence.LockModeType", "enum": [
"READ", "WRITE", "OPTIMISTIC", "OPTIMISTIC_FORCE_INCREMENT",
"PESSIMISTIC_READ", "PESSIMISTIC_WRITE", "PESSIMISTIC_FORCE_INCREMENT", "NONE"
], "deprecated": false, "autowired": false, "secret": false, "defaultValue":
"PESSIMISTIC_WRITE", "description": "To configure t [...]
- "maxMessagesPerPoll": { "index": 13, "kind": "parameter", "displayName":
"Max Messages Per Poll", "group": "consumer", "label": "consumer", "required":
false, "type": "integer", "javaType": "int", "deprecated": false, "autowired":
false, "secret": false, "description": "An integer value to define the maximum
number of messages to gather per poll. By default, no maximum is set. It can be
used to avoid polling many thousands of messages when starting up the server.
Set a value of 0 or [...]
- "preDeleteHandler": { "index": 14, "kind": "parameter", "displayName":
"Pre Delete Handler", "group": "consumer", "label": "consumer", "required":
false, "type": "object", "javaType":
"org.apache.camel.component.jpa.DeleteHandler<java.lang.Object>", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
Pre-DeleteHandler to delete the row after the consumer has read the entity." },
- "sendEmptyMessageWhenIdle": { "index": 15, "kind": "parameter",
"displayName": "Send Empty Message When Idle", "group": "consumer", "label":
"consumer", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "description": "If the polling consumer did not poll any files, you can
enable this option to send an empty message (no body) instead." },
- "skipLockedEntity": { "index": 16, "kind": "parameter", "displayName":
"Skip Locked Entity", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description": "To
configure whether to use NOWAIT on lock and silently skip the entity." },
- "transacted": { "index": 17, "kind": "parameter", "displayName":
"Transacted", "group": "consumer", "label": "consumer", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether to run
the consumer in transacted mode, by which all messages will either commit or
rollback, when the entire batch has been processed. The default behavior
(false) is to commit all the previously succ [...]
- "bridgeErrorHandler": { "index": 18, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
- "exceptionHandler": { "index": 19, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By de [...]
- "exchangePattern": { "index": 20, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
- "parameters": { "index": 21, "kind": "parameter", "displayName":
"Parameters", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "parameters.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "This key\/value mapping is used for building the query
parameters. It is expected to be of the generic type java.util.Map wher [...]
- "pollStrategy": { "index": 22, "kind": "parameter", "displayName": "Poll
Strategy", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false,
"autowired": false, "secret": false, "description": "A pluggable
org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your
custom implementation to control error handling usually occurred during the po
[...]
- "findEntity": { "index": 23, "kind": "parameter", "displayName": "Find
Entity", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, then the
producer will find a single entity by using the message body as a key and
entityType as the class type. This can be used instead of a query to find a
single entity." },
- "firstResult": { "index": 24, "kind": "parameter", "displayName": "First
Result", "group": "producer", "label": "producer", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": -1, "description": "Set the position of the
first result to retrieve." },
- "flushOnSend": { "index": 25, "kind": "parameter", "displayName": "Flush
On Send", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": true, "description": "Flushes the
EntityManager after the entity bean has been persisted." },
- "outputTarget": { "index": 26, "kind": "parameter", "displayName": "Output
Target", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "To put the query (or find) result in a
header or property instead of the body. If the value starts with the prefix
property:, put the result into the so named property, otherwise into the
header." },
- "remove": { "index": 27, "kind": "parameter", "displayName": "Remove",
"group": "producer", "label": "producer", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Indicates to use
entityManager.remove(entity)." },
- "singleResult": { "index": 28, "kind": "parameter", "displayName": "Single
Result", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, a query or
a find which would return no results or more than one result, will throw an
exception instead." },
- "useExecuteUpdate": { "index": 29, "kind": "parameter", "displayName":
"Use Execute Update", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure whether to
use executeUpdate() when producer executes a query. When you use INSERT, UPDATE
or a DELETE statement as a named query, you need to specify this option to
'true'." },
- "usePersist": { "index": 30, "kind": "parameter", "displayName": "Use
Persist", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Indicates to use
entityManager.persist(entity) instead of entityManager.merge(entity). Note:
entityManager.persist(entity) doesn't work for detached entities (where the
EntityManager has to execute an UPDATE [...]
- "lazyStartProducer": { "index": 31, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
- "usePassedInEntityManager": { "index": 32, "kind": "parameter",
"displayName": "Use Passed In Entity Manager", "group": "producer (advanced)",
"label": "producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "If set to true, then Camel will use the
EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the
configured entity manager on the component\/ [...]
- "entityManagerProperties": { "index": 33, "kind": "parameter",
"displayName": "Entity Manager Properties", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "emf.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "Additional properties for the entity manager to use. This is a
multi-value option with prefix: emf." },
- "sharedEntityManager": { "index": 34, "kind": "parameter", "displayName":
"Shared Entity Manager", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to use Spring's SharedEntityManager for the consumer\/producer. Note
in most cases, joinTransaction should be set to false as this is not an
EXTENDED EntityManager." },
- "backoffErrorThreshold": { "index": 35, "kind": "parameter",
"displayName": "Backoff Error Threshold", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "integer", "javaType": "int",
"deprecated": false, "autowired": false, "secret": false, "description": "The
number of subsequent error polls (failed due some error) that should happen
before the backoffMultipler should kick-in." },
- "backoffIdleThreshold": { "index": 36, "kind": "parameter", "displayName":
"Backoff Idle Threshold", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "The number of subsequent
idle polls that should happen before the backoffMultipler should kick-in." },
- "backoffMultiplier": { "index": 37, "kind": "parameter", "displayName":
"Backoff Multiplier", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "To let the scheduled
polling consumer backoff if there has been a number of subsequent idles\/errors
in a row. The multiplier is then the number of polls that will be skipped
before the next actual attempt is h [...]
- "delay": { "index": 38, "kind": "parameter", "displayName": "Delay",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 500, "description": "Milliseconds before the
next poll." },
- "greedy": { "index": 39, "kind": "parameter", "displayName": "Greedy",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If greedy is enabled,
then the ScheduledPollConsumer will run immediately again, if the previous run
polled 1 or more messages." },
- "healthCheckMaxPollDuration": { "index": 40, "kind": "parameter",
"displayName": "Health Check Max Poll Duration", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "duration", "javaType":
"long", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "0", "description": "How long a poll may run before the health
check of the consumer reports DOWN. The health check is otherwise based on the
polls that are done, so it stays UP while a p [...]
- "initialDelay": { "index": 41, "kind": "parameter", "displayName":
"Initial Delay", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": 1000, "description":
"Milliseconds before the first poll starts." },
- "repeatCount": { "index": 42, "kind": "parameter", "displayName": "Repeat
Count", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 0, "description": "Specifies a maximum limit
of number of fires. So if you set it to 1, the scheduler 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." },
- "runLoggingLevel": { "index": 43, "kind": "parameter", "displayName": "Run
Logging Level", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "enum", "javaType": "org.apache.camel.LoggingLevel",
"enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "TRACE",
"description": "The consumer logs a start\/complete log line when it polls.
This option allows you to configure the log [...]
- "scheduledExecutorService": { "index": 44, "kind": "parameter",
"displayName": "Scheduled Executor Service", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "object", "javaType":
"java.util.concurrent.ScheduledExecutorService", "deprecated": false,
"autowired": false, "secret": false, "description": "Allows for configuring a
custom\/shared thread pool to use for the consumer. By default each consumer
has its own single threaded thread pool." },
- "scheduler": { "index": 45, "kind": "parameter", "displayName":
"Scheduler", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "object", "javaType": "java.lang.Object", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "none", "description": "To
use a cron scheduler from either camel-spring or camel-quartz component. Use
value spring or quartz for built in scheduler" },
- "schedulerProperties": { "index": 46, "kind": "parameter", "displayName":
"Scheduler Properties", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "scheduler.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "To configure additional properties when using a custom
scheduler or any of the Quartz, Spring based scheduler. This i [...]
- "startScheduler": { "index": 47, "kind": "parameter", "displayName":
"Start Scheduler", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Whether the scheduler should be auto started." },
- "timeUnit": { "index": 48, "kind": "parameter", "displayName": "Time
Unit", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "enum", "javaType": "java.util.concurrent.TimeUnit", "enum": [
"NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS",
"DAYS" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "MILLISECONDS", "description": "Time unit for initialDelay and
delay options." },
- "useFixedDelay": { "index": 49, "kind": "parameter", "displayName": "Use
Fixed Delay", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in
JDK for details." }
+ "lockTimeout": { "index": 13, "kind": "parameter", "displayName": "Lock
Timeout", "group": "consumer", "label": "consumer", "required": false, "type":
"duration", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": "0", "description": "How long the consumer
waits for the lock of an entity (see consumeLockEntity) that another
transaction holds. It is given to the JPA provider as the
jakarta.persistence.lock.timeout hint, which the provider app [...]
+ "maxMessagesPerPoll": { "index": 14, "kind": "parameter", "displayName":
"Max Messages Per Poll", "group": "consumer", "label": "consumer", "required":
false, "type": "integer", "javaType": "int", "deprecated": false, "autowired":
false, "secret": false, "description": "An integer value to define the maximum
number of messages to gather per poll. By default, no maximum is set. It can be
used to avoid polling many thousands of messages when starting up the server.
Set a value of 0 or [...]
+ "preDeleteHandler": { "index": 15, "kind": "parameter", "displayName":
"Pre Delete Handler", "group": "consumer", "label": "consumer", "required":
false, "type": "object", "javaType":
"org.apache.camel.component.jpa.DeleteHandler<java.lang.Object>", "deprecated":
false, "autowired": false, "secret": false, "description": "To use a custom
Pre-DeleteHandler to delete the row after the consumer has read the entity." },
+ "sendEmptyMessageWhenIdle": { "index": 16, "kind": "parameter",
"displayName": "Send Empty Message When Idle", "group": "consumer", "label":
"consumer", "required": false, "type": "boolean", "javaType": "boolean",
"deprecated": false, "autowired": false, "secret": false, "defaultValue":
false, "description": "If the polling consumer did not poll any files, you can
enable this option to send an empty message (no body) instead." },
+ "skipLockedEntity": { "index": 17, "kind": "parameter", "displayName":
"Skip Locked Entity", "group": "consumer", "label": "consumer", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description": "To
configure whether to use NOWAIT on lock and silently skip the entity." },
+ "transacted": { "index": 18, "kind": "parameter", "displayName":
"Transacted", "group": "consumer", "label": "consumer", "required": false,
"type": "boolean", "javaType": "boolean", "deprecated": false, "autowired":
false, "secret": false, "defaultValue": false, "description": "Whether to run
the consumer in transacted mode, by which all messages will either commit or
rollback, when the entire batch has been processed. The default behavior
(false) is to commit all the previously succ [...]
+ "bridgeErrorHandler": { "index": 19, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
+ "exceptionHandler": { "index": 20, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By de [...]
+ "exchangePattern": { "index": 21, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
+ "parameters": { "index": 22, "kind": "parameter", "displayName":
"Parameters", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "parameters.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "This key\/value mapping is used for building the query
parameters. It is expected to be of the generic type java.util.Map wher [...]
+ "pollStrategy": { "index": 23, "kind": "parameter", "displayName": "Poll
Strategy", "group": "consumer (advanced)", "label": "consumer,advanced",
"required": false, "type": "object", "javaType":
"org.apache.camel.spi.PollingConsumerPollStrategy", "deprecated": false,
"autowired": false, "secret": false, "description": "A pluggable
org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your
custom implementation to control error handling usually occurred during the po
[...]
+ "findEntity": { "index": 24, "kind": "parameter", "displayName": "Find
Entity", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, then the
producer will find a single entity by using the message body as a key and
entityType as the class type. This can be used instead of a query to find a
single entity." },
+ "firstResult": { "index": 25, "kind": "parameter", "displayName": "First
Result", "group": "producer", "label": "producer", "required": false, "type":
"integer", "javaType": "int", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": -1, "description": "Set the position of the
first result to retrieve." },
+ "flushOnSend": { "index": 26, "kind": "parameter", "displayName": "Flush
On Send", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": true, "description": "Flushes the
EntityManager after the entity bean has been persisted." },
+ "outputTarget": { "index": 27, "kind": "parameter", "displayName": "Output
Target", "group": "producer", "label": "producer", "required": false, "type":
"string", "javaType": "java.lang.String", "deprecated": false, "autowired":
false, "secret": false, "description": "To put the query (or find) result in a
header or property instead of the body. If the value starts with the prefix
property:, put the result into the so named property, otherwise into the
header." },
+ "remove": { "index": 28, "kind": "parameter", "displayName": "Remove",
"group": "producer", "label": "producer", "required": false, "type": "boolean",
"javaType": "boolean", "deprecated": false, "autowired": false, "secret":
false, "defaultValue": false, "description": "Indicates to use
entityManager.remove(entity)." },
+ "singleResult": { "index": 29, "kind": "parameter", "displayName": "Single
Result", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If enabled, a query or
a find which would return no results or more than one result, will throw an
exception instead." },
+ "useExecuteUpdate": { "index": 30, "kind": "parameter", "displayName":
"Use Execute Update", "group": "producer", "label": "producer", "required":
false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false,
"autowired": false, "secret": false, "description": "To configure whether to
use executeUpdate() when producer executes a query. When you use INSERT, UPDATE
or a DELETE statement as a named query, you need to specify this option to
'true'." },
+ "usePersist": { "index": 31, "kind": "parameter", "displayName": "Use
Persist", "group": "producer", "label": "producer", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "Indicates to use
entityManager.persist(entity) instead of entityManager.merge(entity). Note:
entityManager.persist(entity) doesn't work for detached entities (where the
EntityManager has to execute an UPDATE [...]
+ "lazyStartProducer": { "index": 32, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produ [...]
+ "usePassedInEntityManager": { "index": 33, "kind": "parameter",
"displayName": "Use Passed In Entity Manager", "group": "producer (advanced)",
"label": "producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "If set to true, then Camel will use the
EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the
configured entity manager on the component\/ [...]
+ "entityManagerProperties": { "index": 34, "kind": "parameter",
"displayName": "Entity Manager Properties", "group": "advanced", "label":
"advanced", "required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "emf.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "Additional properties for the entity manager to use. This is a
multi-value option with prefix: emf." },
+ "sharedEntityManager": { "index": 35, "kind": "parameter", "displayName":
"Shared Entity Manager", "group": "advanced", "label": "advanced", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": false, "description":
"Whether to use Spring's SharedEntityManager for the consumer\/producer. Note
in most cases, joinTransaction should be set to false as this is not an
EXTENDED EntityManager." },
+ "backoffErrorThreshold": { "index": 36, "kind": "parameter",
"displayName": "Backoff Error Threshold", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "integer", "javaType": "int",
"deprecated": false, "autowired": false, "secret": false, "description": "The
number of subsequent error polls (failed due some error) that should happen
before the backoffMultipler should kick-in." },
+ "backoffIdleThreshold": { "index": 37, "kind": "parameter", "displayName":
"Backoff Idle Threshold", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "The number of subsequent
idle polls that should happen before the backoffMultipler should kick-in." },
+ "backoffMultiplier": { "index": 38, "kind": "parameter", "displayName":
"Backoff Multiplier", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "int", "deprecated": false,
"autowired": false, "secret": false, "description": "To let the scheduled
polling consumer backoff if there has been a number of subsequent idles\/errors
in a row. The multiplier is then the number of polls that will be skipped
before the next actual attempt is h [...]
+ "delay": { "index": 39, "kind": "parameter", "displayName": "Delay",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 500, "description": "Milliseconds before the
next poll." },
+ "greedy": { "index": 40, "kind": "parameter", "displayName": "Greedy",
"group": "scheduler", "label": "consumer,scheduler", "required": false, "type":
"boolean", "javaType": "boolean", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": false, "description": "If greedy is enabled,
then the ScheduledPollConsumer will run immediately again, if the previous run
polled 1 or more messages." },
+ "healthCheckMaxPollDuration": { "index": 41, "kind": "parameter",
"displayName": "Health Check Max Poll Duration", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "duration", "javaType":
"long", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "0", "description": "How long a poll may run before the health
check of the consumer reports DOWN. The health check is otherwise based on the
polls that are done, so it stays UP while a p [...]
+ "initialDelay": { "index": 42, "kind": "parameter", "displayName":
"Initial Delay", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "integer", "javaType": "long", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": 1000, "description":
"Milliseconds before the first poll starts." },
+ "repeatCount": { "index": 43, "kind": "parameter", "displayName": "Repeat
Count", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "integer", "javaType": "long", "deprecated": false, "autowired": false,
"secret": false, "defaultValue": 0, "description": "Specifies a maximum limit
of number of fires. So if you set it to 1, the scheduler 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." },
+ "runLoggingLevel": { "index": 44, "kind": "parameter", "displayName": "Run
Logging Level", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "enum", "javaType": "org.apache.camel.LoggingLevel",
"enum": [ "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF" ], "deprecated":
false, "autowired": false, "secret": false, "defaultValue": "TRACE",
"description": "The consumer logs a start\/complete log line when it polls.
This option allows you to configure the log [...]
+ "scheduledExecutorService": { "index": 45, "kind": "parameter",
"displayName": "Scheduled Executor Service", "group": "scheduler", "label":
"consumer,scheduler", "required": false, "type": "object", "javaType":
"java.util.concurrent.ScheduledExecutorService", "deprecated": false,
"autowired": false, "secret": false, "description": "Allows for configuring a
custom\/shared thread pool to use for the consumer. By default each consumer
has its own single threaded thread pool." },
+ "scheduler": { "index": 46, "kind": "parameter", "displayName":
"Scheduler", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "object", "javaType": "java.lang.Object", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "none", "description": "To
use a cron scheduler from either camel-spring or camel-quartz component. Use
value spring or quartz for built in scheduler" },
+ "schedulerProperties": { "index": 47, "kind": "parameter", "displayName":
"Scheduler Properties", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "object", "javaType":
"java.util.Map<java.lang.String, java.lang.Object>", "prefix": "scheduler.",
"multiValue": true, "deprecated": false, "autowired": false, "secret": false,
"description": "To configure additional properties when using a custom
scheduler or any of the Quartz, Spring based scheduler. This i [...]
+ "startScheduler": { "index": 48, "kind": "parameter", "displayName":
"Start Scheduler", "group": "scheduler", "label": "consumer,scheduler",
"required": false, "type": "boolean", "javaType": "boolean", "deprecated":
false, "autowired": false, "secret": false, "defaultValue": true,
"description": "Whether the scheduler should be auto started." },
+ "timeUnit": { "index": 49, "kind": "parameter", "displayName": "Time
Unit", "group": "scheduler", "label": "consumer,scheduler", "required": false,
"type": "enum", "javaType": "java.util.concurrent.TimeUnit", "enum": [
"NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS",
"DAYS" ], "deprecated": false, "autowired": false, "secret": false,
"defaultValue": "MILLISECONDS", "description": "Time unit for initialDelay and
delay options." },
+ "useFixedDelay": { "index": 50, "kind": "parameter", "displayName": "Use
Fixed Delay", "group": "scheduler", "label": "consumer,scheduler", "required":
false, "type": "boolean", "javaType": "boolean", "deprecated": false,
"autowired": false, "secret": false, "defaultValue": true, "description":
"Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in
JDK for details." }
}
}
diff --git a/components/camel-jpa/src/main/docs/jpa-component.adoc
b/components/camel-jpa/src/main/docs/jpa-component.adoc
index af156f128bb8..891d1dd8ac65 100644
--- a/components/camel-jpa/src/main/docs/jpa-component.adoc
+++ b/components/camel-jpa/src/main/docs/jpa-component.adoc
@@ -117,6 +117,40 @@ or select the entity instead.
If you are consuming a lot of rows (100K+) and experience `OutOfMemory`
problems, you should set the `maximumResults` to a sensible value.
+=== Locking the consumed entities
+
+With `consumeLockEntity=true` (the default), the consumer locks each entity
before it routes it, with the
+`lockModeType` (by default `PESSIMISTIC_WRITE`, a `SELECT ... FOR UPDATE` on
most databases), and holds the lock until
+the poll commits. This keeps two consumers from consuming the same entity.
+
+When another transaction holds the lock of an entity, the poll waits for it,
as long as the database lets it.
+PostgreSQL, for one, has no lock timeout by default (`lock_timeout` is 0): the
poll waits until the other transaction
+ends. A transaction that does not end then stops the consumer. This happens
when a client, possibly another consumer,
+loses its connection without the database noticing, after a network failure or
a NAT timeout: PostgreSQL keeps its
+session `idle in transaction`, with its locks, until TCP keepalive gives up on
the client, about two hours with the
+defaults of Linux. A socket timeout of the JDBC driver ends the poll, but not
its wait on the database: each poll leaves
+one more session waiting for the lock.
+
+The consumer waits for at most `lockTimeout`, or not at all with
`skipLockedEntity=true`. The JPA provider applies
+`lockTimeout` if it can with the database: Hibernate 7.4, for one, sets
`lock_timeout` for the lock on PostgreSQL, so the
+database itself cancels the wait.
+
+What happens to a lock that the consumer does not get depends on the database:
+
+* When the transaction can go on, the JPA provider reports a
`LockTimeoutException`: the consumer skips the entity and
+routes the next one.
+* On PostgreSQL, the failed lock aborts the transaction, and the JPA provider
reports a `PessimisticLockException`: the
+consumer routes no more entities in this poll, and the poll is rolled back.
The entities that the poll routed before
+the locked one are not consumed, so the next poll routes them again. This
repeats on every poll for as long as the other
+transaction holds the lock: instead of waiting for the lock, the consumer
routes the entities ahead of the locked one
+again and again. The route must handle these entities being routed again (be
idempotent), or the transaction holding
+the lock must be ended (see `idle_in_transaction_session_timeout` below).
+
+Either way, a later poll consumes the locked entity once its lock is released.
To release the locks of a transaction that
+does not end, set a timeout on the database, such as
`idle_in_transaction_session_timeout` on PostgreSQL, which ends such
+a session. Set it above the time a poll takes to route its entities: while the
route runs, the session of the poll is
+idle in transaction too.
+
=== Configuring EntityManagerFactory
It's strongly advised to configure the JPA component to use a specific
diff --git
a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
index 4384f4bc5a40..34eab709571c 100644
---
a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
+++
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
@@ -51,6 +51,7 @@ public class JpaConsumer extends
ScheduledBatchPollingConsumer {
private static final Logger LOG =
LoggerFactory.getLogger(JpaConsumer.class);
+ private static final String LOCK_TIMEOUT =
"jakarta.persistence.lock.timeout";
private static final Map<String, Object> NOWAIT;
private final EntityManagerFactory entityManagerFactory;
private final TransactionStrategy transactionStrategy;
@@ -66,11 +67,13 @@ public class JpaConsumer extends
ScheduledBatchPollingConsumer {
private Class<?> resultClass;
private boolean transacted;
private boolean skipLockedEntity;
+ private long lockTimeout;
private final AtomicBoolean notEntityWarned = new AtomicBoolean();
static {
NOWAIT = new HashMap<>();
- NOWAIT.put("jakarta.persistence.lock.timeout", 0L);
+ // an int of millis, like the hint given with lockTimeout
+ NOWAIT.put(LOCK_TIMEOUT, 0);
}
private static final class DataHolder {
@@ -362,6 +365,19 @@ public class JpaConsumer extends
ScheduledBatchPollingConsumer {
return skipLockedEntity;
}
+ /**
+ * Sets how long, in millis, to wait for the lock of an entity that
another transaction holds. It is given to the
+ * JPA provider as the <tt>jakarta.persistence.lock.timeout</tt> hint. The
default <tt>0</tt> sets no timeout. Not
+ * used with skipLockedEntity. Must not be negative.
+ */
+ public void setLockTimeout(long lockTimeout) {
+ this.lockTimeout = lockTimeout;
+ }
+
+ public long getLockTimeout() {
+ return lockTimeout;
+ }
+
// Implementation methods
//
-------------------------------------------------------------------------
@@ -386,6 +402,10 @@ public class JpaConsumer extends
ScheduledBatchPollingConsumer {
LOG.debug("Acquiring exclusive lock on entity: {}", entity);
if (isSkipLockedEntity()) {
entityManager.lock(entity, lockModeType, NOWAIT);
+ } else if (lockTimeout > 0) {
+ // the JPA hint is an int of millis
+ int millis = (int) Math.min(lockTimeout, Integer.MAX_VALUE);
+ entityManager.lock(entity, lockModeType, Map.of(LOCK_TIMEOUT,
millis));
} else {
entityManager.lock(entity, lockModeType);
}
@@ -565,6 +585,11 @@ public class JpaConsumer extends
ScheduledBatchPollingConsumer {
protected void doInit() throws Exception {
super.doInit();
+ if (lockTimeout < 0) {
+ // there is no hint for a negative value, so the lock would wait
for ever
+ throw new IllegalArgumentException("lockTimeout must be >= 0, was:
" + lockTimeout);
+ }
+
// need to setup entity manager first
if (getEndpoint().isSharedEntityManager()) {
this.entityManager =
SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
diff --git
a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
index 415ac99972ad..95314e54153a 100644
---
a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
+++
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaEndpoint.java
@@ -124,6 +124,8 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
private boolean transacted;
@UriParam(label = "consumer")
private boolean skipLockedEntity;
+ @UriParam(label = "consumer", defaultValue = "0", javaType =
"java.time.Duration")
+ private long lockTimeout;
@UriParam(label = "consumer")
private DeleteHandler<Object> deleteHandler;
@UriParam(label = "consumer")
@@ -188,6 +190,7 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
consumer.setResultClass(getResultClass());
consumer.setTransacted(isTransacted());
consumer.setSkipLockedEntity(isSkipLockedEntity());
+ consumer.setLockTimeout(getLockTimeout());
consumer.setDeleteHandler(getDeleteHandler());
consumer.setPreDeleteHandler(getPreDeleteHandler());
configureConsumer(consumer);
@@ -524,6 +527,24 @@ public class JpaEndpoint extends ScheduledPollEndpoint {
this.skipLockedEntity = skipLockedEntity;
}
+ public long getLockTimeout() {
+ return lockTimeout;
+ }
+
+ /**
+ * How long the consumer waits for the lock of an entity (see
consumeLockEntity) that another transaction holds. It
+ * is given to the JPA provider as the jakarta.persistence.lock.timeout
hint, which the provider applies if the
+ * database supports it: for example Hibernate on PostgreSQL sets
lock_timeout for the lock. The default 0 sets no
+ * timeout: the lock waits as long as the database lets it, which on
PostgreSQL is until the other transaction ends.
+ * A lock that times out is handled like one that skipLockedEntity could
not get. On PostgreSQL it rolls back the
+ * poll: the entities that the poll routed before the locked one are
routed again by each poll, for as long as the
+ * other transaction holds the lock, so the route must be idempotent. Not
used with skipLockedEntity, which does not
+ * wait at all. The value is in millis, and must not be negative.
+ */
+ public void setLockTimeout(long lockTimeout) {
+ this.lockTimeout = lockTimeout;
+ }
+
public DeleteHandler<Object> getDeleteHandler() {
return deleteHandler;
}
diff --git
a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaConsumerLockTimeoutIT.java
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaConsumerLockTimeoutIT.java
new file mode 100644
index 000000000000..9dd8dcbd50e3
--- /dev/null
+++
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaConsumerLockTimeoutIT.java
@@ -0,0 +1,229 @@
+/*
+ * 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.jpa;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
+import jakarta.persistence.PersistenceException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.postgres.services.PostgresService;
+import org.apache.camel.test.infra.postgres.services.PostgresServiceFactory;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
+import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+
+/**
+ * A row lock held by a transaction that does not end, such as the transaction
of a connection lost without the database
+ * noticing, makes the lock of the consumer wait: PostgreSQL has no lock
timeout by default. With lockTimeout the
+ * database cancels the wait, so the poll gives up instead of waiting, and
leaves no session waiting for the lock. A
+ * socket timeout of the JDBC driver would end the poll too, but its session
would go on waiting for the lock.
+ */
+class JpaConsumerLockTimeoutIT extends CamelTestSupport {
+
+ @RegisterExtension
+ static PostgresService service =
PostgresServiceFactory.createSingletonService();
+
+ private LocalContainerEntityManagerFactoryBean entityManagerFactoryBean;
+ private EntityManagerFactory entityManagerFactory;
+
+ /**
+ * Mapped in lock-timeout-item-orm.xml: an annotated entity would be
picked up by the OpenJPA persistence units of
+ * the other tests, which scan the test classes.
+ */
+ public static class LockTimeoutItem {
+ private Long id;
+
+ public LockTimeoutItem() {
+ }
+
+ public LockTimeoutItem(Long id) {
+ this.id = id;
+ }
+
+ public Long getId() {
+ return id;
+ }
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ // Hibernate, set up the way Spring Boot does it
+ entityManagerFactoryBean = new
LocalContainerEntityManagerFactoryBean();
+ entityManagerFactoryBean.setDataSource(
+ new DriverManagerDataSource(service.jdbcUrl(),
service.userName(), service.password()));
+ entityManagerFactoryBean.setJpaVendorAdapter(new
HibernateJpaVendorAdapter());
+
entityManagerFactoryBean.setManagedTypes(PersistenceManagedTypes.of(LockTimeoutItem.class.getName()));
+
entityManagerFactoryBean.setMappingResources("org/apache/camel/component/jpa/lock-timeout-item-orm.xml");
+ entityManagerFactoryBean.setPersistenceUnitName("lockTimeout");
+
entityManagerFactoryBean.setJpaPropertyMap(Map.of("hibernate.hbm2ddl.auto",
"create-drop"));
+ entityManagerFactoryBean.afterPropertiesSet();
+ entityManagerFactory = entityManagerFactoryBean.getObject();
+
+ CamelContext context = super.createCamelContext();
+ JpaComponent jpa = new JpaComponent();
+ jpa.setEntityManagerFactory(entityManagerFactory);
+ context.addComponent("jpa", jpa);
+ return context;
+ }
+
+ @Override
+ protected void doPostTearDown() throws Exception {
+ if (entityManagerFactoryBean != null) {
+ entityManagerFactoryBean.destroy();
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("jpa://" + LockTimeoutItem.class.getName()
+ + "?query=select x from LockTimeoutItem x order by
x.id&lockTimeout=1000&startScheduler=false")
+ .routeId("consumer")
+ .to("mock:result");
+ }
+ };
+ }
+
+ @Test
+ void pollGivesUpOnALockedEntityInsteadOfWaiting() throws Exception {
+ insertItems(1L, 2L, 3L);
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ JpaConsumer consumer = (JpaConsumer)
context.getRoute("consumer").getConsumer();
+
+ try (Connection other = openConnection()) {
+ // a transaction that locks the first entity and does not end
+ other.setAutoCommit(false);
+ try (Statement st = other.createStatement()) {
+ st.execute("select id from lock_timeout_item where id = 1 for
update");
+ }
+
+ // without a lock timeout, the poll would wait until that
transaction ends
+ assertTimeoutPreemptively(Duration.ofSeconds(30), () -> {
+ consumer.poll();
+ }, "the poll waited for the lock");
+ assertEquals(0, sessionsWaitingForALock(), "the database cancelled
the wait of the poll");
+ // the failed lock rolled back the transaction of the poll
(PostgreSQL), so the poll consumed nothing
+ assertEquals(0, mock.getReceivedCounter());
+ assertEquals(3, countItems());
+
+ // the transaction ends, as idle_in_transaction_session_timeout of
PostgreSQL would end it
+ other.rollback();
+ }
+
+ // the next poll consumes every entity
+ mock.expectedMessageCount(3);
+ assertEquals(3, consumer.poll());
+ mock.assertIsSatisfied();
+ assertEquals(0, countItems());
+ }
+
+ @Test
+ void entitiesAheadOfALockedEntityAreRoutedAgainByEachPoll() throws
Exception {
+ insertItems(1L, 2L, 3L);
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ JpaConsumer consumer = (JpaConsumer)
context.getRoute("consumer").getConsumer();
+
+ try (Connection other = openConnection()) {
+ // a transaction that locks the second entity and does not end
+ other.setAutoCommit(false);
+ try (Statement st = other.createStatement()) {
+ st.execute("select id from lock_timeout_item where id = 2 for
update");
+ }
+
+ // each poll routes the first entity, then the lock of the second
one times out: on PostgreSQL this aborts
+ // the transaction, so the poll fails to commit the consumed first
entity and is rolled back, and the next
+ // poll routes the first entity again
+ for (int poll = 1; poll <= 3; poll++) {
+ assertTimeoutPreemptively(Duration.ofSeconds(30), () -> {
+ assertThrows(PersistenceException.class, consumer::poll);
+ }, "the poll waited for the lock");
+ assertEquals(poll, mock.getReceivedCounter());
+ assertEquals(3, countItems());
+ }
+ List<Long> routed = mock.getReceivedExchanges().stream()
+ .map(exchange ->
exchange.getMessage().getBody(LockTimeoutItem.class).getId())
+ .toList();
+ assertEquals(List.of(1L, 1L, 1L), routed);
+
+ // the transaction ends
+ other.rollback();
+ }
+
+ // the next poll consumes every entity
+ mock.reset();
+ mock.expectedMessageCount(3);
+ assertEquals(3, consumer.poll());
+ mock.assertIsSatisfied();
+ assertEquals(0, countItems());
+ }
+
+ private void insertItems(Long... ids) {
+ EntityManager em = entityManagerFactory.createEntityManager();
+ try {
+ em.getTransaction().begin();
+ for (Long id : ids) {
+ em.persist(new LockTimeoutItem(id));
+ }
+ em.getTransaction().commit();
+ } finally {
+ em.close();
+ }
+ }
+
+ private static Connection openConnection() throws SQLException {
+ return DriverManager.getConnection(service.jdbcUrl(),
service.userName(), service.password());
+ }
+
+ private static int countItems() throws SQLException {
+ return queryInt("select count(*) from lock_timeout_item");
+ }
+
+ private static int sessionsWaitingForALock() throws SQLException {
+ return queryInt("select count(*) from pg_stat_activity where
wait_event_type = 'Lock'");
+ }
+
+ private static int queryInt(String sql) throws SQLException {
+ try (Connection connection = openConnection();
+ Statement st = connection.createStatement();
+ ResultSet rs = st.executeQuery(sql)) {
+ rs.next();
+ return rs.getInt(1);
+ }
+ }
+}
diff --git
a/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaConsumerLockTimeoutTest.java
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaConsumerLockTimeoutTest.java
new file mode 100644
index 000000000000..bd2af1b0454c
--- /dev/null
+++
b/components/camel-jpa/src/test/java/org/apache/camel/component/jpa/JpaConsumerLockTimeoutTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.jpa;
+
+import java.util.Map;
+
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.LockModeType;
+import jakarta.persistence.metamodel.Metamodel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.examples.SendEmail;
+import org.apache.camel.processor.jpa.AbstractJpaTest;
+import org.apache.camel.util.ObjectHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The lockTimeout option is given to the JPA provider as the
jakarta.persistence.lock.timeout hint of the lock of each
+ * entity. JpaConsumerLockTimeoutIT shows its effect on PostgreSQL.
+ */
+class JpaConsumerLockTimeoutTest extends AbstractJpaTest {
+
+ private static final String SELECT_ALL_STRING = "select x from " +
SendEmail.class.getName() + " x";
+
+ @Test
+ void lockTimeoutIsGivenToTheLock() {
+ SendEmail entity = new SendEmail("[email protected]");
+ EntityManager em = entityManagerWithMetamodel();
+
+ assertTrue(consumer("lockTimeout").lockEntity(entity, em));
+ verify(em).lock(entity, LockModeType.PESSIMISTIC_WRITE,
Map.of("jakarta.persistence.lock.timeout", 1500));
+ }
+
+ @Test
+ void noHintWithoutLockTimeout() {
+ SendEmail entity = new SendEmail("[email protected]");
+ EntityManager em = entityManagerWithMetamodel();
+
+ assertTrue(consumer("default").lockEntity(entity, em));
+ verify(em).lock(entity, LockModeType.PESSIMISTIC_WRITE);
+ verify(em, never()).lock(eq(entity),
eq(LockModeType.PESSIMISTIC_WRITE), anyMap());
+ }
+
+ @Test
+ void skipLockedEntityDoesNotWaitWhateverTheLockTimeout() {
+ SendEmail entity = new SendEmail("[email protected]");
+ EntityManager em = entityManagerWithMetamodel();
+
+ assertTrue(consumer("skipLocked").lockEntity(entity, em));
+ // an Integer, as the hint of lockTimeout
+ verify(em).lock(entity, LockModeType.PESSIMISTIC_WRITE,
Map.of("jakarta.persistence.lock.timeout", 0));
+ }
+
+ @Test
+ void negativeLockTimeoutInTheUriIsRejected() {
+ // a negative duration converts without error ("-1", "-1s" or
"-PT1S"), and would wait for ever
+ Exception e = assertThrows(Exception.class, () ->
context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("jpa://" + SendEmail.class.getName() +
"?startScheduler=false&lockTimeout=-1s").to("mock:result");
+ }
+ }));
+ IllegalArgumentException cause =
ObjectHelper.getException(IllegalArgumentException.class, e);
+ assertNotNull(cause, "the route must not start with a negative
lockTimeout");
+ assertEquals("lockTimeout must be >= 0, was: -1000",
cause.getMessage());
+ }
+
+ @Test
+ void negativeLockTimeoutOfTheConsumerIsRejected() throws Exception {
+ JpaEndpoint endpoint = context.getEndpoint("jpa://" +
SendEmail.class.getName(), JpaEndpoint.class);
+ JpaConsumer consumer = (JpaConsumer) endpoint.createConsumer(exchange
-> {
+ });
+ consumer.setLockTimeout(-1);
+
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, consumer::init);
+ assertEquals("lockTimeout must be >= 0, was: -1", e.getMessage());
+ }
+
+ private EntityManager entityManagerWithMetamodel() {
+ EntityManager em = mock(EntityManager.class);
+ Metamodel metamodel = entityManager.getMetamodel();
+ when(em.getMetamodel()).thenReturn(metamodel);
+ return em;
+ }
+
+ private JpaConsumer consumer(String routeId) {
+ return (JpaConsumer) context.getRoute(routeId).getConsumer();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ String uri = "jpa://" + SendEmail.class.getName() +
"?startScheduler=false";
+ from(uri +
"&lockTimeout=1500").routeId("lockTimeout").to("mock:result");
+ from(uri).routeId("default").to("mock:result");
+ from(uri +
"&lockTimeout=1500&skipLockedEntity=true").routeId("skipLocked").to("mock:result");
+ }
+ };
+ }
+
+ @Override
+ protected String routeXml() {
+ return "org/apache/camel/processor/jpa/springJpaRouteTest.xml";
+ }
+
+ @Override
+ protected String selectAllString() {
+ return SELECT_ALL_STRING;
+ }
+}
diff --git
a/components/camel-jpa/src/test/resources/org/apache/camel/component/jpa/lock-timeout-item-orm.xml
b/components/camel-jpa/src/test/resources/org/apache/camel/component/jpa/lock-timeout-item-orm.xml
new file mode 100644
index 000000000000..faea08f87270
--- /dev/null
+++
b/components/camel-jpa/src/test/resources/org/apache/camel/component/jpa/lock-timeout-item-orm.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<!-- the entity of JpaConsumerLockTimeoutIT, mapped here and not with
annotations: the OpenJPA persistence units of
+ the other tests scan the test classes for annotated entities, and this
one is not enhanced for OpenJPA -->
+<entity-mappings xmlns="https://jakarta.ee/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence/orm
https://jakarta.ee/xml/ns/persistence/orm/orm_3_1.xsd"
+ version="3.1">
+ <entity
class="org.apache.camel.component.jpa.JpaConsumerLockTimeoutIT$LockTimeoutItem"
name="LockTimeoutItem"
+ access="FIELD">
+ <table name="lock_timeout_item"/>
+ <attributes>
+ <id name="id"/>
+ </attributes>
+ </entity>
+</entity-mappings>
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java
index 9c2808a49711..c9e0b587a116 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/JpaEndpointBuilderFactory.java
@@ -366,6 +366,60 @@ public interface JpaEndpointBuilderFactory {
doSetProperty("lockModeType", lockModeType);
return this;
}
+ /**
+ * How long the consumer waits for the lock of an entity (see
+ * consumeLockEntity) that another transaction holds. It is given to
the
+ * JPA provider as the jakarta.persistence.lock.timeout hint, which the
+ * provider applies if the database supports it: for example Hibernate
+ * on PostgreSQL sets lock_timeout for the lock. The default 0 sets no
+ * timeout: the lock waits as long as the database lets it, which on
+ * PostgreSQL is until the other transaction ends. A lock that times
out
+ * is handled like one that skipLockedEntity could not get. On
+ * PostgreSQL it rolls back the poll: the entities that the poll routed
+ * before the locked one are routed again by each poll, for as long as
+ * the other transaction holds the lock, so the route must be
+ * idempotent. Not used with skipLockedEntity, which does not wait at
+ * all. The value is in millis, and must not be negative.
+ *
+ * The option is a: <code>long</code> type.
+ *
+ * Default: 0
+ * Group: consumer
+ *
+ * @param lockTimeout the value to set
+ * @return the dsl builder
+ */
+ default JpaEndpointConsumerBuilder lockTimeout(long lockTimeout) {
+ doSetProperty("lockTimeout", lockTimeout);
+ return this;
+ }
+ /**
+ * How long the consumer waits for the lock of an entity (see
+ * consumeLockEntity) that another transaction holds. It is given to
the
+ * JPA provider as the jakarta.persistence.lock.timeout hint, which the
+ * provider applies if the database supports it: for example Hibernate
+ * on PostgreSQL sets lock_timeout for the lock. The default 0 sets no
+ * timeout: the lock waits as long as the database lets it, which on
+ * PostgreSQL is until the other transaction ends. A lock that times
out
+ * is handled like one that skipLockedEntity could not get. On
+ * PostgreSQL it rolls back the poll: the entities that the poll routed
+ * before the locked one are routed again by each poll, for as long as
+ * the other transaction holds the lock, so the route must be
+ * idempotent. Not used with skipLockedEntity, which does not wait at
+ * all. The value is in millis, and must not be negative.
+ *
+ * The option will be converted to a <code>long</code> type.
+ *
+ * Default: 0
+ * Group: consumer
+ *
+ * @param lockTimeout the value to set
+ * @return the dsl builder
+ */
+ default JpaEndpointConsumerBuilder lockTimeout(String lockTimeout) {
+ doSetProperty("lockTimeout", lockTimeout);
+ return this;
+ }
/**
* An integer value to define the maximum number of messages to gather
* per poll. By default, no maximum is set. It can be used to avoid