Search code examples
amazon-web-servicesrediserlangejabberdriak

ejabberd Integration with Riak


I'm building a chat application leveraging ejabberd as the server, with Riak as the backend NoSQL db (on AWS). I could get a single-node ejabberd and a Riak cluster working correctly separately but somehow not able to have chat data pushed onto the database by ejabberd.

As a first shot, I want to store offline messages in Riak. I've written a simple ejabberd module (mod_offline_riak) attaching to the offline_message_hook. This gets called successfully when an offline message is sent, but the moment the riak connection is made (in riakc_pb_socket:start_link), I get an undef error in the ejabberd logs. Relevant code snippets pasted below.

Furthermore, the ejabberd default installation (from code, v15.04) does not contain the riak-erlang-client dependency, so I've even included that in the ejabberd rebar.config.script and done a re-make / re-install but to no help.

start(_Host, _Opt) ->
  ?INFO_MSG("Starting module mod_offline_riak ...", []),
  ejabberd_hooks:add(offline_message_hook, _Host, ?MODULE, save_message, 0),
  ok.

save_message(From, To, Packet) ->
  ?INFO_MSG("Entered function save_message ...", []),
  create_riak_object(To, Packet),

create_riak_object(To, Packet) ->
  ?INFO_MSG("Entered function create_riak_object ...", []),
  {ok, Pid} = riakc_pb_socket:start_link("***IP of one of the Riak nodes***", 8087),
  PollToBeSaved = riakc_obj:new(?DATA_BUCKET, To, Packet),
  riakc_pb_socket:put(Pid, PollToBeSaved),
  ok.

The error in the ejabberd log is:

2015-12-28 16:06:02.166 [error] <0.503.0>@ejabberd_hooks:run1:335 {undef,

[{riakc_pb_socket,start_link,["***Riak IP configured in the module***",8087],
[]},{mod_offline_riak,create_riak_object,2,[{file,"mod_offline_riak.erl"},
{line,39}]},{mod_offline_riak,save_message,3,[{file,"mod_offline_riak.erl"},
{line,23}]},{ejabberd_hooks,safe_apply,3,[{file,"src/ejabberd_hooks.erl"},
{line,385}]},{ejabberd_hooks,run1,3,[{file,"src/ejabberd_hooks.erl"},{line,332}]},
{ejabberd_sm,route,3,[{file,"src/ejabberd_sm.erl"},{line,115}]},
{ejabberd_local,route,3,[{file,"src/ejabberd_local.erl"},{line,112}]},
{ejabberd_router,route,3,[{file,"src/ejabberd_router.erl"},{line,74}]}]}

Afraid I've been struggling with this for the last few days and still learning my steps around Erlang / Riak, so appreciate any help here.

On a slight tangential, I plan to allow embedding of media attachments too in the chat messages too - I presume the recommendation would be to instead use Riak CS instead of Riak - I'll be leveraging S3 in the background.

Finally, is there any good ejabberd / Riak / Redis integration material that I can refer that folks are aware of? I understand there was recently a talk in London but I'm based in NY, so missed that... :-(

Thanks again for all your help...


Solution

  • undef means the module/function is not available. Presumably, you do not have build the riakc_pb_socket module or the beam file is not in your Erlang path.