I am new in erlang. I am trying to build RabitMQ Erlang AMQP client library with my mongoose source so that I can use the library within my mongooseim modules. I downloaded the library source from here. The .ez file contains two directories, ebin and includes. ebin contains .beam files and include contains erlang .hrl files. Will it work if I drop all the .hrl files into mongooseim's apps/ejabberd/include directory and all .beam files into ebin directory? I am using make and make rel for compiling mongooseim.
问题:
回答1:
The way you suggest will work, but a cleaner approach is possible. You could tweak the Makefile to simply copy the library into the just built MongooseIM release directory, but there's a better way:
- Download and unpack
amqp_client-3.5.1.ez
insidemongooseim/apps/
. - Optionally check in
mongooseim/apps/amqp_client-3.5.1/
into your git repo, so you won't have to download it again each time you clone the repository. Make
reltool
bundle the application just as it bundles MongooseIM dependencies and components, that is apply the following patch: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 ],
Please note that
xmerl
is a dependency ofamqp_client
, so also has to be added to the release.make rel
to rebuild the release withamqp_client
bundled with MongooseIM.Run the server (e.g. with
bin/mongooseimctl live
inmongooseim/rel/mongooseim
directory) and verify thatamqp_client
is available and running:(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}}
(Don't mind the error, of course we want it to be started already.)
回答2:
I found its much easier and cleaner using Jon Brisbin's rebar friendly amqp library (https://github.com/jbrisbin). All I had do is to add rabbit_common and amqp_client repo in my dependency list from rebar.config file.
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"}}}
]}.
Then make and make rel. I can include amqp_client header from any mongooseim module using:
-include_lib("amqp_client/include/amqp_client.hrl").