-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs for hstream kafka api (#48)
* kafka: add compatibility doc * add java client examples * add kafka java client docs * reorganize contents --------- Co-authored-by: Yue Yang <[email protected]>
- Loading branch information
Showing
37 changed files
with
564 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
order: ['compatibility.md', 'java.md'] | ||
collapsed: false | ||
--- | ||
|
||
Develop (with Kafka API) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Kafka Compatibility | ||
|
||
## Overview | ||
|
||
HStream also supports Kafka API since 0.19.0, so users can connect to HStream using Kafka clients. HStream implements [Kafka protocol](https://kafka.apache.org/protocol.html) underly, so you do not need to change any code in your current Kafka applications, just updating the Kafka URLs in your configurations to point to a HStream cluster, and that is it, then you can start streaming from your Kafka applications to a HStream cluster. | ||
|
||
::: tip | ||
|
||
Refer to [get started with Kafka API](../start/get-started-with-kafka-api.md) to learn how to enable HStream'support of Kafka API. | ||
|
||
::: | ||
|
||
## Compatibility with Apache Kafka | ||
|
||
HStream supports Apache Kafka version 0.11 and later, and most Kafka clients should be able to auto-negotiate protocol versions. | ||
|
||
Currenty, the clients below are tested by HStream. | ||
|
||
| Language | Kafka Client | | ||
| -------- | ----------------------------------------------------------- | | ||
| Java | [Apache Kafka Java Client](https://github.com/apache/kafka) | | ||
| Python | [kafka-python](https://github.com/dpkp/kafka-python) | | ||
| Go | [franz-go](https://github.com/twmb/franz-go) | | ||
| C/C++ | [librdkafka](https://github.com/confluentinc/librdkafka) | | ||
|
||
::: tip | ||
|
||
Recommand using the latest version of each Kafka client | ||
|
||
::: | ||
|
||
## Features not supported in Apache Kafka | ||
|
||
HStream do not support below Kafka features now(we plan to support them in the later version): | ||
|
||
- Kafka transactions | ||
- Quotas in Kafka | ||
|
||
::: tip | ||
|
||
The configuration of Kafka brokers is not applicable to HStream, as HStream is a completely different implementation. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Develope with Java Kafka client | ||
|
||
This page shows how to use [Apache Kafka Java Client](https://github.com/apache/kafka) to interact with HStream. | ||
|
||
|
||
::: tip | ||
|
||
Replace the variables in the following code according to your setup. | ||
|
||
::: | ||
|
||
## Create a Topic | ||
|
||
|
||
::: code-group | ||
|
||
<<< @/../kafka-examples/java/app/src/main/java/CreateTopic.java [Java] | ||
|
||
::: | ||
|
||
## Produce a Record | ||
|
||
|
||
::: code-group | ||
|
||
<<< @/../kafka-examples/java/app/src/main/java/Produce.java [Java] | ||
|
||
::: | ||
|
||
## Consume Records | ||
|
||
|
||
::: code-group | ||
|
||
<<< @/../kafka-examples/java/app/src/main/java/Consume.java [Java] | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
order: ['write', 'receive', 'process', 'ingest-and-distribute'] | ||
collapsed: false | ||
--- | ||
|
||
Develope |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Get Started with Kafka API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
plugins { | ||
id 'application' | ||
id "com.diffplug.spotless" version "6.2.0" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.apache.kafka:kafka-clients:3.6.1' | ||
} | ||
|
||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
application { | ||
// Define the main class for the application. | ||
mainClass = 'Main' | ||
} | ||
|
||
spotless { | ||
java { | ||
googleJavaFormat() | ||
} | ||
|
||
groovyGradle { | ||
target '*.gradle' | ||
greclipse() | ||
indentWithSpaces() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.Properties; | ||
import org.apache.kafka.clients.consumer.KafkaConsumer; | ||
|
||
class Consume { | ||
public static void main(String[] args) throws Exception { | ||
String endpoint = "localhost:9092"; | ||
String topicName = "my_topic"; | ||
String groupName = "my_group"; | ||
|
||
var props = new Properties(); | ||
props.put("bootstrap.servers", endpoint); | ||
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); | ||
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); | ||
props.put("auto.offset.reset", "earliest"); | ||
props.put("group.id", groupName); | ||
|
||
try (var consumer = new KafkaConsumer<String, String>(props)) { | ||
consumer.subscribe(Collections.singleton(topicName)); | ||
var records = consumer.poll(Duration.ofSeconds(10)); | ||
for (var record : records) { | ||
System.out.println(record); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.util.Collections; | ||
import java.util.Properties; | ||
import org.apache.kafka.clients.admin.AdminClient; | ||
import org.apache.kafka.clients.admin.NewTopic; | ||
|
||
class CreateTopic { | ||
public static void main(String[] args) throws Exception { | ||
String endpoint = "localhost:9092"; | ||
String topicName = "my_topic"; | ||
int partitions = 1; | ||
short replicationFactor = 1; | ||
|
||
var props = new Properties(); | ||
props.put("bootstrap.servers", endpoint); | ||
|
||
try (var admin = AdminClient.create(props)) { | ||
admin | ||
.createTopics( | ||
Collections.singleton(new NewTopic(topicName, partitions, replicationFactor))) | ||
.all() | ||
.get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Main { | ||
public static void main(String[] args) throws Exception { | ||
CreateTopic.main(args); | ||
Produce.main(args); | ||
Consume.main(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.util.Properties; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.clients.producer.ProducerRecord; | ||
|
||
class Produce { | ||
public static void main(String[] args) throws Exception { | ||
String endpoint = "localhost:9092"; | ||
String topicName = "my_topic"; | ||
|
||
var props = new Properties(); | ||
props.put("bootstrap.servers", endpoint); | ||
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer"); | ||
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); | ||
|
||
try (var producer = new KafkaProducer<String, String>(props)) { | ||
producer.send(new ProducerRecord<>(topicName, "Hello HStream!")); | ||
producer.flush(); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.