在 Nitrogen 中包含 Riak 的 Erlang 客户端库

发布于 2024-10-03 19:22:45 字数 338 浏览 3 评论 0原文

我刚刚开始使用氮气的网络应用程序,一切进展顺利。但我也希望我的应用程序能够与我设置的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海不蓝 2024-10-10 19:22:45

如果您在一个节点上运行所有内容,只需调用您需要的内容即可。如果节点是按照 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.

天邊彩虹 2024-10-10 19:22:45

这是一个简单的过程:

  1. 确保使用 Basho 的 Erlang 修补版本。有关执行此操作的说明,请参阅安装 Basho Erlang/OTP .

  2. 然后按照创建 Nitrogen 项目。 请使用“slim-release”版本,以便使用 Basho 的 Erlang 构建项目

  3. 从 github 拉取 riak-erlang-client。有关更多信息查看此处或者只需从 ../$MYPROJECT/lib 目录执行此操作,其中 $MYPROJECT 是您的氮项目名称。 git 克隆 git://github.com/basho/riak-erlang-client.git。这会将 riak-erlang-client 包含在 lib 目录中

  4. 通过执行此 nano ../$MYPROJECT/rebar.config 编辑 rebar.config 文件以包含riak-erlang-client 依赖项。 ** 在下面的代码块中查找 riakc dep **,在这个项目中我使用了 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. 从 ../$MYPROJECT 使用 make all 重新编译您的项目。

  2. 在此步骤结束时,只需通过 ./bin/nitrogen console 启动氮气。尝试通过 {ok, Pid} = riakc_pb_socket:start_link("127.0.0.1",) 连接到您的 riak 节点之一。 然后您就可以开始了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文