Search in sources :

Example 1 with HazelcastComponent

use of org.apache.camel.component.hazelcast.HazelcastComponent in project camel by apache.

the class HazelcastRoute method configure.

@Override
public void configure() throws Exception {
    HazelcastComponent component = new HazelcastComponent();
    ClientConfig config = new ClientConfig();
    config.getNetworkConfig().addAddress("hazelcast");
    config.getNetworkConfig().setSSLConfig(new SSLConfig().setEnabled(false));
    config.setGroupConfig(new GroupConfig("someGroup", "someSecret"));
    HazelcastInstance instance = HazelcastClient.newHazelcastClient(config);
    component.setHazelcastInstance(instance);
    getContext().addComponent("hazelcast", component);
    from("timer:foo?period=5000").log("Producer side: Sending data to Hazelcast topic..").process(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(HazelcastConstants.OPERATION, HazelcastConstants.PUBLISH_OPERATION);
            String payload = "Test " + UUID.randomUUID();
            exchange.getIn().setBody(payload);
        }
    }).to("hazelcast:topic:foo");
    from("hazelcast:topic:foo").log("Consumer side: Detected following action: $simple{in.header.CamelHazelcastListenerAction}");
}
Also used : Exchange(org.apache.camel.Exchange) SSLConfig(com.hazelcast.config.SSLConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Processor(org.apache.camel.Processor) GroupConfig(com.hazelcast.config.GroupConfig) HazelcastComponent(org.apache.camel.component.hazelcast.HazelcastComponent) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 2 with HazelcastComponent

use of org.apache.camel.component.hazelcast.HazelcastComponent in project camel by apache.

the class HazelcastComponentAutoConfiguration method configureHazelcastComponent.

@Lazy
@Bean(name = "hazelcast-component")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(HazelcastComponent.class)
public HazelcastComponent configureHazelcastComponent(CamelContext camelContext, HazelcastComponentConfiguration configuration) throws Exception {
    HazelcastComponent component = new HazelcastComponent();
    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) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HazelcastComponent(org.apache.camel.component.hazelcast.HazelcastComponent) 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

HazelcastComponent (org.apache.camel.component.hazelcast.HazelcastComponent)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 GroupConfig (com.hazelcast.config.GroupConfig)1 SSLConfig (com.hazelcast.config.SSLConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)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