I created an erlang application using the cowboy rest http handler. The application stores data in riak kv. However I am unable to connect to my riak node to return data for the rest api.
When I call riakc_pb_socket:start_link("127.0.0.1", 8087) I get errors.
Following is the code snippet of where i make the call to riak.
get_json(Req, State) ->
{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
Body = riakc_pb_socket:is_connected(Pid),
{Body, Req, State}.
Following is the stack trace from when the error occurs.
=ERROR REPORT==== 28-Dec-2016::00:15:52 ===
Error in process <0.359.0> on node 'paddylenderapi@PaddyLender-2' with
exit value:
{[{reason,undef},
{mfa,{paddylenderapi_rest_handler,get_json,2}},
{stacktrace,
[{riakc_pb_socket,start_link,["127.0.0.1",8087],[]},
{paddylenderapi_rest_handler,get_json,2,
[{file,
"/home/oladipo/Projects/Erlang/PaddyLender/paddylenderapi
/_build/prod/lib/paddylenderapi/src/paddylenderapi_rest_handler.erl"},
{line,37}]},
{cowboy_rest,call,3,
[{file,
"/home/oladipo/Projects/Erlang/PaddyLender/paddylenderapi
/_build/default/lib/cowboy/src/cowboy_rest.erl"},
{line,972}]},
{cowboy_rest,set_resp_body,2,
[{file,
"/home/oladipo/Projects/Erlang/PaddyLender/paddylenderapi
/_build/default/lib/cowboy/src/cowboy_rest.erl"},
{line,854}]},
{cowboy_protocol,execute,4,
[{file,
"/home/oladipo/Projects/Erlang/PaddyLender/paddylenderapi
/_build/default/lib/cowboy/src/cowboy_protocol.erl"},
{line,442}]}]},
See my rebar.config contents below:
{erl_opts, [debug_info]}.
{deps, [
{cowboy, {git, "git://github.com/ninenines/cowboy.git", {tag, "1.0.1"}}},
{riakc, "2.5.*", {git, "https://github.com/basho/riak-erlang-client", {tag, "2.5.1"}}},
{riak_pb, {git, "https://github.com/basho/riak_pb", {tag, "2.1.4.2"}}}
]
}.
{plugins, [
rebar3_run
]
}.
{relx, [
{release, {paddylenderapi, "0.0.1"},[paddylenderapi]},
{dev_mode, true},
{include_erts, false},
{extended_start_script, true}
]
}.
{overrides,
[
{override, rebar3_protobuffs_plugin, [{deps, [ {protobuffs, {git, "https://github.com/basho/erlang_protobuffs.git", {tag, "0.9.0"}}}]}]},
{override, riak_pb, [
{plugins, [{riak_pb_msgcodegen,
{git, "https://github.com/tsloughter/riak_pb_msgcodegen.git",
{ref, "dc51330"}}},
{rebar3_protobuffs_plugin,
{git, "https://github.com/cmkarlsson/rebar3_protobuffs_plugin",
{tag, "0.1.1"}}}]},
{provider_hooks, [{pre, [{compile, {protobuffs, compile}},
{compile, riak_pb_msgcodegen}]}]}]}
]
}.
I suggest you don't have riak_kv in 'applications' part in your paddylenderapi.app.src. And that's the reason why this application doesn't place in release lib folder. So you get the undef error.