Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-291

Add builder to create configs for consumer and broker

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 0.7
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None

      Description

      Creating Consumer and Producer can be cumbersome because you have to remember the exact string for the property to be set. And since these are just strings, IDEs cannot really help.

      This patch contains builders that help with this.

        Activity

        Hide
        john.wang@gmail.com John Wang added a comment -

        examples (in java):

        Producer:

        instead of:

        Properties props = new Properties();
        props.put("zk.connect", "localhost:2181");
        props.put("serializer.class", "kafka.serializer.DefaultEncoder");

        ProducerConfig producerConfig = new ProducerConfig(props);
        we can do:

        ProducerConfig producerConfig = new ProducerConfigBuilder().setZkConnect("localhost:2181").setSerializerClass("kafka.serializer.DefaultEncoder").build();

        Consumer:

        instead of:

        Properties props = new Properties();
        props.put("zk.connect", _zookeeperUrl);
        props.put("consumer.timeout.ms", _kafkaSoTimeout);
        props.put("groupid", _consumerGroupId);

        ConsumerConfig consumerConfig = new ConsumerConfig(props);

        we can do:

        ConsumerConfig consumerConfig = new ConsumerConfigBuilder().setGroupId(_consumerGroupId).setZkConnect(_zookeeperUrl).setGroupId(_consumerGroupId).build();

        Show
        john.wang@gmail.com John Wang added a comment - examples (in java): Producer: instead of: Properties props = new Properties(); props.put("zk.connect", "localhost:2181"); props.put("serializer.class", "kafka.serializer.DefaultEncoder"); ProducerConfig producerConfig = new ProducerConfig(props); we can do: ProducerConfig producerConfig = new ProducerConfigBuilder().setZkConnect("localhost:2181").setSerializerClass("kafka.serializer.DefaultEncoder").build(); Consumer: instead of: Properties props = new Properties(); props.put("zk.connect", _zookeeperUrl); props.put("consumer.timeout.ms", _kafkaSoTimeout); props.put("groupid", _consumerGroupId); ConsumerConfig consumerConfig = new ConsumerConfig(props); we can do: ConsumerConfig consumerConfig = new ConsumerConfigBuilder().setGroupId(_consumerGroupId).setZkConnect(_zookeeperUrl).setGroupId(_consumerGroupId).build();
        Hide
        swapnilghike Swapnil Ghike added a comment -

        Not sure if the ConfigBuilder is going to reduce complexity. The strings like "localhost:2181" will generally not be hardcoded in java code and will be passed from some config map, this passing of config values will have the same caveats.

        Show
        swapnilghike Swapnil Ghike added a comment - Not sure if the ConfigBuilder is going to reduce complexity. The strings like "localhost:2181" will generally not be hardcoded in java code and will be passed from some config map, this passing of config values will have the same caveats.

          People

          • Assignee:
            Unassigned
            Reporter:
            john.wang@gmail.com John Wang
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development