【问题标题】:How to build erlang AMQP client in Mongooseim如何在 Mongooseim 中构建 erlang AMQP 客户端
【发布时间】:2015-06-30 17:40:19
【问题描述】:

我是 erlang 的新手。我正在尝试使用我的 mongoose 源构建 RabitMQ Erlang AMQP 客户端库,以便我可以在我的 mongooseim 模块中使用该库。我从here 下载了库源。 .ez 文件包含两个目录,ebin 和includes。 ebin 包含 .beam 文件,而 include 包含 erlang .hrl 文件。如果我将所有 .hrl 文件放入 mongooseim 的 apps/ejabberd/include 目录并将所有 .beam 文件放入 ebin 目录,它会起作用吗?我正在使用 make 和 make rel 来编译 mongooseim。

【问题讨论】:

    标签: erlang rabbitmq mongoose-im


    【解决方案1】:

    我发现使用 Jon Brisbin 的钢筋友好型 amqp 库 (https://github.com/jbrisbin) 更容易、更清洁。我所要做的就是在 rebar.config 文件的依赖项列表中添加 rabbit_common 和 amqp_client repo。

    diff --git a/rebar.config b/rebar.config
    index c719d98..cafdb0f 100644
    --- a/rebar.config
    +++ b/rebar.config
    @@ -36,6 +36,8 @@
       {pa, ".*", {git, "git://github.com/lavrin/pa.git", "c616d3f9"}},
       {ecoveralls, ".*", {git, "git://github.com/nifoc/ecoveralls.git", "40fa0d2f2057fff29e964f94fccf6ef2f13d34d2"}},
       {mustache, ".*", {git, "git://github.com/mojombo/mustache.erl.git", "d0246fe143058b6404f66cf99fece3ff6e87b7ed"}},
    +  {rabbit_common, ".*", {git, "git://github.com/jbrisbin/rabbit_common.git", "rabbitmq-3.5.0"}},
    +  {amqp_client, ".*", {git, "git://github.com/jbrisbin/amqp_client.git", {tag, "rabbitmq-3.5.0"}}},
       {recon, "2.2.1", {git, "git://github.com/ferd/recon.git", {tag, "2.2.1"}}}
      ]}.
    

    然后制作并制作rel。我可以使用来自任何 mongooseim 模块的 amqp_client 标头:

    -include_lib("amqp_client/include/amqp_client.hrl").
    

    【讨论】:

      【解决方案2】:

      您建议的方式可行,但更清洁的方法是可能的。您可以调整 Makefile 以简单地将库复制到刚刚构建的 MongooseIM 发布目录中,但有更好的方法:

      1. 在mongooseim/apps/中下载并解压amqp_client-3.5.1.ez。
      2. 可以选择将 mongooseim/apps/amqp_client-3.5.1/ 签入到您的 git 存储库中,这样您就不必在每次克隆存储库时再次下载它。
      3. 使reltool 像捆绑MongooseIM 依赖项和组件一样捆绑应用程序,即应用以下补丁:

        diff --git a/rel/reltool.config.script b/rel/reltool.config.script
        index 731d58c..395a73f 100644
        --- a/rel/reltool.config.script
        +++ b/rel/reltool.config.script
        @@ -20,7 +20,9 @@ BaseAppsToRun = [compiler,
                          cowboy,
                          fusco,
                          folsom,
        -                 exometer],
        +                 exometer,
        +                 xmerl,
        +                 amqp_client],
        
         AppsToRunIn = BaseAppsToRun ++ proplists:get_value(apps_to_run, Conf, []),
        
        @@ -44,7 +46,9 @@ BaseAppsToInclude = AppsToRun ++
                              alarms,
                              idna,
                              recon,
        -                     setup
        +                     setup,
        +                     xmerl,
        +                     amqp_client
                              ],
        

        请注意xmerl 是amqp_client 的依赖项,因此也必须添加到发行版中。

      4. make rel 使用与 MongooseIM 捆绑的 amqp_client 重建版本。
      5. 运行服务器(例如在mongooseim/rel/mongooseim 目录中使用bin/mongooseimctl live)并验证amqp_client 是否可用并且正在运行:

        (mongooseim@localhost)1> application:which_applications().
        ... snipped ...
         {amqp_client,"RabbitMQ AMQP Client","3.5.1"},
         {xmerl,"XML parser","1.3.7"},
        ... snipped ...
        (mongooseim@localhost)2> amqp_client:start().             
        {error,{already_started,amqp_client}}
        

        (不要介意错误,我们当然希望它已经启动。)

      【讨论】:

      • 您好,感谢您的回复。我按照您的指示进行操作,amqp_client 正在开始。但是,当我尝试包含头文件并再次制作 mongooseim 时,出现错误:找不到包含文件“amqp_client.hrl”。如何解决这个问题?
      猜你喜欢
      • 2011-01-28
      • 2011-03-20
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      • 2011-03-06
      • 1970-01-01
      • 2014-02-11
      • 2019-07-28
      相关资源
      最近更新 更多