2
votes

I'm trying sample codes from http://kafka.apache.org/0100/javadoc/index.html?org/apache/kafka/streams/KafkaStreams.html

but for this two lines

KStreamBuilder builder = new KStreamBuilder();
builder.from("my-input-topic").mapValue(value -> value.length().toString()).to("my-output-topic");

There seems no method called 'from' in KStreamBuilder now according to https://kafka.apache.org/0100/javadoc/org/apache/kafka/streams/kstream/KStreamBuilder.html

So what's the current way to do the same thing as the above 2 lines?

Maven is used to manage the dependencies

<dependency>
  <groupId>org.apache.kafka</groupId>
  <artifactId>kafka-streams</artifactId>
  <version>0.10.0.0</version>
</dependency>
2

2 Answers

1
votes

This method was renamed to stream() (from() is an old name)

KStreamBuilder builder = new KStreamBuilder();
builder.stream("my-input-topic").mapValues(value -> value.length().toString()).to("my-output-topic");

It's a bug in the documentation: https://github.com/apache/kafka/pull/1450

Also have a look here: http://docs.confluent.io/3.0.0/streams/developer-guide.html#kafka-streams-dsl

0
votes

What's more, the KStreamBuilder itself is deprecated now and StreamsBuilder should be used instead. It's a quite a bit more than just a name change although for most cases, end-users will not need anything else immediately, apart from the name of the class:

The two main classes to specify a topology via the DSL (KStreamBuilder) or the Processor API (TopologyBuilder) were deprecated and replaced by StreamsBuilder and Topology (both new classes are located in package org.apache.kafka.streams). Note, that StreamsBuilder does not extend Topology, i.e., the class hierarchy is different now. The new classes have basically the same methods as the old ones to build a topology via DSL or Processor API. However, some internal methods that were public in KStreamBuilder and TopologyBuilder but not part of the actual API are not present in the new classes any longer.