Including the Erlang client library from Riak in Nitrogen

心已入冬 提交于 2019-12-29 08:04:11

问题


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)


回答1:


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.




回答2:


This is a simple procedure:

  1. Ensure using Basho's patched version of Erlang. Instructions to do that are found at Installing Basho Erlang/OTP.

  2. 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

  3. 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 directory

  4. Edit 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 used make 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"}}}

]}.

  1. From ../$MYPROJECT recompile your project by using make all.

  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!