From a2fa3aeff5ff04cf6d94c6321c29bb55bba3bb31 Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Thu, 1 Sep 2011 14:07:29 -0500 Subject: [PATCH] Use the configuration file to determine AMQP routing key --- irc/irc_conn.erl | 9 +++++++-- irc/irc_object_sup.erl | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/irc/irc_conn.erl b/irc/irc_conn.erl index f7dc563..f4ed6cc 100644 --- a/irc/irc_conn.erl +++ b/irc/irc_conn.erl @@ -133,8 +133,13 @@ send_command(Command) -> join_channel(Channel, State) -> Command = #irc_command{command = "JOIN", middles = [Channel]}, send_command(Command), - #irc_state{ object_sup = ObjectSup } = State, - {ok, _ChildPid} = irc_object_sup:add_amqp_listener(ObjectSup, self(), Channel). + #irc_state{object_sup = ObjectSup, + instance = Instance + } = State, + + {{Instance, Channel}, RoutingKey} = lists:keyfind({Instance, Channel}, + 1, config:get_config(irc_amqp_bind)), + {ok, _ChildPid} = irc_object_sup:add_amqp_listener(ObjectSup, self(), Channel, RoutingKey). %% @doc Splits a buffer into full lines, keeping whatever is left over %% Returns either {ok, [Line], Remaining} or none. diff --git a/irc/irc_object_sup.erl b/irc/irc_object_sup.erl index b301e3e..ab00a87 100644 --- a/irc/irc_object_sup.erl +++ b/irc/irc_object_sup.erl @@ -6,7 +6,7 @@ -export([ start_link/3, - add_amqp_listener/3 + add_amqp_listener/4 ]). -export([init/1]). @@ -18,10 +18,10 @@ init({_Instance, _Supervisor, _TableId}) -> RestartStrategy = {one_for_one, 5, 60}, {ok, {RestartStrategy, Children}}. -add_amqp_listener(ObjectSup, ConnectionPid, Channel) -> +add_amqp_listener(ObjectSup, ConnectionPid, Channel, RoutingKey) -> Child = {"amqp_" ++ Channel, % TODO: ↓ fix the routing key - {irc_amqp_listener, start_link, [ConnectionPid, Channel, "foobar"]}, + {irc_amqp_listener, start_link, [ConnectionPid, Channel, RoutingKey]}, transient, brutal_kill, worker, -- 2.11.0