From 449239d0f46c56de2f60f827632f1ea6d19bda05 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Fri, 12 Aug 2022 01:29:37 +0800 Subject: [PATCH] fix: count all msg size of `event_message` for mqtt bridge --- apps/emqx_connector/src/mqtt/emqx_connector_mqtt_msg.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/emqx_connector/src/mqtt/emqx_connector_mqtt_msg.erl b/apps/emqx_connector/src/mqtt/emqx_connector_mqtt_msg.erl index 581d2670f..43700506b 100644 --- a/apps/emqx_connector/src/mqtt/emqx_connector_mqtt_msg.erl +++ b/apps/emqx_connector/src/mqtt/emqx_connector_mqtt_msg.erl @@ -142,11 +142,14 @@ from_binary(Bin) -> binary_to_term(Bin). %% @doc Estimate the size of a message. %% Count only the topic length + payload size +%% There is no topic and payload for event message. So count all `Msg` term -spec estimate_size(msg()) -> integer(). estimate_size(#message{topic = Topic, payload = Payload}) -> size(Topic) + size(Payload); estimate_size(#{topic := Topic, payload := Payload}) -> - size(Topic) + size(Payload). + size(Topic) + size(Payload); +estimate_size(Term) -> + erlang:external_size(Term). set_headers(undefined, Msg) -> Msg;