Kafka
  1. Kafka
  2. KAFKA-291

Add builder to create configs for consumer and broker

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • 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
        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
        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.
        Hide
        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 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();
        John Wang made changes -
        Field Original Value New Value
        Attachment builderPatch.diff [ 12516878 ]
        John Wang created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            John Wang
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development