Current section

113 Versions

Jump to

Compare versions

10 files changed
+236 additions
-86 deletions
  @@ -1,6 +1,6 @@
1 1 PROJECT = brod
2 2 PROJECT_DESCRIPTION = Kafka client library in Erlang
3 - PROJECT_VERSION = 2.2.12
3 + PROJECT_VERSION = 2.2.14
4 4
5 5 DEPS = supervisor3 kafka_protocol
  @@ -1,5 +1,5 @@
1 1 {<<"name">>,<<"brod">>}.
2 - {<<"version">>,<<"2.2.12">>}.
2 + {<<"version">>,<<"2.2.14">>}.
3 3 {<<"requirements">>,
4 4 #{<<"kafka_protocol">> => #{<<"app">> => <<"kafka_protocol">>,
5 5 <<"optional">> => false,
  @@ -1,6 +1,6 @@
1 1 {application,brod,
2 2 [{description,"Apache Kafka Erlang client library"},
3 - {vsn,"2.2.12"},
3 + {vsn,"2.2.14"},
4 4 {registered,[]},
5 5 {applications,[kernel,stdlib,ssl,kafka_protocol,supervisor3]},
6 6 {env,[]},
  @@ -136,8 +136,7 @@ start_client(BootstrapEndpoints) ->
136 136 start_client(BootstrapEndpoints, ?BROD_DEFAULT_CLIENT_ID).
137 137
138 138 %% @equiv stat_client(BootstrapEndpoints, ClientId, [])
139 - -spec start_client([endpoint()], brod_client_id()) ->
140 - ok | {error, any()}.
139 + -spec start_client([endpoint()], brod_client_id()) -> ok | {error, any()}.
141 140 start_client(BootstrapEndpoints, ClientId) ->
142 141 start_client(BootstrapEndpoints, ClientId, []).
143 142
  @@ -173,9 +172,15 @@ start_client(BootstrapEndpoints, ClientId) ->
173 172 %% user is trying to call 'produce' but did not call
174 173 %% brod:start_producer explicitly. Can be useful for applications
175 174 %% which don't know beforehand which topics they will be working with.
176 - %% default_producer_config (optional, default [])
175 + %% default_producer_config (optional, default=[])
177 176 %% Producer configuration to use when auto_start_producers is true.
178 177 %% @see brod_client:start_producer/3. for more details.
178 + %% ssl (optional, default=[])
179 + %% [{certfile, ...},{keyfiel, ...},{cacertfile, ...}]
180 + %% connect_timeout (optional, default=5000)
181 + %% Timeout when trying to connect to one endpoint.
182 + %% request_timeout (optional, default=120000, constraint: >= 1000)
183 + %% Timeout when waiting for a response, socket restart when timedout.
179 184 %% @end
180 185 -spec start_client([endpoint()], brod_client_id(), client_config()) ->
181 186 ok | {error, any()}.
  @@ -77,14 +77,6 @@
77 77
78 78 -define(UNKNOWN_TOPIC_CACHE_EXPIRE_SECONDS, 120).
79 79
80 - -define(TRY_CLIENT_ETS_LOOKUP(Expr),
81 - try
82 - Expr
83 - catch
84 - error : badarg ->
85 - {error, client_down}
86 - end).
87 -
88 80 -type partition_worker_key() :: ?PRODUCER_KEY(topic(), partition())
89 81 | ?CONSUMER_KEY(topic(), partition()).
90 82
  @@ -455,20 +447,22 @@ get_partition_worker(ClientId, Key) when is_atom(ClientId) ->
455 447 -spec lookup_partition_worker(client(), ets:tab(), partition_worker_key()) ->
456 448 {ok, pid()} | { error, get_worker_error()}.
457 449 lookup_partition_worker(Client, Ets, Key) ->
458 - ?TRY_CLIENT_ETS_LOOKUP(
459 - case ets:lookup(Ets, Key) of
460 - [] ->
461 - %% not yet registered, 2 possible reasons:
462 - %% 1. caller is too fast, producers/consumers are starting up
463 - %% make a synced call all the way down the supervision tree
464 - %% to the partition producer sup should resolve the race
465 - %% 2. bad argument, no such worker started, supervisors should know
466 - find_partition_worker(Client, Key);
467 - [?PRODUCER(_Topic, _Partition, Pid)] ->
468 - {ok, Pid};
469 - [?CONSUMER(_Topic, _Partition, Pid)] ->
470 - {ok, Pid}
471 - end).
450 + try ets:lookup(Ets, Key) of
451 + [] ->
452 + %% not yet registered, 2 possible reasons:
453 + %% 1. caller is too fast, producers/consumers are starting up
454 + %% make a synced call all the way down the supervision tree
455 + %% to the partition producer sup should resolve the race
456 + %% 2. bad argument, no such worker started, supervisors should know
457 + find_partition_worker(Client, Key);
458 + [?PRODUCER(_Topic, _Partition, Pid)] ->
459 + {ok, Pid};
460 + [?CONSUMER(_Topic, _Partition, Pid)] ->
461 + {ok, Pid}
462 + catch
463 + error : badarg ->
464 + {error, client_down}
465 + end.
472 466
473 467 -spec find_partition_worker(client(), partition_worker_key()) ->
474 468 {ok, pid()} | {error, get_worker_error()}.
  @@ -743,19 +737,21 @@ get_partitions_count(Client, Ets, Topic) ->
743 737 {ok, pos_integer()} | {error, any()} | false.
744 738 lookup_partitions_count_cache(_Ets, ?undef) -> false;
745 739 lookup_partitions_count_cache(Ets, Topic) ->
746 - ?TRY_CLIENT_ETS_LOOKUP(
747 - case ets:lookup(Ets, ?TOPIC_METADATA_KEY(Topic)) of
748 - [{_, Count, _Ts}] when is_integer(Count) ->
749 - {ok, Count};
750 - [{_, {error, Reason}, Ts}] ->
751 - case timer:now_diff(os:timestamp(), Ts) =<
752 - ?UNKNOWN_TOPIC_CACHE_EXPIRE_SECONDS * 1000000 of
753 - true -> {error, Reason};
754 - false -> false
755 - end;
756 - [] ->
757 - false
758 - end).
740 + try ets:lookup(Ets, ?TOPIC_METADATA_KEY(Topic)) of
741 + [{_, Count, _Ts}] when is_integer(Count) ->
742 + {ok, Count};
743 + [{_, {error, Reason}, Ts}] ->
744 + case timer:now_diff(os:timestamp(), Ts) =<
745 + ?UNKNOWN_TOPIC_CACHE_EXPIRE_SECONDS * 1000000 of
746 + true -> {error, Reason};
747 + false -> false
748 + end;
749 + [] ->
750 + false
751 + catch
752 + error : badarg ->
753 + {error, client_down}
754 + end.
759 755
760 756 -spec do_get_partitions_count(kpro_TopicMetadata()) ->
761 757 {ok, pos_integer()} | {error, any()}.
Loading more files…