【问题标题】:Including the Erlang client library from Riak in Nitrogen在 Nitrogen 中包含来自 Riak 的 Erlang 客户端库
【发布时间】:2014-12-21 09:35:04
【问题描述】:

我刚刚使用氮气启动了一个网络应用程序,一切进展顺利。但我也希望我的应用程序能够与我设置的 riak db 交互,但我遇到了一些麻烦。

我很困惑如何“包含”erlang 客户端接口,以便我在氮气中的代码可以访问它。

(https://wiki.basho.com/display/RIAK/Erlang+Client+PBC)

我是 erlang 和氮气的新手,但我的意思是一般来说,对于 erlang,我如何包含其他库作为参考?我是否只是将编译后的梁文件扔到某个地方,然后在我的 erlang 代码顶部有一个 -include 行?如果是这样,我该把这些文件扔到哪里去换氮(我认为它有自己独立的 erlang 节点实例)

【问题讨论】:

    标签: erlang nitrogen


    【解决方案1】:

    如果您在一个节点上运行所有内容,只需调用您需要的内容。如果节点是使用 Erlang/OPT 发布处理规则构建的,则意味着所有需要的库都已加载到 VM。

    -include 仅用于包含头文件,例如记录定义或宏。

    所有这些对你来说都应该是透明的,因为 rebar(由 basho 构建系统)可以很好地处理它。

    要使用一些 lib,请确保它位于 deps 目录中,因为正确的 rebar 配置(deps 部分)。接下来是修改 rel/files 中配置节点的 systools.config(从 deps/ 中提取应用程序以包含在正在运行的系统中)。

    仅此而已。

    【讨论】:

    • 太棒了,你说得对。我将它安装在氮气使用的节点上(而不是已经安装在我的计算机上的 erlang 节点),现在一切正常。谢谢!
    • 我想知道你是否可以通过帮助回答这个问题来继续这个想法,Using the Erlang client library from Riak in Nitrogen
    【解决方案2】:

    这是一个简单的过程:

    1. 确保使用 Basho 的 Erlang 补丁版本。在Installing Basho Erlang/OTP 上可以找到相关说明。

    2. 然后按照Creating a Nitrogen project 的说明安装精简版。 请使用“slim-release”版本,以便您使用 Basho 的 Erlang 构建项目

    3. 从 github 拉取 riak-erlang-client。更多信息Check here 或直接从 ../$MYPROJECT/lib 目录执行此操作,其中 $MYPROJECT 是您的氮气项目名称。 git clone git://github.com/basho/riak-erlang-client.git。这将包括 lib 目录中的 riak-erlang-client

    4. 通过 nano ../$MYPROJECT/rebar.config 编辑 rebar.config 文件以包含 riak-erlang-client 依赖项。 ** 在下面的代码块中寻找riakc dep **,在这个项目中我使用了make slim_cowboy

    {部门,[

      {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", <PORT>). 连接到您的 riak 节点之一,然后您就可以开始了。

    【讨论】:

    • 第三步,在客户端的根目录下包含一个nitrogen.plugin文件,即touch ../$MYPROJECT/lib/riak-erlang-client/nitrogen.plugin。这将使您能够使用氮气的 do-plugins.enscript 包含此插件,而不会产生副作用。
    猜你喜欢
    • 2014-04-05
    • 2011-03-06
    • 2015-01-02
    • 1970-01-01
    • 2014-07-05
    • 2017-04-02
    • 1970-01-01
    • 2014-06-29
    • 2011-01-28
    相关资源
    最近更新 更多