[
https://issues.apache.org/jira/browse/CAMEL-14672?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17183103#comment-17183103
]
Luca Burgazzoli edited comment on CAMEL-14672 at 8/24/20, 9:46 AM:
-------------------------------------------------------------------
Thinking a little bit more about this, what we can do is something similar to
the EventNotifier so
{code:java}
@FunctionalInterface
public interface ComponentCustomizer extends Consumer<Component>, Ordered {
default boolean isEnabled(Component event) {
return true;
}
}
{code}
Then in addition to manually implement the interface and providing some
helpers, we can also expand the component dsl so once could write something like
{code:java}
@BindToRegistry
ComponentCustomizer customizeLog() {
return ComponentsBuilderFactory.log(c -> c.setExchangeFormatter(...));
}
{code}
For XML, I don't think we need to add anything as in fact they are just beans
so you'd only need to implement the interface and you are done.
For Spring, I think we can simply turn the bean from creating a component to
creating a customizer and keep most of the classes we have, as example:
{code:java}
@Lazy
@Bean(name = "log-component-customizer")
public ComponentCustomizer configureLogComponent() throws Exception {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
return new ComponentCustomizer() {
@Override
boolean isEnabled(Component component) {
return component instancef LogComponent;
}
@Override
void customize(Component component) {
CamelPropertiesHelper.setCamelProperties(camelContext, component,
parameters, false);
}
};
}
{code}
was (Author: lb):
Thinking a little bit more about this, what we can do is something similar to
the EventNotifier so
{code:java}
@FunctionalInterface
public interface ComponentCustomizer extends Consumer<Component>, Ordered {
default boolean isEnabled(Component event) {
return true;
}
}
{code}
Then in addition to manually implement the interface and providing some
helpers, we can also expand the component dsl so once could write something like
{code:java}
@BindToRegistry
ComponentCustomizer customizeLog() {
return ComponentsBuilderFactory.log(c -> c.setExchangeFormatter(...));
}
{code}
For XML, I don't think we need to add anything as in fact they are just beans
so you'd only need to implement the interface and you are done.
For Spring, I think we can simply turn the bean from creating a component to
creating a customizer and keep most of the classes we have as example:
{code:java}
@Lazy
@Bean(name = "log-component-customizer")
public ComponentCustomizer configureLogComponent() throws Exception {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
return new ComponentCustomizer() {
@Override
boolean isEnabled(Component component) {
return component instancef LogComponent;
}
@Override
void customize(Component component) {
CamelPropertiesHelper.setCamelProperties(camelContext, component,
parameters, false);
}
};
}
{code}
> Invoke ComponentCustomizer as part of component initialization
> --------------------------------------------------------------
>
> Key: CAMEL-14672
> URL: https://issues.apache.org/jira/browse/CAMEL-14672
> Project: Camel
> Issue Type: New Feature
> Components: camel-core
> Reporter: Luca Burgazzoli
> Priority: Major
> Fix For: 3.5.0
>
>
> Camel has the concept of _ComponentCustomizer_ which is currently used only
> by spring-boot starters and I wonder if we can make it a generic concept so
> basically after configuring the component with properties, we should search
> for customizers in the camel registry and apply them to the component itself.
> Examples:
> -
> https://github.com/apache/camel-spring-boot/blob/master/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
> -
> https://github.com/apache/camel-spring-boot/blob/master/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentAutoConfiguration.java
--
This message was sent by Atlassian Jira
(v8.3.4#803005)