org.smartloli.kafka.eagle.plugins.KafkaGroupCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsql-client Show documentation
Show all versions of jsql-client Show documentation
Intermediate DataSet use sql to query , Through the jsql-client , we can use sql to get results .
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.smartloli.kafka.eagle.plugins;
import java.util.Properties;
import org.apache.kafka.clients.CommonClientConfigs;
import kafka.admin.AdminClient;
import kafka.admin.AdminClient.ConsumerSummary;
import scala.Option;
import scala.collection.Iterator;
import scala.collection.immutable.List;
/**
* Get the owner information stored in the Kafka in the bottom source through
* the topic.
*
* @author smartloli.
*
* Created by Jan 20, 2017
*/
public class KafkaGroupCommand {
public static String owners(String bootstrapServers, String group) {
String target = "";
Properties prop = new Properties();
prop.put(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
try {
AdminClient adminClient = AdminClient.create(prop);
Option> opts = adminClient.describeConsumerGroup(group);
Iterator consumerSummarys = opts.get().iterator();
while (consumerSummarys.hasNext()) {
ConsumerSummary consumerSummary = consumerSummarys.next();
target = consumerSummary.clientHost();
}
} catch (Exception e) {
e.printStackTrace();
}
return target;
}
public static void main(String[] args) {
System.out.println(owners("slave01:9094", "test33"));
}
}