Jelajahi Sumber

fix: count all msg size of `event_message` for mqtt bridge

JimMoen 3 tahun lalu
induk
melakukan
449239d0f4
1 mengubah file dengan 4 tambahan dan 1 penghapusan
  1. 4 1
      apps/emqx_connector/src/mqtt/emqx_connector_mqtt_msg.erl

+ 4 - 1
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.
 %% @doc Estimate the size of a message.
 %% Count only the topic length + payload size
 %% 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().
 -spec estimate_size(msg()) -> integer().
 estimate_size(#message{topic = Topic, payload = Payload}) ->
 estimate_size(#message{topic = Topic, payload = Payload}) ->
     size(Topic) + size(Payload);
     size(Topic) + size(Payload);
 estimate_size(#{topic := Topic, payload := 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) ->
 set_headers(undefined, Msg) ->
     Msg;
     Msg;