Skip to content

Instantly share code, notes, and snippets.

@denen99
Created March 20, 2012 13:21
Show Gist options
  • Save denen99/2135485 to your computer and use it in GitHub Desktop.
Save denen99/2135485 to your computer and use it in GitHub Desktop.
AD pubsub
start_link() ->
io:format("Starting erltest1 pubsub server...~n"),
{ok, SubPid} = eredis_sub:start_link(),
io:format("Registering pid...~n"),
register(eredispid,SubPid),
io:format("Registered...~n"),
_Receiver = spawn_link(fun () ->
eredis_sub_client:controlling_process(SubPid),
receiver(SubPid)
end),
subscribe("testchannel1"),
{ok,SubPid}.
stop(Pid) ->
eredis_sub_client:stop(Pid).
receiver(Pid) ->
receive
Msg ->
io:format("received ~p~n", [Msg]),
eredis_sub:ack_message(Pid),
?MODULE:receiver(Pid)
end.
subscribe(Channel) ->
EredisPid = register:whereis(eredispid),
eredis_sub:subscribe(EredisPid,[Channel]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment