Use the configuration file to determine AMQP routing key
authorMatt Mullins <mmullins@mmlx.us>
Thu, 1 Sep 2011 19:07:29 +0000 (14:07 -0500)
committerMatt Mullins <mmullins@mmlx.us>
Thu, 1 Sep 2011 19:07:29 +0000 (14:07 -0500)
irc/irc_conn.erl
irc/irc_object_sup.erl

index f7dc563..f4ed6cc 100644 (file)
@@ -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.
index b301e3e..ab00a87 100644 (file)
@@ -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,