summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Jones <paulj@lshift.net>2009-08-11 15:25:42 +0100
committerPaul Jones <paulj@lshift.net>2009-08-11 15:25:42 +0100
commit8a3e6da26346f8ac382dc8cd91c1bb411e7d9878 (patch)
tree65997087af0b6e11ef0ababb798866c5f3ded5e3
parentfa814810f38241d83e572762a85c8cf0c668a84a (diff)
downloadrabbitmq-server-8a3e6da26346f8ac382dc8cd91c1bb411e7d9878.tar.gz
Added notify_remote method, allowing a remote node to be notified of a hookbug18748
-rw-r--r--src/rabbit_hooks.erl7
-rw-r--r--src/rabbit_tests.erl16
2 files changed, 22 insertions, 1 deletions
diff --git a/src/rabbit_hooks.erl b/src/rabbit_hooks.erl
index 05db6630..b3d271c2 100644
--- a/src/rabbit_hooks.erl
+++ b/src/rabbit_hooks.erl
@@ -32,7 +32,7 @@
-module(rabbit_hooks).
-export([start/0]).
--export([subscribe/3, unsubscribe/2, trigger/2]).
+-export([subscribe/3, unsubscribe/2, trigger/2, notify_remote/5]).
-define(TableName, rabbit_hooks).
@@ -42,6 +42,7 @@
-spec(subscribe/3 :: (atom(), atom(), {atom(), atom(), list()}) -> 'ok').
-spec(unsubscribe/2 :: (atom(), atom()) -> 'ok').
-spec(trigger/2 :: (atom(), list()) -> 'ok').
+-spec(notify_remote/5 :: (atom(), atom(), list(), pid(), list()) -> 'ok').
-endif.
@@ -66,3 +67,7 @@ trigger(Hook, Args) ->
_ -> ok
end || {_, Name, {M, F, A}} <- Hooks],
ok.
+
+notify_remote(Hook, HandlerName, Args, Pid, PidArgs) ->
+ Pid ! {rabbitmq_hook, [Hook, HandlerName, Args | PidArgs]},
+ ok.
diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl
index 71d529a3..e5100ccd 100644
--- a/src/rabbit_tests.erl
+++ b/src/rabbit_tests.erl
@@ -633,6 +633,22 @@ test_hooks() ->
rabbit_hooks:trigger(arg_hook, [arg1, arg2]),
{[arg1, arg2], 1, 3} = get(arg_hook_test_fired),
+ %% Invoking Pids
+ Remote = fun() ->
+ receive
+ {rabbitmq_hook,[remote_test,test,[],Target]} ->
+ Target ! invoked
+ end
+ end,
+ P = spawn(Remote),
+ rabbit_hooks:subscribe(remote_test, test, {rabbit_hooks, notify_remote, [P, [self()]]}),
+ rabbit_hooks:trigger(remote_test, []),
+ receive
+ invoked -> ok
+ after 100 ->
+ io:format("Remote hook not invoked"),
+ throw(timeout)
+ end,
passed.
%---------------------------------------------------------------------