%%% %%% Copyright (c) 2017-2018 Klarna Bank AB (publ) %%% %%% Licensed 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. %%% -module(brod_cli). -ifdef(build_brod_cli). -export([main/1, main/2]). -include("brod_int.hrl"). -define(CLIENT, brod_cli_client). -ifdef(OTP_RELEASE). -define(BIND_STACKTRACE(Var), :Var). -define(GET_STACKTRACE(Var), ok). -else. -define(BIND_STACKTRACE(Var), ). -define(GET_STACKTRACE(Var), Var = erlang:get_stacktrace()). -endif. %% 'halt' is for escript, stop the vm immediately %% 'exit' is for testing, we want eunit or ct to be able to capture -define(STOP(How), begin try brod:stop_client(?CLIENT) catch exit : {noproc, _} -> ok end, _ = brod:stop(), case How of 'halt' -> erlang:halt(?LINE); 'exit' -> erlang:exit(?LINE) end end). -define(MAIN_DOC, "usage: brod -h|--help brod -v|--version brod [options] [-h|--help] [--verbose|--debug] commands: meta: Inspect topic metadata offset: Inspect offsets fetch: Fetch messages send: Produce messages pipe: Pipe file or stdin as messages to kafka groups: List/describe consumer group commits: List/descibe committed offsets or force overwrite existing commits "). %% NOTE: bad indentation at the first line is intended -define(COMMAND_COMMON_OPTIONS, " --ssl Use TLS, validate server using trusted CAs --cacertfile= Use TLS, validate server using the given certificate --certfile= Client certificate in case client authentication is enabled in borkers --keyfile= Client private key in case client authentication is enabled in borkers --sasl-plain= Tell brod to use username/password stored in the given file, the file should have username and password in two lines. --ebin-paths= Comma separated directory names for extra beams, This is to support user compiled message formatters --no-api-vsn-query Do not query api version (for kafka 0.9 or earlier) Or set KAFKA_VERSION environment variable to 0.9 for the same effect " ). -define(META_CMD, "meta"). -define(META_DOC, "usage: brod meta [options] options: -b,--brokers= Comma separated host:port pairs [default: localhost:9092] -t,--topic= Topic name [default: *] -T,--text Print metadata as aligned texts (default) -J,--json Print metadata as JSON object -L,--list List topics, no partition details, Applicable only for --text option -U,--under-replicated Display only under-replicated partitions " ?COMMAND_COMMON_OPTIONS "Text output schema (out of sync replicas are marked with *): brokers : : topics : : [[ERROR] []] : (replicas[*]...) [] " ). -define(OFFSET_CMD, "offset"). -define(OFFSET_DOC, "usage: brod offset [options] options: -b,--brokers= Comma separated host:port pairs [default: localhost:9092] -t,--topic= Topic name -p,--partition= Partition number [default: all] -T,--time=