Current section

113 Versions

Jump to

Compare versions

20 files changed
+450 additions
-293 deletions
  @@ -8,14 +8,14 @@ DEPS = supervisor3 kafka_protocol
8 8 ERLC_OPTS = -Werror +warn_unused_vars +warn_shadow_vars +warn_unused_import +warn_obsolete_guard +debug_info -Dbuild_brod_cli
9 9
10 10 dep_supervisor3_commit = 1.1.8
11 - dep_kafka_protocol_commit = 2.3.1
11 + dep_kafka_protocol_commit = 2.3.2
12 12 dep_kafka_protocol = git https://github.com/klarna/kafka_protocol.git $(dep_kafka_protocol_commit)
13 13
14 14 EDOC_OPTS = preprocess, {macros, [{build_brod_cli, true}]}
15 15
16 16 ## Make app the default target
17 17 ## To avoid building a release when brod is used as a erlang.mk project's dependency
18 - app:: vsn-check
18 + app::
19 19
20 20 include erlang.mk
  @@ -1,9 +1,9 @@
1 1 {<<"name">>,<<"brod">>}.
2 - {<<"version">>,<<"3.9.2">>}.
2 + {<<"version">>,<<"3.9.3">>}.
3 3 {<<"requirements">>,
4 4 #{<<"kafka_protocol">> =>
5 5 #{<<"app">> => <<"kafka_protocol">>,<<"optional">> => false,
6 - <<"requirement">> => <<"2.3.1">>},
6 + <<"requirement">> => <<"2.3.2">>},
7 7 <<"supervisor3">> =>
8 8 #{<<"app">> => <<"supervisor3">>,<<"optional">> => false,
9 9 <<"requirement">> => <<"1.1.8">>}}}.
  @@ -1,5 +1,5 @@
1 1 {deps, [ {supervisor3, "1.1.8"}
2 - , {kafka_protocol, "2.3.1"}
2 + , {kafka_protocol, "2.3.2"}
3 3 ]}.
4 4 {edoc_opts, [{preprocess, true}, {macros, [{build_brod_cli, true}]}]}.
5 5 {erl_opts, [warn_unused_vars,warn_shadow_vars,warn_unused_import,warn_obsolete_guard,debug_info]}.
  @@ -1,6 +1,6 @@
1 1 {application,brod,
2 2 [{description,"Apache Kafka Erlang client library"},
3 - {vsn,"3.9.2"},
3 + {vsn,"3.9.3"},
4 4 {registered,[]},
5 5 {applications,[kernel,stdlib,kafka_protocol,supervisor3]},
6 6 {env,[]},
  @@ -246,8 +246,8 @@
246 246 -type fetch_opts() :: kpro:fetch_opts().
247 247 -type fold_acc() :: term().
248 248 -type fold_fun(Acc) :: fun((message(), Acc) -> {ok, Acc} | {error, any()}).
249 - %% fold always returns when reaches the high watermark offset
250 - %% fold also returns when any of the limits is hit
249 + %% `fold' always returns when reaches the high watermark offset. `fold'
250 + %% also returns when any of the limits is hit.
251 251 -type fold_limits() :: #{ message_count => pos_integer()
252 252 , reach_offset => offset()
253 253 }.
  @@ -255,7 +255,7 @@
255 255 | reached_message_count_limit
256 256 | reached_target_offset
257 257 | {error, any()}.
258 - %% OffsetToContinue: begin offset for the next fold call
258 + %% OffsetToContinue: begin offset for the next fold call
259 259 -type fold_result() :: ?BROD_FOLD_RET(fold_acc(),
260 260 OffsetToContinue :: offset(),
261 261 fold_stop_reason()).
  @@ -291,78 +291,102 @@ start_client(BootstrapEndpoints, ClientId) ->
291 291
292 292 %% @doc Start a client.
293 293 %%
294 - %% BootstrapEndpoints:
295 - %% Kafka cluster endpoints, can be any of the brokers in the cluster
296 - %% which does not necessarily have to be a leader of any partition,
297 - %% e.g. a load-balanced entrypoint to the remote kakfa cluster.
294 + %% `BootstrapEndpoints':
295 + %% Kafka cluster endpoints, can be any of the brokers in the cluster,
296 + %% which does not necessarily have to be the leader of any partition,
297 + %% e.g. a load-balanced entrypoint to the remote Kafka cluster.
298 298 %%
299 - %% ClientId: Atom to identify the client process.
299 + %% `ClientId': Atom to identify the client process.
300 300 %%
301 - %% Config is a proplist, possible values:
302 - %% restart_delay_seconds (optional, default=10)
303 - %% How much time to wait between attempts to restart brod_client
304 - %% process when it crashes
301 + %% `Config' is a proplist, possible values:
302 + %% <ul>
303 + %% <li>`restart_delay_seconds' (optional, default=10)
304 + %%
305 + %% How long to wait between attempts to restart brod_client
306 + %% process when it crashes.</li>
307 + %%
308 + %% <li>`get_metadata_timeout_seconds' (optional, default=5)
305 309 %%
306 - %% get_metadata_timeout_seconds (optional, default=5)
307 310 %% Return `{error, timeout}' from `brod_client:get_xxx' calls if
308 311 %% responses for APIs such as `metadata', `find_coordinator'
309 - %% is not received in time.
312 + %% are not received in time.</li>
313 + %%
314 + %% <li>`reconnect_cool_down_seconds' (optional, default=1)
310 315 %%
311 - %% reconnect_cool_down_seconds (optional, default=1)
312 316 %% Delay this configured number of seconds before retrying to
313 - %% estabilish a new connection to the kafka partition leader.
317 + %% estabilish a new connection to the kafka partition leader.</li>
314 318 %%
315 - %% allow_topic_auto_creation (optional, default=true)
316 - %% By default, brod respects what is configured in broker about
317 - %% topic auto-creation. i.e. whatever `auto.create.topics.enable'
318 - %% is set in broker configuration.
319 - %% However if `allow_topic_auto_creation' is set to `false' in client
320 - %% config, brod will avoid sending metadata requests that may cause an
321 - %% auto-creation of the topic regardless of what broker config is.
319 + %% <li>`allow_topic_auto_creation' (optional, default=true)
320 + %%
321 + %% By default, brod respects what is configured in the broker
322 + %% about topic auto-creation. i.e. whether
323 + %% `auto.create.topics.enable' is set in the broker configuration.
324 + %% However if `allow_topic_auto_creation' is set to `false' in
325 + %% client config, brod will avoid sending metadata requests that
326 + %% may cause an auto-creation of the topic regardless of what
327 + %% broker config is.</li>
328 + %%
329 + %% <li>`auto_start_producers' (optional, default=false)
322 330 %%
323 - %% auto_start_producers (optional, default=false)
324 331 %% If true, brod client will spawn a producer automatically when
325 332 %% user is trying to call `produce' but did not call `brod:start_producer'
326 333 %% explicitly. Can be useful for applications which don't know beforehand
327 - %% which topics they will be working with.
334 + %% which topics they will be working with.</li>
335 + %%
336 + %% <li>`default_producer_config' (optional, default=[])
328 337 %%
329 - %% default_producer_config (optional, default=[])
330 338 %% Producer configuration to use when auto_start_producers is true.
331 - %% @see brod_producer:start_link/4. for details about producer config
339 + %% See `brod_producer:start_link/4' for details about producer config</li>
332 340 %%
333 - %% Connection config entries can be added in the same proplist.
334 - %% see `kpro_connection.erl' in `kafka_protocol' for more details.
341 + %% </ul>
342 + %%
343 + %% Connection options can be added to the same proplist. See
344 + %% `kpro_connection.erl' in `kafka_protocol' for the details:
345 + %%
346 + %% <ul>
347 + %% <li>`ssl' (optional, default=false)
335 348 %%
336 - %% ssl (optional, default=false)
337 349 %% `true | false | ssl:ssl_option()'
338 350 %% `true' is translated to `[]' as `ssl:ssl_option()' i.e. all default.
351 + %% </li>
352 + %%
353 + %% <li>`sasl' (optional, default=undefined)
339 354 %%
340 - %% sasl (optional, default=undefined)
341 355 %% Credentials for SASL/Plain authentication.
342 356 %% `{mechanism(), Filename}' or `{mechanism(), UserName, Password}'
343 - %% where mechanism can be atoms: plain (for "PLAIN"), scram_sha_256
344 - %% (for "SCRAM-SHA-256") or scram_sha_512 (for SCRAM-SHA-512).
357 + %% where mechanism can be atoms: `plain' (for "PLAIN"), `scram_sha_256'
358 + %% (for "SCRAM-SHA-256") or `scram_sha_512' (for SCRAM-SHA-512).
345 359 %% `Filename' should be a file consisting two lines, first line
346 - %% is the username and second line is the password.
347 - %% `Username', `Password' should be `string() | binary()'
360 + %% is the username and the second line is the password.
361 + %% Both `Username' and `Password' should be `string() | binary()'</li>
348 362 %%
349 - %% connect_timeout (optional, default=5000)
350 - %% Timeout when trying to connect to an endpoint.
363 + %% <li>`connect_timeout' (optional, default=5000)
364 + %%
365 + %% Timeout when trying to connect to an endpoint.</li>
366 + %%
367 + %% <li>`request_timeout' (optional, default=240000, constraint: >= 1000)
368 + %%
369 + %% Timeout when waiting for a response, connection restart when timed
370 + %% out.</li>
371 + %%
372 + %% <li>`query_api_versions' (optional, default=true)
351 373 %%
352 - %% request_timeout (optional, default=240000, constraint: >= 1000)
353 - %% Timeout when waiting for a response, connection restart when timed out.
354 - %% query_api_versions (optional, default=true)
355 374 %% Must be set to false to work with kafka versions prior to 0.10,
356 375 %% When set to `true', at connection start, brod will send a query request
357 376 %% to get the broker supported API version ranges.
358 377 %% When set to 'false', brod will alway use the lowest supported API version
359 378 %% when sending requests to kafka.
360 379 %% Supported API version ranges can be found in:
361 - %% `brod_kafka_apis:supported_versions/1'
362 - %% extra_sock_opts (optional, default=[])
380 + %% `brod_kafka_apis:supported_versions/1'</li>
381 + %%
382 + %% <li>`extra_sock_opts' (optional, default=[])
383 + %%
363 384 %% Extra socket options to tune socket performance.
364 - %% e.g. [{sndbuf, 1 bsl 20}].
365 - %% ref: http://erlang.org/doc/man/gen_tcp.html#type-option
385 + %% e.g. `[{sndbuf, 1 bsl 20}]'.
386 + %% <a href="http://erlang.org/doc/man/gen_tcp.html#type-option">More info
387 + %% </a>
388 + %% </li>
389 + %% </ul>
366 390 -spec start_client([endpoint()], client_id(), client_config()) ->
367 391 ok | {error, any()}.
368 392 start_client(BootstrapEndpoints, ClientId, Config) ->
  @@ -399,7 +423,7 @@ stop_client(Client) when is_pid(Client) ->
399 423 brod_client:stop(Client).
400 424
401 425 %% @doc Dynamically start a per-topic producer.
402 - %% @see brod_producer:start_link/4. for details about producer config.
426 + %% @see brod_producer:start_link/4
403 427 -spec start_producer(client(), topic(), producer_config()) ->
404 428 ok | {error, any()}.
405 429 start_producer(Client, TopicName, ProducerConfig) ->
  @@ -447,29 +471,29 @@ get_producer(Client, Topic, Partition) ->
447 471 produce(Pid, Value) ->
448 472 produce(Pid, _Key = <<>>, Value).
449 473
450 - %% @doc Produce one message if Value is binary or iolist,
451 - %% Or send a batch if Value is a (nested) kv-list or a list of maps,
452 - %% in this case Key is discarded (only the keys in kv-list are sent to kafka).
453 - %% The pid should be a partition producer pid, NOT client pid.
454 - %% The return value is a call reference of type `call_ref()',
455 - %% so the caller can used it to expect (match) a
456 - %% `#brod_produce_reply{result = brod_produce_req_acked}'
457 - %% message after the produce request has been acked by kafka.
474 + %% @doc Produce one message if `Value' is a binary or an
475 + %% iolist. Otherwise send a batch, if `Value' is a (nested) key-value
476 + %% list, or a list of maps. In this case `Key' is discarded (only the
477 + %% keys in the key-value list are sent to Kafka). The pid should be a
478 + %% partition producer pid, NOT client pid. The return value is a call
479 + %% reference of type `call_ref()', so the caller can use it to expect
480 + %% (match) a `#brod_produce_reply{result = brod_produce_req_acked}'
481 + %% message after the produce request has been acked by Kafka.
458 482 -spec produce(pid(), key(), value()) ->
459 483 {ok, call_ref()} | {error, any()}.
460 484 produce(ProducerPid, Key, Value) ->
461 485 brod_producer:produce(ProducerPid, Key, Value).
462 486
463 - %% @doc Produce one message if Value is binary or iolist,
464 - %% Or send a batch if Value is a (nested) kv-list or a list of maps,
465 - %% in this case Key is used only for partitioning, or discarded if the 3rd
466 - %% arg is a partition number instead of a partitioner callback.
467 - %% This function first lookup the producer pid,
468 - %% then call `produce/3' to do the real work.
469 - %% The return value is a call reference of type `call_ref()',
470 - %% so the caller can used it to expect (match) a
471 - %% `#brod_produce_reply{result = brod_produce_req_acked}'
472 - %% message after the produce request has been acked by kafka.
487 + %% @doc Produce one message if `Value' is a binary or an iolist.
488 + %% Otherwise send a batch if `Value' is a (nested) key-value list, or
489 + %% a list of maps. In this case `Key' is used only for partitioning,
490 + %% or discarded if the 3rd argument is a partition number instead of a
491 + %% partitioner callback. This function first looks up the producer
492 + %% pid, then calls `produce/3' to do the real work. The return value
493 + %% is a call reference of type `call_ref()', so the caller can used it
494 + %% to expect (match) a `#brod_produce_reply{result =
495 + %% brod_produce_req_acked}' message after the produce request has been
496 + %% acked by Kafka.
473 497 -spec produce(client(), topic(), partition() | partitioner(),
474 498 key(), value()) -> {ok, call_ref()} | {error, any()}.
475 499 produce(Client, Topic, Partition, Key, Value) when is_integer(Partition) ->
  @@ -487,7 +511,7 @@ produce(Client, Topic, Partitioner, Key, Value) ->
487 511 {error, Reason}
488 512 end.
489 513
490 - %% @doc Same as `produce/3' only the ack is not delivered as a message,
514 + %% @doc Same as `produce/3', only the ack is not delivered as a message,
491 515 %% instead, the callback is evaluated by producer worker when ack is received
492 516 %% from kafka.
493 517 -spec produce_cb(pid(), key(), value(), produce_ack_cb()) ->
  @@ -522,14 +546,14 @@ produce_cb(Client, Topic, Partitioner, Key, Value, AckCb) ->
522 546
523 547 %% @doc Send the message to partition worker without any ack.
524 548 %% NOTE: This call has no back-pressure to the caller,
525 - %% excessive usage may cause beam to run out of memory.
549 + %% excessive usage may cause BEAM to run out of memory.
526 550 -spec produce_no_ack(pid(), key(), value()) -> ok | {error, any()}.
527 551 produce_no_ack(ProducerPid, Key, Value) ->
528 552 brod_producer:produce_no_ack(ProducerPid, Key, Value).
529 553
530 554 %% @doc Find the partition worker and send message without any ack.
531 555 %% NOTE: This call has no back-pressure to the caller,
532 - %% excessive usage may cause beam to run out of memory.
556 + %% excessive usage may cause BEAM to run out of memory.
533 557 -spec produce_no_ack(client(), topic(), partition() | partitioner(),
534 558 key(), value()) -> ok | {error, any()}.
535 559 produce_no_ack(Client, Topic, Part, Key, Value) when is_integer(Part) ->
  @@ -555,9 +579,11 @@ produce_sync(Pid, Value) ->
555 579 produce_sync(Pid, _Key = <<>>, Value).
556 580
557 581 %% @doc Sync version of produce/3
558 - %% This function will not return until a response is received from kafka,
559 - %% however if producer is started with required_acks set to 0, this function
560 - %% will return onece the messages is buffered in the producer process.
582 + %%
583 + %% This function will not return until the response is received from
584 + %% Kafka. But when producer is started with `required_acks' set to 0,
585 + %% this function will return once the messages are buffered in the
586 + %% producer process.
561 587 -spec produce_sync(pid(), key(), value()) ->
562 588 ok | {error, any()}.
563 589 produce_sync(Pid, Key, Value) ->
  @@ -620,18 +646,22 @@ sync_produce_request_offset(CallRef) ->
620 646 sync_produce_request_offset(CallRef, Timeout) ->
621 647 brod_producer:sync_produce_request(CallRef, Timeout).
622 648
623 - %% @doc Subscribe data stream from the given topic-partition.
624 - %% If {error, Reason} is returned, the caller should perhaps retry later.
625 - %% {ok, ConsumerPid} is returned if success, the caller may want to monitor
626 - %% the consumer pid to trigger a re-subscribe in case it crashes.
649 + %% @doc Subscribe to a data stream from the given topic-partition.
627 650 %%
628 - %% If subscribed successfully, the subscriber process should expect messages
651 + %% If `{error, Reason}' is returned, the caller should perhaps retry later.
652 + %%
653 + %% `{ok, ConsumerPid}' is returned on success. The caller may want to
654 + %% monitor the consumer pid and re-subscribe should the `ConsumerPid' crash.
655 + %%
656 + %% Upon successful subscription the subscriber process should expect messages
629 657 %% of pattern:
630 - %% {ConsumerPid, #kafka_message_set{}} and
631 - %% {ConsumerPid, #kafka_fetch_error{}},
632 - %% -include_lib(brod/include/brod.hrl) to access the records.
633 - %% In case #kafka_fetch_error{} is received the subscriber should re-subscribe
634 - %% itself to resume the data stream.
658 + %% `{ConsumerPid, #kafka_message_set{}}' and
659 + %% `{ConsumerPid, #kafka_fetch_error{}}'.
660 + %%
661 + %% `-include_lib("brod/include/brod.hrl")' to access the records.
662 + %%
663 + %% In case `#kafka_fetch_error{}' is received the subscriber should
664 + %% re-subscribe itself to resume the data stream.
635 665 -spec subscribe(client(), pid(), topic(), partition(),
636 666 consumer_options()) -> {ok, pid()} | {error, any()}.
637 667 subscribe(Client, SubscriberPid, Topic, Partition, Options) ->
  @@ -649,7 +679,8 @@ subscribe(Client, SubscriberPid, Topic, Partition, Options) ->
649 679 subscribe(ConsumerPid, SubscriberPid, Options) ->
650 680 brod_consumer:subscribe(ConsumerPid, SubscriberPid, Options).
651 681
652 - %% @doc Unsubscribe the current subscriber. Assuming the subscriber is self().
682 + %% @doc Unsubscribe the current subscriber. Assuming the subscriber is
683 + %% `self()'.
653 684 -spec unsubscribe(client(), topic(), partition()) -> ok | {error, any()}.
654 685 unsubscribe(Client, Topic, Partition) ->
655 686 unsubscribe(Client, Topic, Partition, self()).
  @@ -662,7 +693,8 @@ unsubscribe(Client, Topic, Partition, SubscriberPid) ->
662 693 Error -> Error
663 694 end.
664 695
665 - %% @doc Unsubscribe the current subscriber. Assuming the subscriber is self().
696 + %% @doc Unsubscribe the current subscriber. Assuming the subscriber is
697 + %% `self()'.
666 698 -spec unsubscribe(pid()) -> ok | {error, any()}.
667 699 unsubscribe(ConsumerPid) ->
668 700 unsubscribe(ConsumerPid, self()).
  @@ -684,7 +716,7 @@ consume_ack(Client, Topic, Partition, Offset) ->
684 716 consume_ack(ConsumerPid, Offset) ->
685 717 brod_consumer:ack(ConsumerPid, Offset).
686 718
687 - %% @equiv brod_group_subscriber:start_link/7
719 + %% @see brod_group_subscriber:start_link/7
688 720 -spec start_link_group_subscriber(
689 721 client(), group_id(), [topic()],
690 722 group_config(), consumer_config(), module(), term()) ->
  @@ -701,7 +733,7 @@ start_link_group_subscriber(Client, GroupId, Topics, GroupConfig,
701 733 start_link_group_subscriber_v2(Config) ->
702 734 brod_group_subscriber_v2:start_link(Config).
703 735
704 - %% @equiv brod_group_subscriber:start_link/8
736 + %% @see brod_group_subscriber:start_link/8
705 737 -spec start_link_group_subscriber(
706 738 client(), group_id(), [topic()], group_config(),
707 739 consumer_config(), message | message_set,
  @@ -736,7 +768,7 @@ start_link_topic_subscriber(Client, Topic, Partitions,
736 768 start_link_topic_subscriber(Client, Topic, Partitions,
737 769 ConsumerConfig, message, CbModule, CbInitArg).
738 770
739 - %% @equiv brod_topic_subscriber:start_link/7
771 + %% @see brod_topic_subscriber:start_link/7
740 772 -spec start_link_topic_subscriber(
741 773 client(), topic(), all | [partition()],
742 774 consumer_config(), message | message_set,
  @@ -908,9 +940,15 @@ describe_groups(CoordinatorEndpoint, ConnCfg, IDs) ->
908 940 brod_utils:describe_groups(CoordinatorEndpoint, ConnCfg, IDs).
909 941
910 942 %% @doc Connect to consumer group coordinator broker.
911 - %% Done in steps: 1) connect to any of the given bootstrap ednpoints;
912 - %% 2) send group_coordinator_request to resolve group coordinator endpoint;;
913 - %% 3) connect to the resolved endpoint and return the connection pid
943 + %%
944 + %% Done in steps: <ol>
945 + %% <li>Connect to any of the given bootstrap ednpoints</li>
946 + %%
947 + %% <li>Send group_coordinator_request to resolve group coordinator
948 + %% endpoint</li>
949 + %%
950 + %% <li>Connect to the resolved endpoint and return the connection
951 + %% pid</li></ol>
914 952 -spec connect_group_coordinator([endpoint()], conn_config(), group_id()) ->
915 953 {ok, pid()} | {error, any()}.
916 954 connect_group_coordinator(BootstrapEndpoints, ConnCfg, GroupId) ->
Loading more files…