Permalink
Browse files

basic layout; recieves events as they occur

  • Loading branch information...
0 parents commit b59f79a652643d40ae45cc25eb2de8a667037644 @simulacre committed Mar 1, 2012
Showing with 90 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +1 −0 Makefile
  3. +1 −0 package.mk
  4. +24 −0 src/rabbit_events_app.erl
  5. +41 −0 src/rabbit_events_handler.erl
  6. +11 −0 src/rabbit_events_sup.erl
  7. +9 −0 src/rabbitmq_events.app.src
@@ -0,0 +1,3 @@
+build/
+dist/
+ebin/
@@ -0,0 +1 @@
+include ../umbrella.mk
@@ -0,0 +1 @@
+DEPS:=rabbitmq-erlang-client
@@ -0,0 +1,24 @@
+-module(rabbit_events_app).
+
+-behaviour(application).
+-export([start/2, stop/1]).
+
+%% Make sure our database is hooked in *before* listening on the network or
+%% recovering queues (i.e. so there can't be any events fired before it starts).
+-rabbit_boot_step({rabbit_events_handler,
+ [{description, "events notifiction agent"},
+ {mfa, {rabbit_events_handler, add_handler,
+ []}},
+ {requires, rabbit_event},
+ {enables, recovery}]}).
+
+
+start(_Type, _StartArgs) ->
+ log_startup(),
+ rabbit_events_sup:start_link().
+
+stop(_State) ->
+ ok.
+
+log_startup() ->
+ rabbit_log:info("Events Notification Agents started.~n", []).
@@ -0,0 +1,41 @@
+
+-module(rabbit_events_handler).
+
+-behaviour(gen_event).
+
+-export([add_handler/0]).
+
+-export([init/1, handle_call/2, handle_event/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+%%----------------------------------------------------------------------------
+
+add_handler() ->
+ rabbit_log:info("add_handler called"),
+ gen_event:add_sup_handler(rabbit_event, ?MODULE, []).
+
+%%----------------------------------------------------------------------------
+
+
+init([]) ->
+ {ok, []}.
+
+handle_call(_Request, State) ->
+ rabbit_log:info("[events] got state that isn't understood ~p.~n", [State]),
+ {ok, not_understood, State}.
+
+handle_event(Event, State) ->
+ rabbit_log:info("[events] caught an event ~p in state ~p.~n", [Event, State]),
+ {ok, State}.
+
+handle_info(_Info, State) ->
+ rabbit_log:info("[events] caught an info ~p for state ~p.~n", [_Info, State]),
+ {ok, State}.
+
+terminate(_Arg, _State) ->
+ rabbit_log:info("[events] terminating.~n", []),
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ rabbit_log:info("[events] code change called.~n", []),
+ {ok, State}.
@@ -0,0 +1,11 @@
+-module(rabbit_events_sup).
+
+-behaviour(supervisor).
+
+-export([init/1]).
+-export([start_link/0]).
+
+init([]) -> {ok, {{one_for_one, 10, 10}, []}}.
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
@@ -0,0 +1,9 @@
+{application, rabbitmq_events,
+ [{description, "RabbitMQ Event Notifications"},
+ {vsn, "%%VSN%%"},
+ {modules, []},
+ {registered, []},
+ {mod, {rabbit_events_app, []}},
+ {env, []},
+ {applications, [kernel, stdlib, rabbit]}]}.
+

0 comments on commit b59f79a

Please sign in to comment.