nsq是基于golang开发的分布式消息系统,这里仅仅贴个和erlang之间的通信demo

rebar-creator create-app test_nsq

rebar.config

% -*- erlang -*-
{erl_opts, [debug_info]}.
{deps, [
{ensq,".*",{git, "https://github.com/project-fifo/ensq.git", {tag, "0.1.5"}}}
]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{sub_dirs, ["apps/test_nsq", "rel"]}.

my_nsq.erl

-module(my_nsq).

-export([connect/,send/]).

connect() ->
ensq:start(),
DiscoveryServers = [{"localhost", }], %% Discovery Server
Channels = [
{
<<"channel1">>, %% Channel name
ensq_debug_callback %% 预定义的调试模块,可修改为自己的
},
{
<<"channel2">>,
ensq_debug_callback
}
],
ensq_topic:discover(
my_topic, %% Topic
DiscoveryServers, %% Discovery servers to use
Channels, %% Channels to join.
[{"localhost", }]). %% Targets for SUBing send() ->
%% Sending a message to a topic
ensq:send(my_topic, <<"hello channel1!">>),
ensq:send(my_topic, <<"hello channel2!">>).

nsq的客户端库列表参考

05-02 06:38