diff options
-rw-r--r-- | src/rabbit_hooks.erl | 7 | ||||
-rw-r--r-- | src/rabbit_tests.erl | 16 |
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. %--------------------------------------------------------------------- |