Java tutorial
/* * Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Amazon Software License (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/asl/ * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.importio.kinesis.elasticsearch; import java.io.File; import java.io.IOException; import java.io.Reader; import java.nio.file.Files; import java.util.Properties; import com.amazonaws.auth.EnvironmentVariableCredentialsProvider; import com.amazonaws.services.kinesis.connectors.KinesisConnectorConfiguration; import com.amazonaws.services.kinesis.connectors.KinesisConnectorExecutorBase; import com.amazonaws.services.kinesis.connectors.KinesisConnectorRecordProcessorFactory; import com.amazonaws.services.kinesis.connectors.elasticsearch.ElasticsearchObject; import com.importio.kinesis.elasticsearch.data.Page; public class ElasticsearchExecutor extends KinesisConnectorExecutorBase<Page, ElasticsearchObject> { private KinesisConnectorConfiguration config; public ElasticsearchExecutor(Properties properties) { config = new KinesisConnectorConfiguration(properties, new EnvironmentVariableCredentialsProvider()); initialize(config); } private static Properties loadPropertiesFile(File configFile) throws IOException { Properties properties = new Properties(); try (Reader reader = Files.newBufferedReader(configFile.toPath())) { properties.load(reader); } return properties; } @Override public KinesisConnectorRecordProcessorFactory<Page, ElasticsearchObject> getKinesisConnectorRecordProcessorFactory() { return new KinesisConnectorRecordProcessorFactory<Page, ElasticsearchObject>(new ElasticsearchPipeline(), config); } /** * Main method starts and runs the ElasticsearchExecutor. * * @param args */ public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: java -jar es-kinesis.jar [config file path]"); System.exit(1); return; } File configFile = new File(args[0]); if (!configFile.exists()) { System.err.println("No such configuration file"); System.exit(1); return; } Properties properties; try { properties = loadPropertiesFile(configFile); } catch (Exception e) { System.err.println("Could not load configuration file"); e.printStackTrace(System.err); System.exit(1); return; } new ElasticsearchExecutor(properties).run(); } }