Search in sources :

Example 1 with Generator

use of io.confluent.avro.random.generator.Generator in project ksql by confluentinc.

the class DataGen method main.

public static void main(String[] args) {
    Arguments arguments;
    try {
        arguments = new Arguments.Builder().parseArgs(args).build();
    } catch (Arguments.ArgumentParseException exception) {
        System.err.println(exception.getMessage());
        usage(1);
        return;
    } catch (IOException exception) {
        System.err.printf("IOException encountered: %s%n", exception.getMessage());
        return;
    }
    if (arguments.help) {
        usage(0);
    }
    Generator generator;
    try {
        generator = new Generator(arguments.schemaFile, new Random());
    } catch (IOException exception) {
        System.err.printf("IOException encountered: %s%n", exception.getMessage());
        return;
    }
    DataGenProducer dataProducer;
    switch(arguments.format) {
        case AVRO:
            dataProducer = new AvroProducer(new KsqlConfig(Collections.singletonMap(KsqlConfig.SCHEMA_REGISTRY_URL_PROPERTY, arguments.schemaRegistryUrl)));
            break;
        case JSON:
            dataProducer = new JsonProducer();
            break;
        case DELIMITED:
            dataProducer = new DelimitedProducer();
            break;
        default:
            System.err.printf("Invalid format in '%s'; was expecting one of AVRO, JSON, or DELIMITED%n", arguments.format);
            usage(1);
            return;
    }
    Properties props = new Properties();
    props.put("bootstrap.servers", arguments.bootstrapServer);
    props.put("client.id", "KSQLDataGenProducer");
    try {
        if (arguments.propertiesFile != null) {
            props.load(arguments.propertiesFile);
        }
    } catch (IOException exception) {
        System.err.printf("IOException encountered: %s%n", exception.getMessage());
        return;
    }
    dataProducer.populateTopic(props, generator, arguments.topicName, arguments.keyName, arguments.iterations, arguments.maxInterval);
}
Also used : Random(java.util.Random) KsqlConfig(io.confluent.ksql.util.KsqlConfig) IOException(java.io.IOException) Properties(java.util.Properties) Generator(io.confluent.avro.random.generator.Generator)

Aggregations

Generator (io.confluent.avro.random.generator.Generator)1 KsqlConfig (io.confluent.ksql.util.KsqlConfig)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 Random (java.util.Random)1