27
27
-include_lib("amqp_client/include/amqp_client.hrl").
28
28
-import(rabbit_misc, [pget/3]).
29
-import(rabbit_federation_util, [pget_bin/2, pget_bin/3]).
31
30
start(_Type, _StartArgs) ->
32
{ok, Xs} = application:get_env(exchanges),
33
[declare_exchange(X) || X <- Xs],
34
31
rabbit_federation_link:go(),
35
32
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
40
%%----------------------------------------------------------------------------
42
declare_exchange(Props) ->
43
{ok, DefaultVHost} = application:get_env(rabbit, default_vhost),
44
VHost = pget_bin(virtual_host, Props, DefaultVHost),
45
Params = rabbit_federation_util:local_params(VHost),
46
{ok, Conn} = amqp_connection:start(Params),
47
{ok, Ch} = amqp_connection:open_channel(Conn),
48
XNameBin = pget_bin(exchange, Props),
50
Ch, #'exchange.declare'{
52
type = <<"x-federation">>,
53
durable = pget(durable, Props, true),
54
auto_delete = pget(auto_delete, Props, false),
55
internal = pget(internal, Props, false),
57
[{<<"upstream-set">>, longstr, pget_bin(upstream_set, Props)},
58
{<<"type">>, longstr, pget_bin(type, Props)}]}),
59
amqp_channel:close(Ch),
60
amqp_connection:close(Conn),
63
36
%%----------------------------------------------------------------------------
65
38
init([]) -> {ok, {{one_for_one, 3, 10}, []}}.