Packages
diint_utilites_common_app
1.0.13
1.4.23
1.4.22
1.4.21
1.4.20
1.4.19
1.4.18
1.4.17
1.4.16
1.4.15
1.4.14
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.9
1.3.8
1.3.7
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.101
1.2.11
1.2.10
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.13
1.0.12
1.0.11
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
библиотеки для работы с ребитом и протоколы
Current section
Files
Jump to
Current section
Files
src/mq/rabbit_utilites.erl
%%%-------------------------------------------------------------------
%%% @author cheese
%%% @copyright (C) 2015, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 09. Jan 2015 8:56
%%%-------------------------------------------------------------------
-module(rabbit_utilites).
-author("cheese").
-include("_build/default/lib/amqp_client/include/amqp_client.hrl").
-include("include/types_rabbit.hrl").
%% API
-export([close_rpc_channel/4, convert_array_to_rabbit_connection_config/1]).
-export([connect/3]).
-export([internal_convert_array_to_rabbit_connection_config/2]).
convert_array_to_rabbit_connection_config(Arr) ->
internal_convert_array_to_rabbit_connection_config(Arr, #rabbit_connection_config{}).
internal_convert_array_to_rabbit_connection_config([], Info) ->
Info;
internal_convert_array_to_rabbit_connection_config([{Key, Value} | Tail], Info) ->
case Key of
process_name ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{process_name = Value});
host ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{host = Value});
password ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{password = Value});
username ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{username = Value});
virtual_host ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{ virtual_host = Value});
queue_response ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{ queue_response = Value});
exchange_response ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{ exchange_response = Value});
arguments ->
internal_convert_array_to_rabbit_connection_config(Tail, Info#rabbit_connection_config{ arguments = Value});
_Other ->
internal_convert_array_to_rabbit_connection_config(Tail, Info)
end.
close_rpc_channel(ProcessName, Connection, Channel, LogFile) ->
logger_Cheese:info("Try to close ~w: ~w-~w~n", [ProcessName, Connection, Channel], LogFile),
try amqp_channel:close(Channel) of
ResCloseChannel ->
logger_Cheese:info("Close ~w chanell ~w: ~w~n", [ProcessName, Channel, ResCloseChannel], LogFile),
try amqp_connection:close(Connection) of
ResCloseConnection ->
logger_Cheese:info("Close ~w connection ~w: ~w~n", [ProcessName, Connection, ResCloseConnection], LogFile)
catch
ErrCloseConnection ->
logger_Cheese:info("Close ~w connection ~w error: ~w~n", [ProcessName, Connection, ErrCloseConnection], LogFile)
end
catch
ErrCloseChannel ->
logger_Cheese:info("Close ~w channel ~w error: ~w~n", [ProcessName, Channel, ErrCloseChannel], LogFile)
end.
connect(Process, #rabbit_connection_config{ host=Host, username=Username, password=Password, virtual_host=VirtHost}, LogFile) ->
logger_Cheese:info("Start create connection. Host: ~s, User: ~s, VirtHost: ~s~n", [Host, Username, VirtHost], LogFile),
case amqp_connection:start(#amqp_params_network{host = Host, password = Password, username = Username, heartbeat = 10, frame_max = 8388608, virtual_host = VirtHost}) of
{ok, Connection} ->
logger_Cheese:info("Create ~w connection: ~p~n", [Process, Connection], LogFile),
case amqp_connection:open_channel(Connection) of
{ok, Channel} ->
logger_Cheese:info("Create ~w channel: ~p~n", [Process, Channel], LogFile),
{ok, Connection, Channel};
ErrorChannel ->
logger_Cheese:info("Create ~w connection error: ~p~n", [Process, ErrorChannel], LogFile),
{error, ErrorChannel}
end;
ErrorConnection ->
logger_Cheese:info("Create ~w connection error: ~p~n", [Process, ErrorConnection], LogFile),
{error, ErrorConnection}
end.