Croway commented on PR #2046:
URL:
https://github.com/apache/camel-spring-boot/pull/2046#issuecomment-6268654466
@ramu11 Yes, that's the intended approach. Please keep it in the existing
`camel-state-store-starter` behind a property; no separate starter is needed.
- Put it in its own package, e.g.
`org.apache.camel.component.statestore.springboot.cache`, and add it to
`AutoConfiguration.imports`. The generator leaves hand-written classes alone,
and Spring's `Cache` API comes from `spring-context`, which
`spring-boot-starter` already includes. So no new dependency is needed.
- Turn it on with a property that is off by default, for example
`camel.state-store.spring-cache.enabled`. Avoid the
`camel.component.state-store.*` prefix, because those keys are generated from
the component's options.
- Use `@ConditionalOnSingleCandidate(CacheManager.class)` and
`@ConditionalOnMissingBean(StateStoreBackendFactory.class)`.
- No customizer is needed. The component's `backendFactory` option is
autowired, so a single factory bean is picked up automatically.
The auto-configuration would look roughly like this:
```java
@Bean
@ConditionalOnSingleCandidate(CacheManager.class)
@ConditionalOnMissingBean(StateStoreBackendFactory.class)
public StateStoreBackendFactory
springCacheStateStoreBackendFactory(CacheManager cacheManager) {
return storeName -> new SpringCacheKeyValueRepository(cacheManager,
storeName);
}
```
and a user would configure it like this:
```properties
spring.cache.type=caffeine
spring.cache.cache-names=orders,users
camel.state-store.spring-cache.enabled=true
```
```java
from("direct:order")
.setHeader("CamelStateStoreKey", simple("${header.orderId}"))
.to("state-store:orders?operation=put"); // stored in the Spring cache
"orders"
```
Each store name is backed by the Spring cache with the same name, so
`state-store:users` uses the `users` cache. Aggregate, Idempotent Consumer and
the Cache EIP are not affected, because no global `KeyValueRepository` bean is
registered.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]