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}");
}
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;
}
Aggregations