Search in sources :

Example 1 with SjmsBatchComponent

use of org.apache.camel.component.sjms.batch.SjmsBatchComponent in project camel by apache.

the class ManualBatchFromQueueTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("testStrategy", new ListAggregationStrategy());
    CamelContext camel = new DefaultCamelContext(registry);
    SjmsBatchComponent sjms = new SjmsBatchComponent();
    sjms.setAsyncStartListener(true);
    log.info("Using live connection to existing ActiveMQ broker running on {}", url);
    sjms.setConnectionFactory(new ActiveMQConnectionFactory(url));
    camel.addComponent("sjms-batch", sjms);
    return camel;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) SjmsBatchComponent(org.apache.camel.component.sjms.batch.SjmsBatchComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ListAggregationStrategy(org.apache.camel.component.sjms.batch.ListAggregationStrategy)

Example 2 with SjmsBatchComponent

use of org.apache.camel.component.sjms.batch.SjmsBatchComponent in project camel by apache.

the class SjmsBatchComponentAutoConfiguration method configureSjmsBatchComponent.

@Lazy
@Bean(name = "sjms-batch-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(SjmsBatchComponent.class)
public SjmsBatchComponent configureSjmsBatchComponent(CamelContext camelContext, SjmsBatchComponentConfiguration configuration) throws Exception {
    SjmsBatchComponent component = new SjmsBatchComponent();
    component.setCamelContext(camelContext);
    Map<String, Object> parameters = new HashMap<>();
    IntrospectionSupport.getProperties(configuration, parameters, null, false);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : HashMap(java.util.HashMap) SjmsBatchComponent(org.apache.camel.component.sjms.batch.SjmsBatchComponent) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

SjmsBatchComponent (org.apache.camel.component.sjms.batch.SjmsBatchComponent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 CamelContext (org.apache.camel.CamelContext)1 ListAggregationStrategy (org.apache.camel.component.sjms.batch.ListAggregationStrategy)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1