在 Nitrogen 中包含 Riak 的 Erlang 客户端库
我刚刚开始使用氮气的网络应用程序,一切进展顺利。但我也希望我的应用程序能够与我设置的 riak 数据库交互,但我遇到了一些麻烦。
我对如何“包含”erlang 客户端接口感到困惑,以便氮中的代码可以访问它。
(https://wiki.basho.com/display/RIAK/Erlang+Client+PBC)
我是erlang和氮的新手,但我的意思是一般来说,对于erlang,我如何包含其他库作为参考?我是否只需将编译后的光束文件扔到某个地方,然后在我的 erlang 代码顶部添加一个 -include 行?如果是这样,我该把这些文件扔到哪里获取氮气(我认为它有自己独立的 erlang 节点实例)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在一个节点上运行所有内容,只需调用您需要的内容即可。如果节点是按照 Erlang/OPT 发布处理规则构建的,则意味着所有需要的库都已加载到 VM。
-include 仅用于包含带有记录定义或宏等的头文件。
所有这些对您来说都应该是透明的,因为 rebar(basho 构建系统)可以很好地处理它。
要使用某些库,请确保它位于 deps 目录中,这是正确的 rebar 配置(deps 部分)的结果。接下来是修改 rel/files 中的 systools.config,它配置节点(从 deps/ 获取应用程序以包含在运行系统中)。
仅此而已。
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.
这是一个简单的过程:
确保使用 Basho 的 Erlang 修补版本。有关执行此操作的说明,请参阅安装 Basho Erlang/OTP .
然后按照创建 Nitrogen 项目。 请使用“slim-release”版本,以便使用 Basho 的 Erlang 构建项目
从 github 拉取 riak-erlang-client。有关更多信息查看此处或者只需从 ../$MYPROJECT/lib 目录执行此操作,其中 $MYPROJECT 是您的氮项目名称。
git 克隆 git://github.com/basho/riak-erlang-client.git
。这会将 riak-erlang-client 包含在 lib 目录中通过执行此
nano ../$MYPROJECT/rebar.config
编辑 rebar.config 文件以包含riak-erlang-client 依赖项。 ** 在下面的代码块中查找 riakc dep **,在这个项目中我使用了make slim_cowboy
{deps, [
]}。
从 ../$MYPROJECT 使用
make all
重新编译您的项目。在此步骤结束时,只需通过
./bin/nitrogen console
启动氮气。尝试通过{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1",) 连接到您的 riak 节点之一。
然后您就可以开始了。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, [
]}.
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.