代码如下
package calc.bi.rc
import scala.collection.mutable.ArrayBuffer
import joptsimple.OptionParser
import kafka.utils.CommandLineUtils
import kafka.utils.ToolsUtils
import kafka.client.ClientUtils
import kafka.common.TopicAndPartition
import kafka.api.PartitionOffsetRequestInfo
import kafka.api.OffsetRequest
import kafka.consumer.SimpleConsumer
import scala.collection.mutable.Map
//这是对kafka自带工具包的扩展
object GetOffsetShellWrap {
//在主函数添加一个参数map
def main(args: Array[String],map: Map[String, String]): Unit = {
//对参数的解析
val parser = new OptionParser
val brokerListOpt = parser.accepts("broker-list", "REQUIRED: The list of hostname and port of the server to connect to.")
.withRequiredArg
.describedAs("hostname:port,...,hostname:port")
.ofType(classOf[String])
val topicOpt = parser.accepts("topic", "REQUIRED: The topic to get offset from.")
.withRequiredArg
.describe