private static ConsumerConfig createConsumerConfig( String zookeeper, String groupId, String optionalConfigs) { try { Properties props = new Properties(); props.put(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_ZOOKEEPER_CONNECT, zookeeper); props.put(KafkaEventAdapterConstants.ADAPTOR_SUSCRIBER_GROUP_ID, groupId); if (optionalConfigs != null) { String[] optionalProperties = optionalConfigs.split(","); if (optionalProperties != null && optionalProperties.length > 0) { for (String header : optionalProperties) { String[] configPropertyWithValue = header.split(":", 2); if (configPropertyWithValue.length == 2) { props.put(configPropertyWithValue[0], configPropertyWithValue[1]); } else { log.warn( "Optional configuration property not defined in the correct format.\nRequired - property_name1:property_value1,property_name2:property_value2\nFound - " + optionalConfigs); } } } } return new ConsumerConfig(props); } catch (NoClassDefFoundError e) { throw new InputEventAdapterRuntimeException( "Cannot access kafka context due to missing jars", e); } }
private Properties getServerProperties() { Properties serverProperties = new Properties(); serverProperties.put("zookeeper.connect", zkServer.getConnectString()); serverProperties.put("broker.id", "1"); serverProperties.put("host.name", "localhost"); serverProperties.put("port", String.valueOf(kafkaPort)); serverProperties.put("log.dir", FileUtils.createTmpDir("embedded-kafka")); serverProperties.put("log.flush.interval.messages", "1"); return serverProperties; }