-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cdf39ca
Showing
4 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
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,8 @@ | ||
# kafka-adminclient-test | ||
|
||
Simple test of Kafka AdminClient (create topic) | ||
|
||
Run with: | ||
``` | ||
mvn compile exec:java -Dexec.args="bootstrap-string topic-name" -Djava.security.auth.login.config=jaas-config-file | ||
``` |
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,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<groupId>test</groupId> | ||
<artifactId>topictest</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.kafka</groupId> | ||
<artifactId>kafka-clients</artifactId> | ||
<version>2.0.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<configuration> | ||
<mainClass>TopicTest</mainClass> | ||
<cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,26 @@ | ||
import java.util.Collections; | ||
import java.util.Properties; | ||
import org.apache.kafka.clients.admin.AdminClient; | ||
import org.apache.kafka.clients.admin.AdminClientConfig; | ||
import org.apache.kafka.clients.admin.CreateTopicsResult; | ||
import org.apache.kafka.clients.admin.KafkaAdminClient; | ||
import org.apache.kafka.clients.admin.NewTopic; | ||
|
||
public class TopicTest { | ||
|
||
public static void main(String args[]) throws Exception { | ||
String bootstrap = args[0]; | ||
String topic = args[1]; | ||
System.out.println("Creating topic "+topic+" on "+bootstrap); | ||
Properties config = new Properties(); | ||
config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrap); | ||
config.put(AdminClientConfig.CLIENT_ID_CONFIG, "topics-test"); | ||
config.put(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "SASL_SSL"); | ||
config.put("sasl.mechanism", "PLAIN"); | ||
AdminClient admin = KafkaAdminClient.create(config); | ||
NewTopic newTopic = new NewTopic(topic, 1, (short)1); | ||
CreateTopicsResult result = admin.createTopics(Collections.singleton(newTopic)); | ||
result.values().get(topic).get(); | ||
} | ||
|
||
} |