尝试在OSX下的Erlang中运行RabbitMQ的教程示例,但它失败并显示以下消息:
./send.erl:20: can't find include lib "rabbit_common/include/rabbit.hrl"
./send.erl:21: can't find include lib "rabbit_common/include/rabbit_framing.hrl"
escript: There were compilation errors.
amqp_example.erl:
-module(amqp_example).
-include("amqp_client.hrl").
-compile([export_all]).
test() ->
%% Start a network connection
{ok, Connection} = amqp_connection:start(#amqp_params_network{}),
%% Open a channel on the connection
{ok, Channel} = amqp_connection:open_channel(Connection),
%% Declare a queue
#'queue.declare_ok'{queue = Q}
= amqp_channel:call(Channel, #'queue.declare'{}),
%% Publish a message
Payload = <<"foobar">>,
Publish = #'basic.publish'{exchange = <<>>, routing_key = Q},
amqp_channel:cast(Channel, Publish, #amqp_msg{payload = Payload}),
%% Get the message back from the queue
Get = #'basic.get'{queue = Q},
{#'basic.get_ok'{delivery_tag = Tag}, Content}
= amqp_channel:call(Channel, Get),
%% Do something with the message payload
%% (some work here)
%% Ack the message
amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
%% Close the channel
amqp_channel:close(Channel),
%% Close the connection
amqp_connection:close(Connection),
ok.
请帮我解决这个问题。谢谢!
答案 0 :(得分:3)
Erlang有宏include_lib
,它可以在路径中搜索库并且很方便,因为您不必指定库的版本 - 它会自动使用最新版本。所以,而不是
-include("rabbit_common-3.3.5/include/rabbit.hrl").
你可以写:
-include_lib("rabbit_common/include/rabbit.hrl").
因此,在您的情况下,您必须确保该文件rabbit_common-[version]/include/rabbit.hrl
位于ERL_LIBS
路径中。在tutorial, you are using中,他们希望您从here下载这些文件并将其解压缩:
unzip -d deps deps/amqp_client.ez
unzip -d deps deps/rabbit_common.ez
那些解压缩命令不能在OS X上工作,因为解压缩只能用于.zip文件。所以这可能是你的问题。尝试使用其他应用程序解压缩它们并仔细检查文件是否存在。在编译和运行示例之前,不要忘记添加ERL_LIBS=deps
:
ERL_LIBS=deps erlc -o ebin amqp_example.erl
ERL_LIBS=deps erl -pa ebin