~ubuntu-branches/ubuntu/saucy/rabbitmq-server/saucy

« back to all changes in this revision

Viewing changes to plugins-src/rabbitmq-old-federation/src/rabbit_federation_old_app.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2012-11-19 11:42:31 UTC
  • mfrom: (0.2.18) (0.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20121119114231-hvapkn4akng09etr
Tags: 3.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%% The contents of this file are subject to the Mozilla Public License
 
2
%% Version 1.1 (the "License"); you may not use this file except in
 
3
%% compliance with the License. You may obtain a copy of the License
 
4
%% at http://www.mozilla.org/MPL/
 
5
%%
 
6
%% Software distributed under the License is distributed on an "AS IS"
 
7
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
8
%% the License for the specific language governing rights and
 
9
%% limitations under the License.
 
10
%%
 
11
%% The Original Code is RabbitMQ Federation.
 
12
%%
 
13
%% The Initial Developer of the Original Code is VMware, Inc.
 
14
%% Copyright (c) 2007-2012 VMware, Inc.  All rights reserved.
 
15
%%
 
16
 
 
17
-module(rabbit_federation_old_app).
 
18
 
 
19
-behaviour(application).
 
20
-export([start/2, stop/1]).
 
21
 
 
22
%% This does the same dummy supervisor thing as rabbit_mgmt_app - see the
 
23
%% comment there.
 
24
-behaviour(supervisor).
 
25
-export([init/1]).
 
26
 
 
27
-include_lib("amqp_client/include/amqp_client.hrl").
 
28
-import(rabbit_misc, [pget/3]).
 
29
-import(rabbit_federation_old_util, [pget_bin/2, pget_bin/3]).
 
30
 
 
31
start(_Type, _StartArgs) ->
 
32
    {ok, Xs} = application:get_env(rabbitmq_old_federation, exchanges),
 
33
    [declare_exchange(X) || X <- Xs],
 
34
    rabbit_federation_old_link:go(),
 
35
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
36
 
 
37
stop(_State) ->
 
38
    ok.
 
39
 
 
40
%%----------------------------------------------------------------------------
 
41
 
 
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_old_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),
 
49
    amqp_channel:call(
 
50
      Ch, #'exchange.declare'{
 
51
        exchange    = XNameBin,
 
52
        type        = <<"x-federation">>,
 
53
        durable     = pget(durable,     Props, true),
 
54
        auto_delete = pget(auto_delete, Props, false),
 
55
        internal    = pget(internal,    Props, false),
 
56
        arguments   =
 
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),
 
61
    ok.
 
62
 
 
63
%%----------------------------------------------------------------------------
 
64
 
 
65
init([]) -> {ok, {{one_for_one, 3, 10}, []}}.