refactor(kafka_consumer): apply review suggestions
This commit is contained in:
parent
2a3aef92bb
commit
fecc08bb8f
|
@ -274,7 +274,9 @@ fields(consumer_kafka_opts) ->
|
||||||
})},
|
})},
|
||||||
{max_rejoin_attempts,
|
{max_rejoin_attempts,
|
||||||
mk(non_neg_integer(), #{
|
mk(non_neg_integer(), #{
|
||||||
default => 5, desc => ?DESC(consumer_max_rejoin_attempts)
|
hidden => true,
|
||||||
|
default => 5,
|
||||||
|
desc => ?DESC(consumer_max_rejoin_attempts)
|
||||||
})},
|
})},
|
||||||
{offset_reset_policy,
|
{offset_reset_policy,
|
||||||
mk(
|
mk(
|
||||||
|
|
|
@ -129,7 +129,7 @@ on_start(InstanceId, Config) ->
|
||||||
}),
|
}),
|
||||||
throw(failed_to_start_kafka_client)
|
throw(failed_to_start_kafka_client)
|
||||||
end,
|
end,
|
||||||
start_subscriber(Config, InstanceId, ClientID).
|
start_consumer(Config, InstanceId, ClientID).
|
||||||
|
|
||||||
-spec on_stop(manager_id(), state()) -> ok.
|
-spec on_stop(manager_id(), state()) -> ok.
|
||||||
on_stop(_InstanceID, State) ->
|
on_stop(_InstanceID, State) ->
|
||||||
|
@ -169,7 +169,10 @@ handle_message(Message, State) ->
|
||||||
?tp_span(
|
?tp_span(
|
||||||
kafka_consumer_handle_message,
|
kafka_consumer_handle_message,
|
||||||
#{message => Message, state => State},
|
#{message => Message, state => State},
|
||||||
begin
|
do_handle_message(Message, State)
|
||||||
|
).
|
||||||
|
|
||||||
|
do_handle_message(Message, State) ->
|
||||||
#{
|
#{
|
||||||
resource_id := ResourceId,
|
resource_id := ResourceId,
|
||||||
hookpoint := Hookpoint,
|
hookpoint := Hookpoint,
|
||||||
|
@ -203,9 +206,7 @@ handle_message(Message, State) ->
|
||||||
emqx_resource_metrics:received_inc(ResourceId),
|
emqx_resource_metrics:received_inc(ResourceId),
|
||||||
%% note: just `ack' does not commit the offset to the
|
%% note: just `ack' does not commit the offset to the
|
||||||
%% kafka consumer group.
|
%% kafka consumer group.
|
||||||
{ok, commit, State}
|
{ok, commit, State}.
|
||||||
end
|
|
||||||
).
|
|
||||||
|
|
||||||
%%-------------------------------------------------------------------------------------
|
%%-------------------------------------------------------------------------------------
|
||||||
%% Helper fns
|
%% Helper fns
|
||||||
|
@ -241,8 +242,8 @@ ensure_consumer_supervisor_started() ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec start_subscriber(config(), manager_id(), brod:client_id()) -> {ok, state()}.
|
-spec start_consumer(config(), manager_id(), brod:client_id()) -> {ok, state()}.
|
||||||
start_subscriber(Config, InstanceId, ClientID) ->
|
start_consumer(Config, InstanceId, ClientID) ->
|
||||||
#{
|
#{
|
||||||
bootstrap_hosts := BootstrapHosts0,
|
bootstrap_hosts := BootstrapHosts0,
|
||||||
bridge_name := BridgeName,
|
bridge_name := BridgeName,
|
||||||
|
@ -256,7 +257,7 @@ start_subscriber(Config, InstanceId, ClientID) ->
|
||||||
},
|
},
|
||||||
mqtt := #{topic := MQTTTopic, qos := MQTTQoS, payload := MQTTPayload}
|
mqtt := #{topic := MQTTTopic, qos := MQTTQoS, payload := MQTTPayload}
|
||||||
} = Config,
|
} = Config,
|
||||||
ensure_consumer_supervisor_started(),
|
ok = ensure_consumer_supervisor_started(),
|
||||||
InitialState = #{
|
InitialState = #{
|
||||||
resource_id => emqx_bridge_resource:resource_id(kafka_consumer, BridgeName),
|
resource_id => emqx_bridge_resource:resource_id(kafka_consumer, BridgeName),
|
||||||
mqtt => #{
|
mqtt => #{
|
||||||
|
|
Loading…
Reference in New Issue