Skip to content

Commit dcefa2a

Browse files
author
Paul Jones
committed
Added notify_remote method, allowing a remote node to be notified of a hook
1 parent f137177 commit dcefa2a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/rabbit_hooks.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
-module(rabbit_hooks).
3333

3434
-export([start/0]).
35-
-export([subscribe/3, unsubscribe/2, trigger/2]).
35+
-export([subscribe/3, unsubscribe/2, trigger/2, notify_remote/5]).
3636

3737
-define(TableName, rabbit_hooks).
3838

@@ -42,6 +42,7 @@
4242
-spec(subscribe/3 :: (atom(), atom(), {atom(), atom(), list()}) -> 'ok').
4343
-spec(unsubscribe/2 :: (atom(), atom()) -> 'ok').
4444
-spec(trigger/2 :: (atom(), list()) -> 'ok').
45+
-spec(notify_remote/5 :: (atom(), atom(), list(), pid(), list()) -> 'ok').
4546

4647
-endif.
4748

@@ -66,3 +67,7 @@ trigger(Hook, Args) ->
6667
_ -> ok
6768
end || {_, Name, {M, F, A}} <- Hooks],
6869
ok.
70+
71+
notify_remote(Hook, HandlerName, Args, Pid, PidArgs) ->
72+
Pid ! {rabbitmq_hook, [Hook, HandlerName, Args | PidArgs]},
73+
ok.

src/rabbit_tests.erl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,22 @@ test_hooks() ->
633633
rabbit_hooks:trigger(arg_hook, [arg1, arg2]),
634634
{[arg1, arg2], 1, 3} = get(arg_hook_test_fired),
635635

636+
%% Invoking Pids
637+
Remote = fun() ->
638+
receive
639+
{rabbitmq_hook,[remote_test,test,[],Target]} ->
640+
Target ! invoked
641+
end
642+
end,
643+
P = spawn(Remote),
644+
rabbit_hooks:subscribe(remote_test, test, {rabbit_hooks, notify_remote, [P, [self()]]}),
645+
rabbit_hooks:trigger(remote_test, []),
646+
receive
647+
invoked -> ok
648+
after 100 ->
649+
io:format("Remote hook not invoked"),
650+
throw(timeout)
651+
end,
636652
passed.
637653

638654
%---------------------------------------------------------------------

0 commit comments

Comments
 (0)