i'm just starting up with a web app using nitrogen and everything is going well. But i also want my app to interface with a riak db that i set up and i'm having some trouble.
I'm confused as to how I "include" the erlang client interface so that my code in nitrogen can access it.
(https://wiki.basho.com/display/RIAK/Erlang+Client+PBC)
I'm new to erlang and nitrogen, but i mean in general, for erlang, how do i include other libraries as reference? Do i just take the compiled beam files and throw it somewhere, then have an -include line at the top of my erlang code? if so, where do do i throw these files for nitrogen (it has its own separate erlang node instance i think)
If you run everything on one node just call what you need. If node is build with rules of Erlang/OPT release handling it means that all needed libraries are loaded to VM.
-include is just used to include header files with e.g. record definitions or macros.
All of it should be transparent for you because rebar (build system by basho) handles it pretty well.
To use some lib make sure it is in deps directory as a result of proper rebar config (deps section). The next thing is to modify systools.config in rel/files which configures node (picks up apps from deps/ to be included in running system).
And thats all.
This is a simple procedure:
Ensure using Basho's patched version of Erlang. Instructions to do that are found at Installing Basho Erlang/OTP.
Then install a slim version by following following the instructions at Creating a Nitrogen project. Please use the "slim-release" versions such that you build your project using the Basho's Erlang
Pull the riak-erlang-client from github. For more information Check here or simply do this from the ../$MYPROJECT/lib directory, where $MYPROJECT is your nitrogen project name.
git clone git://github.com/basho/riak-erlang-client.git
. This will include riak-erlang-client in the lib directoryEdit the rebar.config file by doing this
nano ../$MYPROJECT/rebar.config
to include the riak-erlang-client dependencies. ** Look for riakc dep in the code block below **, in this project i usedmake slim_cowboy
{deps, [
{cowboy, ".*", {git, "git://github.com/ninenines/cowboy", {tag, "1.0.0"}}},
%% Uncomment the following lines and comment the bottom lines with specific
%% tags to always pull the latest versions
{simple_bridge, ".*", {git, "git://github.com/nitrogen/simple_bridge",{branch, master}}},
{nprocreg, ".*", {git, "git://github.com/nitrogen/nprocreg", {branch, master}}},
{nitrogen_core, ".*", {git, "git://github.com/nitrogen/nitrogen_core",{branch, master}}},
%% The riak-erlang-client dep starts
{riakc, "1.4.1", {git, "git://github.com/basho/riak-erlang-client", {tag, "1.4.1"}}},
%% The riak-erlang-client dep ends
{sync, ".*", {git, "git://github.com/rustyio/sync", {branch, master}}}
%% Get specific tagged version
%{simple_bridge, ".*", {git, "git://github.com/nitrogen/simple_bridge",{tag, "v2.0.0-beta5"}}},
%{nprocreg, ".*", {git, "git://github.com/nitrogen/nprocreg", {tag, "v0.2.1"}}},
%{nitrogen_core, ".*", {git, "git://github.com/nitrogen/nitrogen_core",{tag, "v2.3.0-beta6"}}},
%{sync, ".*", {git, "git://github.com/rustyio/sync", {tag, "4dbe32bb4"}}}
]}.
From ../$MYPROJECT recompile your project by using
make all
.At the end of this step just start nitrogen by
./bin/nitrogen console
. Try connecting to one of your riak nodes by{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", <PORT>).
Then you are ready to go.
来源:https://stackoverflow.com/questions/4222478/including-the-erlang-client-library-from-riak-in-nitrogen