Created
September 12, 2011 17:07
-
-
Save RJ/1211785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Start a connection to the server | |
{ok, Connection} = amqp_connection:start(#amqp_params_network{}), | |
%% Once you have a connection to the server, you can start an AMQP channel | |
{ok, Channel} = amqp_connection:open_channel(Connection), | |
%% Now that you have access to a connection with the server, you can declare a queue and bind it to an exchange | |
%% Routing topology: | |
%% | |
%% All msgs go to irc_x (fanout exchange) | |
%% exchange-to-exchange bindings spread msgs to these exchanges: | |
%% - irc_search_x | |
%% - irc_db_x | |
%% - irc_log_x | |
%% | |
%% Those exchanges have 1 queue each at the moment, for consumers that | |
%% write the msgs to logs/search/database | |
#'exchange.declare_ok'{} = | |
amqp_channel:call(Channel, | |
#'exchange.declare'{exchange = <<"irc_x">>, | |
type = <<"fanout">>, | |
durable=true, | |
auto_delete=false}), | |
#'exchange.declare_ok'{} = | |
amqp_channel:call(Channel, | |
#'exchange.declare'{exchange = <<"irc_search_x">>, | |
type = <<"topic">>, | |
durable=true, | |
auto_delete=false}), | |
#'exchange.declare_ok'{} = | |
amqp_channel:call(Channel, | |
#'exchange.declare'{exchange = <<"irc_db_x">>, | |
type = <<"topic">>, | |
durable=true, | |
auto_delete=false}), | |
#'exchange.declare_ok'{} = | |
amqp_channel:call(Channel, | |
#'exchange.declare'{exchange = <<"irc_log_x">>, | |
type = <<"topic">>, | |
durable=true, | |
auto_delete=false}), | |
%% Bind the three exchanges, db, search, log, to the toplevel fanout exchange | |
#'exchange.bind_ok'{} = | |
amqp_channel:call(Channel, #'exchange.bind'{ source = <<"irc_x">>, | |
destination = <<"irc_search_x">>, | |
routing_key = <<"#">> | |
}), | |
#'exchange.bind_ok'{} = | |
amqp_channel:call(Channel, #'exchange.bind'{ source = <<"irc_x">>, | |
destination = <<"irc_db_x">>, | |
routing_key = <<"#">> | |
}), | |
#'exchange.bind_ok'{} = | |
amqp_channel:call(Channel, #'exchange.bind'{ source = <<"irc_x">>, | |
destination = <<"irc_log_x">>, | |
routing_key = <<"#">> | |
}), | |
%% Set up queues for exchanges | |
#'queue.declare_ok'{queue = IrcSearchQ} = | |
amqp_channel:call(Channel, #'queue.declare'{queue = <<"irc_search_q">>}), | |
#'queue.declare_ok'{queue = IrcDbQ} = | |
amqp_channel:call(Channel, #'queue.declare'{queue = <<"irc_db_q">>}), | |
#'queue.declare_ok'{queue = IrcLogQ} = | |
amqp_channel:call(Channel, #'queue.declare'{queue = <<"irc_log_q">>}), | |
%% bind queues to exchanges | |
#'queue.bind_ok'{} = | |
amqp_channel:call(Channel, #'queue.bind'{ queue = IrcSearchQ, | |
exchange = <<"irc_search_x">>, | |
routing_key = <<"irc.#">>}), | |
#'queue.bind_ok'{} = | |
amqp_channel:call(Channel, #'queue.bind'{ queue = IrcDbQ, | |
exchange = <<"irc_db_x">>, | |
routing_key = <<"irc.#">>}), | |
#'queue.bind_ok'{} = | |
amqp_channel:call(Channel, #'queue.bind'{ queue = IrcLogQ, | |
exchange = <<"irc_log_x">>, | |
routing_key = <<"irc.#">>}), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment