Federico Mariani created CAMEL-25791:
----------------------------------------
Summary: camel-state-store - Add a backend factory option to
create one KeyValueRepository per store name
Key: CAMEL-25791
URL: https://issues.apache.org/jira/browse/CAMEL-25791
Project: Camel
Issue Type: Improvement
Components: camel-core
Reporter: Federico Mariani
h2. Problem
When no {{backend}} option is set on a {{state-store}} endpoint,
{{StateStoreComponent}} picks the backend in two ways:
* a single {{KeyValueRepository}} bean from the registry, which is then shared
by *every* store name, or
* a new {{MemoryKeyValueRepository}} per store name.
There is no way to get one dedicated (non in-memory) backend per store name
without setting {{backend=#...}} on every endpoint. It also means that
integrations can only plug in a backend by registering a global
{{KeyValueRepository}} bean. The Aggregate, Idempotent Consumer and Cache EIPs
also auto-discover that bean through {{findSingleByType}}, which changes their
behaviour (for example an {{optimisticLocking()}} aggregator then fails to
start).
This came up while reviewing the Spring Cache adapter for camel-spring-boot
(CAMEL-24757, apache/camel-spring-boot#2046), where {{state-store:myStore}}
should map to the Spring cache {{myStore}}.
h2. Proposal
Add a {{StateStoreBackendFactory}} functional interface ({{KeyValueRepository
createBackend(String storeName)}}) and an autowired {{backendFactory}}
component option on {{StateStoreComponent}}.
Resolution order for an endpoint:
# explicit endpoint {{backend}}
# {{backendFactory}} (called once per store name, the component starts/stops
the created backend; returning {{null}} falls through)
# a single {{KeyValueRepository}} from the registry
# {{MemoryKeyValueRepository}}
Since the option is autowired, a runtime only needs to register a
{{StateStoreBackendFactory}} bean. The EIPs are unaffected because it is not a
{{KeyValueRepository}}.
_Claude Code on behalf of Federico Mariani_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)