-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubidots_emqx_retainer_payload_changer.erl
42 lines (34 loc) · 1.41 KB
/
ubidots_emqx_retainer_payload_changer.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%%%-------------------------------------------------------------------
%%% @author ubidots
%%% @copyright (C) 2019, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 19. Sep 2019 1:20 p. m.
%%%-------------------------------------------------------------------
-module(ubidots_emqx_retainer_payload_changer).
-author("ubidots").
-include_lib("eunit/include/eunit.hrl").
%% API
-export([get_retained_messages_from_topic/4]).
get_variables_from_topic(Pool, Type, Topic) ->
{ok, Result} = ubidots_emqx_reactor_redis_cli:get_variables_from_topic(Pool, Type, Topic),
Result.
get_values_variables(Pool, Type, VariablesData) ->
{ok, Result} =
ubidots_emqx_core_redis_cli:get_values_variables(Pool, Type, VariablesData),
Result.
get_values_from_topic(Topic, Env, PoolReactor, PoolCore) ->
UbidotsRedisType = maps:get(ubidots_cache_type, Env, single),
ReactorRedisType = maps:get(reactor_cache_type, Env, single),
VariablesData = get_variables_from_topic(PoolReactor, ReactorRedisType, Topic),
Values = get_values_variables(PoolCore, UbidotsRedisType, VariablesData),
Values.
get_messages([]) ->
[];
get_messages([Topic, Value | Rest]) ->
NewMessage = emqx_message:make(Topic, Value),
[NewMessage | get_messages(Rest)].
get_retained_messages_from_topic(Topic, Env, PoolReactor, PoolCore) ->
Values = get_values_from_topic(Topic, Env, PoolReactor, PoolCore),
get_messages(Values).